mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-22 15:00:34 -04:00
* Implemented a workaround for nginx users with BlockCommonExploits enabled, which would interfere with book image escaping done by Kavita when images had ../ in their path. * Added back to top support on all pages but those that untilize virtual scrolling without a parent scroll. * Hide jumpbar on pages where there is no scroll * Refactored jumbar code into a dedicated service * Stash some jumpkey resume code as I can't get it working with the virtual scroller. * Don't allow non-admins to see File locations on card detail drawer. * Some cleanup on GetServerInfo * When an error occurs in register, delete the user on exception. * Fixed a NPE in Stat collection for brand new users * When we catch an exception on registering a new user, delete the user as rolling back doesn't do anything. * Don't close typeahead when we are selecting options from it * Added shortcut key H to open shortcut modal on manga reader * When processing progress updates on cards, for volumes, properly find the chapter to update pages read. * Hide cover image on reading list if it's not set and fixed a missing closing div tag * Hide collection poster when nothing is set on collection detail * Small fix around updating state * Sped up the bookmark image call by removing one DB call * Fixed broken test from change in bookmark code * Fixed an oversight where if there is no tag in ComicInfo after a chapter was updated with People or Genres, then the People/Genres would never be removed. * Added test with TagHelper * Fixed a bug where 2 clear buttons would show on search bar due to browser injecting their own. Search bar wont show clear button until text is typed. * Fixed a bug where InstallID wasn't being selected correctly in converter
162 lines
5.0 KiB
C#
162 lines
5.0 KiB
C#
using System;
|
|
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
|
|
{
|
|
[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);
|
|
}
|
|
|
|
[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, Array.Empty<string>(), PersonRole.Writer, person =>
|
|
{
|
|
peopleRemoved.Add(person);
|
|
});
|
|
|
|
Assert.NotEqual(existingPeople, peopleRemoved);
|
|
Assert.Equal(2, peopleRemoved.Count);
|
|
}
|
|
|
|
[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);
|
|
}
|
|
|
|
[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);
|
|
}
|
|
|
|
}
|