mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-02 21:24:18 -04:00
* Fixed bookmarking failing to convert to webp * Brought the ag-swipe/ng-swipe code into Kavita due to being abandoned by developer and angular requirements. * Fixed average reading time per week finally * Cleaned up some extra decimals on time duration pipe * Don't try to update index.html for base url on local. Fixed ag-swipe on prod mode. * Updated a link on theme manager to point to the new github * Range knobs should be primary color on firefox too * Implemented the ability to get thumbnails of pages inside an archive or pdf. * Updated packages and fixed opds-ps 1.2 issue * Fixed lock file * Allow Kavita's Swagger to hit instances with CORS * Added IP/Request logging for Security Audits * Linked up Summary tag from CBL into Kavita. * Redid the migration so SecurityEvent now has UTC date as well. * Split security logging to a separate file * Update to new versions of checkout and setup * Added a PR check on PR body to ensure that it doesn't contain any characters that break our discord hook. * Updating action * optimize regex in action * Fixed an issue where fit to width would cause the actual height of the image to be shown for pagination bars, instead of rendered. * Added some new code in GetPageFromFiles to ensure pages that exceed array map down to last file. * Added comment about robots * Fixed up unit tests for new ReaderService signature * Kavita now cleans up empty reading lists at night * Don't allow nightly cleanup to run if we are running media conversion tasks * Fixed some bugs in typeahead, it should behave much more reliably. * Fix an issue where emulate comic book wasn't extending to the bottom properly * Added support for Series Chapter 001 Volume 001 * Refactor XFrameOptions="SameOrigins" out to allow users to override in appsettings.json. * Added a rate limiter for some endpoints, but it doesn't seem to be triggering --------- Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
179 lines
5.2 KiB
C#
179 lines
5.2 KiB
C#
using System.Collections.Generic;
|
|
using API.Data;
|
|
using API.Entities;
|
|
using API.Entities.Enums;
|
|
using API.Helpers;
|
|
using Xunit;
|
|
|
|
namespace API.Tests.Helpers;
|
|
|
|
public class PersonHelperTests
|
|
{
|
|
#region UpdatePeople
|
|
[Fact]
|
|
public void UpdatePeople_ShouldAddNewPeople()
|
|
{
|
|
var allPeople = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer)
|
|
};
|
|
var peopleAdded = new List<Person>();
|
|
|
|
PersonHelper.UpdatePeople(allPeople, new[] {"Joseph Shmo", "Sally Ann"}, PersonRole.Writer, person =>
|
|
{
|
|
peopleAdded.Add(person);
|
|
});
|
|
|
|
Assert.Equal(2, peopleAdded.Count);
|
|
Assert.Equal(4, allPeople.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdatePeople_ShouldNotAddDuplicatePeople()
|
|
{
|
|
var allPeople = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer),
|
|
DbFactory.Person("Sally Ann", PersonRole.CoverArtist),
|
|
|
|
};
|
|
var peopleAdded = new List<Person>();
|
|
|
|
PersonHelper.UpdatePeople(allPeople, new[] {"Joe Shmo", "Sally Ann"}, PersonRole.CoverArtist, person =>
|
|
{
|
|
peopleAdded.Add(person);
|
|
});
|
|
|
|
Assert.Equal(3, allPeople.Count);
|
|
}
|
|
#endregion
|
|
|
|
#region UpdatePeopleList
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region RemovePeople
|
|
[Fact]
|
|
public void RemovePeople_ShouldRemovePeopleOfSameRole()
|
|
{
|
|
var existingPeople = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer)
|
|
};
|
|
var peopleRemoved = new List<Person>();
|
|
PersonHelper.RemovePeople(existingPeople, new[] {"Joe Shmo", "Sally Ann"}, PersonRole.Writer, person =>
|
|
{
|
|
peopleRemoved.Add(person);
|
|
});
|
|
|
|
Assert.NotEqual(existingPeople, peopleRemoved);
|
|
Assert.Equal(1, peopleRemoved.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemovePeople_ShouldRemovePeopleFromBothRoles()
|
|
{
|
|
var existingPeople = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer)
|
|
};
|
|
var peopleRemoved = new List<Person>();
|
|
PersonHelper.RemovePeople(existingPeople, new[] {"Joe Shmo", "Sally Ann"}, PersonRole.Writer, person =>
|
|
{
|
|
peopleRemoved.Add(person);
|
|
});
|
|
|
|
Assert.NotEqual(existingPeople, peopleRemoved);
|
|
Assert.Equal(1, peopleRemoved.Count);
|
|
|
|
PersonHelper.RemovePeople(existingPeople, new[] {"Joe Shmo"}, PersonRole.CoverArtist, person =>
|
|
{
|
|
peopleRemoved.Add(person);
|
|
});
|
|
|
|
Assert.Equal(0, existingPeople.Count);
|
|
Assert.Equal(2, peopleRemoved.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void RemovePeople_ShouldRemovePeopleOfSameRole_WhenNothingPassed()
|
|
{
|
|
var existingPeople = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer),
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer),
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist)
|
|
};
|
|
var peopleRemoved = new List<Person>();
|
|
PersonHelper.RemovePeople(existingPeople, new List<string>(), PersonRole.Writer, person =>
|
|
{
|
|
peopleRemoved.Add(person);
|
|
});
|
|
|
|
Assert.NotEqual(existingPeople, peopleRemoved);
|
|
Assert.Equal(2, peopleRemoved.Count);
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region KeepOnlySamePeopleBetweenLists
|
|
[Fact]
|
|
public void KeepOnlySamePeopleBetweenLists()
|
|
{
|
|
var existingPeople = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer),
|
|
DbFactory.Person("Sally", PersonRole.Writer),
|
|
};
|
|
|
|
var peopleFromChapters = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),
|
|
};
|
|
|
|
var peopleRemoved = new List<Person>();
|
|
PersonHelper.KeepOnlySamePeopleBetweenLists(existingPeople,
|
|
peopleFromChapters, person =>
|
|
{
|
|
peopleRemoved.Add(person);
|
|
});
|
|
|
|
Assert.Equal(2, peopleRemoved.Count);
|
|
}
|
|
#endregion
|
|
|
|
#region AddPeople
|
|
|
|
[Fact]
|
|
public void AddPeople_ShouldAddOnlyNonExistingPeople()
|
|
{
|
|
var existingPeople = new List<Person>
|
|
{
|
|
DbFactory.Person("Joe Shmo", PersonRole.CoverArtist),
|
|
DbFactory.Person("Joe Shmo", PersonRole.Writer),
|
|
DbFactory.Person("Sally", PersonRole.Writer),
|
|
};
|
|
|
|
|
|
PersonHelper.AddPersonIfNotExists(existingPeople, DbFactory.Person("Joe Shmo", PersonRole.CoverArtist));
|
|
Assert.Equal(3, existingPeople.Count);
|
|
|
|
PersonHelper.AddPersonIfNotExists(existingPeople, DbFactory.Person("Joe Shmo", PersonRole.Writer));
|
|
Assert.Equal(3, existingPeople.Count);
|
|
|
|
PersonHelper.AddPersonIfNotExists(existingPeople, DbFactory.Person("Joe Shmo Two", PersonRole.CoverArtist));
|
|
Assert.Equal(4, existingPeople.Count);
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|