feat: Add unit-tests #25

Merged
timharek merged 31 commits from feature-testing into main 2024-04-11 19:10:16 +00:00
1 changed files with 9 additions and 7 deletions
Showing only changes of commit 48eade901a - Show all commits

View File

@ -32,16 +32,18 @@ async function updateFetch(existingSeries: Series): Promise<UpdatedSeries | null
return !existingSeries.episodes.find((serieEpisode) => serieEpisode.id === episode.id); return !existingSeries.episodes.find((serieEpisode) => serieEpisode.id === episode.id);
}); });
const updated = {
...existingSeries,
lastFetch: new Date(),
/** /**
* Since we don't control the API, * Since we don't control the API,
* we should not make assumptions about the order, * we should not make assumptions about the order,
* but rather sort the episode to what we want. * but rather sort the episode to what we want.
*/ */
episodes: [...newEpisodes, ...existingSeries.episodes] const episodesSorted = [...newEpisodes, ...existingSeries.episodes]
.sort((a, b) => a.date.getTime() > b.date.getTime() ? -1 : 1), .sort((a, b) => a.date.getTime() > b.date.getTime() ? -1 : 1);
const updated = {
...existingSeries,
lastFetch: new Date(),
episodes: episodesSorted,
}; };
const updateSuccessful = await storage.write(updated); const updateSuccessful = await storage.write(updated);