mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-08-05 08:40:04 -04:00
Adding movies episodes triggers
This commit is contained in:
parent
0c537e1cc1
commit
27f2751bd0
@ -38,6 +38,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
NEW.slug := CONCAT(
|
NEW.slug := CONCAT(
|
||||||
(SELECT slug FROM shows WHERE id = NEW.show_id),
|
(SELECT slug FROM shows WHERE id = NEW.show_id),
|
||||||
CASE
|
CASE
|
||||||
|
WHEN NEW.season_number IS NULL AND NEW.episode_number IS NULL THEN NULL
|
||||||
WHEN NEW.season_number IS NULL THEN CONCAT('-', NEW.absolute_number)
|
WHEN NEW.season_number IS NULL THEN CONCAT('-', NEW.absolute_number)
|
||||||
ELSE CONCAT('-s', NEW.season_number, 'e', NEW.episode_number)
|
ELSE CONCAT('-s', NEW.season_number, 'e', NEW.episode_number)
|
||||||
END
|
END
|
||||||
@ -62,6 +63,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
BEGIN
|
BEGIN
|
||||||
UPDATE seasons SET slug = CONCAT(NEW.slug, '-s', season_number) WHERE show_id = NEW.id;
|
UPDATE seasons SET slug = CONCAT(NEW.slug, '-s', season_number) WHERE show_id = NEW.id;
|
||||||
UPDATE episodes SET slug = CASE
|
UPDATE episodes SET slug = CASE
|
||||||
|
WHEN season_number IS NULL AND episode_number IS NULL THEN NEW.slug
|
||||||
WHEN season_number IS NULL THEN CONCAT(NEW.slug, '-', absolute_number)
|
WHEN season_number IS NULL THEN CONCAT(NEW.slug, '-', absolute_number)
|
||||||
ELSE CONCAT(NEW.slug, '-s', season_number, 'e', episode_number)
|
ELSE CONCAT(NEW.slug, '-s', season_number, 'e', episode_number)
|
||||||
END
|
END
|
||||||
|
@ -28,6 +28,7 @@ namespace Kyoo.SqLite.Migrations
|
|||||||
UPDATE Episodes
|
UPDATE Episodes
|
||||||
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
||||||
CASE
|
CASE
|
||||||
|
WHEN SeasonNumber IS NULL AND AbsoluteNumber IS NULL THEN ''
|
||||||
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
||||||
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
||||||
END
|
END
|
||||||
@ -41,6 +42,7 @@ namespace Kyoo.SqLite.Migrations
|
|||||||
UPDATE Episodes
|
UPDATE Episodes
|
||||||
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
SET Slug = (SELECT Slug from Shows WHERE ID = ShowID) ||
|
||||||
CASE
|
CASE
|
||||||
|
WHEN SeasonNumber IS NULL AND AbsoluteNumber IS NULL THEN ''
|
||||||
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
||||||
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
||||||
END
|
END
|
||||||
@ -56,6 +58,7 @@ namespace Kyoo.SqLite.Migrations
|
|||||||
UPDATE Episodes
|
UPDATE Episodes
|
||||||
SET Slug = new.Slug ||
|
SET Slug = new.Slug ||
|
||||||
CASE
|
CASE
|
||||||
|
WHEN SeasonNumber IS NULL AND AbsoluteNumber IS NULL THEN ''
|
||||||
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
WHEN SeasonNumber IS NULL THEN '-' || AbsoluteNumber
|
||||||
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
ELSE '-s' || SeasonNumber || 'e' || EpisodeNumber
|
||||||
END
|
END
|
||||||
|
@ -167,6 +167,26 @@ namespace Kyoo.Tests.Library
|
|||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-12", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-12", episode.Slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add movies tests.
|
[Fact]
|
||||||
|
public async Task MovieEpisodeTest()
|
||||||
|
{
|
||||||
|
Episode episode = await _repository.Create(TestSample.GetMovieEpisode());
|
||||||
|
Assert.Equal(TestSample.Get<Show>().Slug, episode.Slug);
|
||||||
|
episode = await _repository.Get(3);
|
||||||
|
Assert.Equal(TestSample.Get<Show>().Slug, episode.Slug);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task MovieEpisodeEditTest()
|
||||||
|
{
|
||||||
|
await _repository.Create(TestSample.GetMovieEpisode());
|
||||||
|
await Repositories.LibraryManager.Edit(new Show
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
Slug = "john-wick"
|
||||||
|
}, false);
|
||||||
|
Episode episode = await _repository.Get(3);
|
||||||
|
Assert.Equal("john-wick", episode.Slug);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
@ -29,9 +30,11 @@ namespace Kyoo.Tests.Library
|
|||||||
public abstract class ALibraryItemTest
|
public abstract class ALibraryItemTest
|
||||||
{
|
{
|
||||||
private readonly ILibraryItemRepository _repository;
|
private readonly ILibraryItemRepository _repository;
|
||||||
|
private readonly RepositoryActivator _repositories;
|
||||||
|
|
||||||
public ALibraryItemTest(RepositoryActivator repositories)
|
protected ALibraryItemTest(RepositoryActivator repositories)
|
||||||
{
|
{
|
||||||
|
_repositories = repositories;
|
||||||
_repository = repositories.LibraryManager.LibraryItemRepository;
|
_repository = repositories.LibraryManager.LibraryItemRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,5 +59,31 @@ namespace Kyoo.Tests.Library
|
|||||||
LibraryItem actual = await _repository.Get(-1);
|
LibraryItem actual = await _repository.Get(-1);
|
||||||
KAssert.DeepEqual(expected, actual);
|
KAssert.DeepEqual(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetShowSlugTests()
|
||||||
|
{
|
||||||
|
LibraryItem expected = new(TestSample.Get<Show>());
|
||||||
|
LibraryItem actual = await _repository.Get(TestSample.Get<Show>().Slug);
|
||||||
|
KAssert.DeepEqual(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetCollectionSlugTests()
|
||||||
|
{
|
||||||
|
LibraryItem expected = new(TestSample.Get<Collection>());
|
||||||
|
LibraryItem actual = await _repository.Get(TestSample.Get<Collection>().Slug);
|
||||||
|
KAssert.DeepEqual(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task GetDuplicatedSlugTests()
|
||||||
|
{
|
||||||
|
await _repositories.LibraryManager.Create(new Collection()
|
||||||
|
{
|
||||||
|
Slug = TestSample.Get<Show>().Slug
|
||||||
|
});
|
||||||
|
await Assert.ThrowsAsync<InvalidOperationException>(() => _repository.Get(TestSample.Get<Show>().Slug));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -154,5 +154,20 @@ namespace Kyoo.Tests
|
|||||||
ReleaseDate = new DateTime(2020, 06, 05)
|
ReleaseDate = new DateTime(2020, 06, 05)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Episode GetMovieEpisode()
|
||||||
|
{
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
ID = 3,
|
||||||
|
ShowSlug = "anohana",
|
||||||
|
ShowID = 1,
|
||||||
|
Path = "/home/kyoo/john-wick",
|
||||||
|
Thumb = "thumb",
|
||||||
|
Title = "John wick",
|
||||||
|
Overview = "A movie episode test",
|
||||||
|
ReleaseDate = new DateTime(1595, 05, 12)
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user