test(tvdb): add tvdb tests

This commit is contained in:
TOomaAh
2024-10-27 11:23:05 +01:00
parent c5987e2275
commit f4997d0aa0
9 changed files with 104 additions and 17 deletions

View File

@@ -0,0 +1,91 @@
describe('TVDB Integration', () => {
// Constants for routes and selectors
const ROUTES = {
home: '/',
tvdbSettings: '/settings/tvdb',
pokemonShow: '/tv/72879',
};
const SELECTORS = {
sidebarToggle: '[data-testid=sidebar-toggle]',
sidebarSettingsMobile: '[data-testid=sidebar-menu-settings-mobile]',
settingsNavDesktop: 'nav[data-testid="settings-nav-desktop"]',
tvdbEnable: 'input[data-testid="tvdb-enable"]',
tvdbSaveButton: '[data-testid=tvbd-save-button]',
heading: '.heading',
season1: 'Season 1',
season2: 'Season 2',
};
// Reusable commands
const toggleTVDBSetting = () => {
cy.intercept('/api/v1/settings/tvdb').as('tvdbRequest');
cy.get(SELECTORS.tvdbSaveButton).click();
return cy.wait('@tvdbRequest');
};
const verifyTVDBResponse = (response, expectedUseValue) => {
expect(response.statusCode).to.equal(200);
expect(response.body.use).to.equal(expectedUseValue);
};
beforeEach(() => {
// Perform login
cy.login(Cypress.env('ADMIN_EMAIL'), Cypress.env('ADMIN_PASSWORD'));
// Navigate to TVDB settings
cy.visit(ROUTES.home);
cy.get(SELECTORS.sidebarToggle).click();
cy.get(SELECTORS.sidebarSettingsMobile).click();
cy.get(
`${SELECTORS.settingsNavDesktop} a[href="${ROUTES.tvdbSettings}"]`
).click();
// Verify heading
cy.get(SELECTORS.heading).should('contain', 'Tvdb');
// Configure TVDB settings
cy.get(SELECTORS.tvdbEnable).then(($checkbox) => {
const isChecked = $checkbox.is(':checked');
if (!isChecked) {
// If disabled, enable TVDB
cy.wrap($checkbox).click();
toggleTVDBSetting().then(({ response }) => {
verifyTVDBResponse(response, true);
});
} else {
// If enabled, disable then re-enable TVDB
cy.wrap($checkbox).click();
toggleTVDBSetting().then(({ response }) => {
verifyTVDBResponse(response, false);
});
cy.wrap($checkbox).click();
toggleTVDBSetting().then(({ response }) => {
verifyTVDBResponse(response, true);
});
}
});
});
it('should display "Tomorrow is Ours" show information correctly (1 season on TMDB >1 seasons on TVDB)', () => {
cy.visit(ROUTES.pokemonShow);
cy.contains(SELECTORS.season2)
.should('be.visible')
.scrollIntoView()
.click();
});
it('Should display "Monster" show information correctly (Not existing on TVDB)', () => {
cy.visit('/tv/225634');
cy.intercept('/api/v1/tv/225634/season/1').as('season1');
cy.contains(SELECTORS.season1)
.should('be.visible')
.scrollIntoView()
.click();
cy.wait('@season1');
cy.contains('9 - Hang Men').should('be.visible');
});
});

View File

@@ -17,7 +17,7 @@ describe('TV Details', () => {
cy.visit('/tv/66732'); cy.visit('/tv/66732');
// intercept request for season info // intercept request for season info
cy.intercept('/api/v1/tv/66732/season/4/163313').as('season4'); cy.intercept('/api/v1/tv/66732/season/4').as('season4');
cy.contains('Season 4').should('be.visible').scrollIntoView().click(); cy.contains('Season 4').should('be.visible').scrollIntoView().click();

View File

@@ -6532,7 +6532,7 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/TvDetails' $ref: '#/components/schemas/TvDetails'
/tv/{tvId}/season/{seasonNumber}/{seasonId}: /tv/{tvId}/season/{seasonNumber}:
get: get:
summary: Get season details and episode list summary: Get season details and episode list
description: Returns season details with a list of episodes in a JSON object. description: Returns season details with a list of episodes in a JSON object.
@@ -6545,12 +6545,6 @@ paths:
schema: schema:
type: number type: number
example: 76479 example: 76479
- in: path
name: seasonId
required: true
schema:
type: number
example: 1
- in: path - in: path
name: seasonNumber name: seasonNumber
required: true required: true

View File

@@ -13,12 +13,10 @@ export interface TvShowIndexer {
}): Promise<TmdbTvDetails>; }): Promise<TmdbTvDetails>;
getTvSeason({ getTvSeason({
tvId, tvId,
seasonId,
seasonNumber, seasonNumber,
language, language,
}: { }: {
tvId: number; tvId: number;
seasonId: number;
seasonNumber: number; seasonNumber: number;
language?: string; language?: string;
}): Promise<TmdbSeasonWithEpisodes>; }): Promise<TmdbSeasonWithEpisodes>;

View File

@@ -15,6 +15,12 @@ tvdbRoutes.get('/', (_req, res) => {
tvdbRoutes.put('/', (req, res) => { tvdbRoutes.put('/', (req, res) => {
const settings = getSettings(); const settings = getSettings();
if (!settings.tvdb) {
settings.tvdb = {
use: false,
};
}
const newTvdb = req.body as TvdbSettings; const newTvdb = req.body as TvdbSettings;
const tvdb = settings.tvdb; const tvdb = settings.tvdb;

View File

@@ -56,14 +56,12 @@ tvRoutes.get('/:id', async (req, res, next) => {
} }
}); });
tvRoutes.get('/:id/season/:seasonNumber/:seasonId', async (req, res, next) => { tvRoutes.get('/:id/season/:seasonNumber', async (req, res, next) => {
try { try {
const indexer = getIndexer(); const indexer = getIndexer();
const seasonIdentifier = indexer.getSeasonIdentifier(req);
const season = await indexer.getTvSeason({ const season = await indexer.getTvSeason({
tvId: Number(req.params.id), tvId: Number(req.params.id),
seasonId: seasonIdentifier,
seasonNumber: Number(req.params.seasonNumber), seasonNumber: Number(req.params.seasonNumber),
}); });

View File

@@ -118,6 +118,7 @@ const SettingsTvdb = () => {
</label> </label>
<div className="form-input-area"> <div className="form-input-area">
<Field <Field
data-testid="tvdb-enable"
type="checkbox" type="checkbox"
id="enable" id="enable"
name="enable" name="enable"
@@ -165,6 +166,7 @@ const SettingsTvdb = () => {
</span> </span>
<span className="ml-3 inline-flex rounded-md shadow-sm"> <span className="ml-3 inline-flex rounded-md shadow-sm">
<Button <Button
data-testid="tvbd-save-button"
buttonType="primary" buttonType="primary"
type="submit" type="submit"
disabled={isSubmitting || !isValid} disabled={isSubmitting || !isValid}

View File

@@ -14,13 +14,12 @@ const messages = defineMessages('components.TvDetails.Season', {
type SeasonProps = { type SeasonProps = {
seasonNumber: number; seasonNumber: number;
tvId: number; tvId: number;
seasonId: number;
}; };
const Season = ({ seasonNumber, tvId, seasonId }: SeasonProps) => { const Season = ({ seasonNumber, tvId }: SeasonProps) => {
const intl = useIntl(); const intl = useIntl();
const { data, error } = useSWR<SeasonWithEpisodes>( const { data, error } = useSWR<SeasonWithEpisodes>(
`/api/v1/tv/${tvId}/season/${seasonNumber}/${seasonId}` `/api/v1/tv/${tvId}/season/${seasonNumber}`
); );
if (!data && !error) { if (!data && !error) {

View File

@@ -1076,7 +1076,6 @@ const TvDetails = ({ tv }: TvDetailsProps) => {
<Season <Season
tvId={data.id} tvId={data.id}
seasonNumber={season.seasonNumber} seasonNumber={season.seasonNumber}
seasonId={season.id}
/> />
</Disclosure.Panel> </Disclosure.Panel>
</Transition> </Transition>