Skip to content

Commit

Permalink
test(requests): requesting listed movies and shows
Browse files Browse the repository at this point in the history
  • Loading branch information
seferturan committed Feb 9, 2025
1 parent 0398a08 commit 0cd3ec4
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ListedMoviesMappedMock } from '$mocks/data/lists/mapped/ListedMoviesMappedMock.ts';
import { runQuery } from '$test/beds/query/runQuery.ts';
import { createQuery } from '@tanstack/svelte-query';
import { describe, expect, it } from 'vitest';
import { listMovieItemsQuery } from './listMovieItemsQuery.ts';

describe('listMovieItemsQuery', () => {
it('should query for movies on a list', async () => {
const result = await runQuery({
factory: () => createQuery(listMovieItemsQuery({ id: 1 })),
mapper: (response) => response?.data,
});

expect(result).to.deep.equal(ListedMoviesMappedMock);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { ListedShowsMappedMock } from '$mocks/data/lists/mapped/ListedShowsMappedMock.ts';
import { runQuery } from '$test/beds/query/runQuery.ts';
import { createQuery } from '@tanstack/svelte-query';
import { describe, expect, it } from 'vitest';
import { listShowItemsQuery } from './listShowItemsQuery.ts';

describe('listShowItemsQuery', () => {
it('should query for shows on a list', async () => {
const result = await runQuery({
factory: () => createQuery(listShowItemsQuery({ id: 1 })),
mapper: (response) => response?.data,
});

expect(result).to.deep.equal(ListedShowsMappedMock);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ListedMovie } from '$lib/requests/queries/lists/listMovieItemsQuery.ts';
import { MovieMatrixMappedMock } from '$mocks/data/summary/movies/matrix/MovieMatrixMappedMock.ts';

export const ListedMoviesMappedMock: ListedMovie[] = [
{
'entry': MovieMatrixMappedMock,
'id': 1146014560,
'listedAt': new Date('2024-12-27T21:34:14.000Z'),
'notes': null,
'rank': 1,
'type': 'movie',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ListedShow } from '$lib/requests/queries/lists/listShowItemsQuery.ts';
import { ShowSiloMappedMock } from '$mocks/data/summary/shows/silo/mapped/ShowSiloMappedMock.ts';

export const ListedShowsMappedMock: ListedShow[] = [
{
'entry': ShowSiloMappedMock,
'id': 1234,
'listedAt': new Date('2024-12-27T21:34:14.000Z'),
'notes': null,
'rank': 1,
'type': 'show',
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MovieMatrixResponseMock } from '$mocks/data/summary/movies/matrix/MovieMatrixResponseMock.ts';
import type { ListedMovieResponse } from '@trakt/api';

export const ListedMoviesResponseMock: ListedMovieResponse[] = [
{
'rank': 1,
'id': 1146014560,
'listed_at': '2024-12-27T21:34:14.000Z',
'notes': null,
'type': 'movie',
'movie': MovieMatrixResponseMock,
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ShowSiloResponseMock } from '$mocks/data/summary/shows/silo/response/ShowSiloResponseMock.ts';
import type { ListedShowResponse } from '@trakt/api';

export const ListedShowsResponseMock: ListedShowResponse[] = [
{
'rank': 1,
'id': 1234,
'listed_at': '2024-12-27T21:34:14.000Z',
'notes': null,
'type': 'show',
'show': ShowSiloResponseMock,
},
];
13 changes: 13 additions & 0 deletions projects/client/src/mocks/handlers/lists.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ListedMoviesResponseMock } from '$mocks/data/lists/response/ListedMoviesResponseMock.ts';
import { ListedShowsResponseMock } from '$mocks/data/lists/response/ListedShowsResponseMock.ts';

import { http, HttpResponse } from 'msw';

export const lists = [
http.get(`http://localhost/lists/*/items/movies*`, () => {
return HttpResponse.json(ListedMoviesResponseMock);
}),
http.get(`http://localhost/lists/*/items/shows*`, () => {
return HttpResponse.json(ListedShowsResponseMock);
}),
];
2 changes: 2 additions & 0 deletions projects/client/src/mocks/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { setupServer } from 'msw/node';
import { auth } from './handlers/auth.ts';
import { calendars } from './handlers/calendars.ts';
import { episodes } from './handlers/episodes.ts';
import { lists } from './handlers/lists.ts';
import { movies } from './handlers/movies.ts';
import { people } from './handlers/people.ts';
import { recommendations } from './handlers/recommendations.ts';
Expand All @@ -23,6 +24,7 @@ const handlers = [
...recommendations,
...calendars,
...search,
...lists,
];

export const server = setupServer(...handlers);

0 comments on commit 0cd3ec4

Please sign in to comment.