mirror of
https://github.com/jellyfin/jellyfin-vue.git
synced 2024-11-27 16:20:36 +00:00
Merge pull request #747 from jellyfin/test-server-middlware
test(server middleware): add tests for server middleware
This commit is contained in:
commit
12830dabeb
68
middleware/__tests__/serverMiddleware.spec.ts
Normal file
68
middleware/__tests__/serverMiddleware.spec.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { Context } from '@nuxt/types/app';
|
||||
import serverMiddleware from '../serverMiddleware';
|
||||
|
||||
const mockRedirect = jest.fn();
|
||||
|
||||
const BASE_INPUT = ({
|
||||
$axios: {
|
||||
defaults: {
|
||||
baseURL: ''
|
||||
}
|
||||
},
|
||||
store: {
|
||||
state: {
|
||||
servers: {
|
||||
serverList: []
|
||||
}
|
||||
}
|
||||
},
|
||||
redirect: mockRedirect
|
||||
} as unknown) as Context;
|
||||
|
||||
const INPUT_WITH_BASEURL = ({
|
||||
...BASE_INPUT,
|
||||
$axios: { defaults: { baseURL: 'test-url' } }
|
||||
} as unknown) as Context;
|
||||
|
||||
const INPUT_WITH_SERVERLIST = ({
|
||||
...BASE_INPUT,
|
||||
store: { state: { servers: { serverList: ['item-a'] } } }
|
||||
} as unknown) as Context;
|
||||
|
||||
const INPUT_WITH_BOTH = ({
|
||||
...BASE_INPUT,
|
||||
$axios: { defaults: { baseURL: 'test-url' } },
|
||||
store: { state: { servers: { serverList: ['item-a'] } } }
|
||||
} as unknown) as Context;
|
||||
|
||||
const EXPECTED_REDIRECT = '/addserver';
|
||||
|
||||
afterEach(() => mockRedirect.mockReset());
|
||||
|
||||
describe('serverMiddleware', () => {
|
||||
it('redirects to "/addserver/ when a baseUrl is not set', (): void => {
|
||||
serverMiddleware(BASE_INPUT);
|
||||
|
||||
expect(mockRedirect).toHaveBeenCalled();
|
||||
|
||||
expect(mockRedirect.mock.calls[0][0]).toBe(EXPECTED_REDIRECT);
|
||||
});
|
||||
|
||||
it('redirects to "/addserver" when the serverlist length is 0', (): void => {
|
||||
serverMiddleware(INPUT_WITH_BASEURL);
|
||||
|
||||
expect(mockRedirect.mock.calls[0][0]).toBe(EXPECTED_REDIRECT);
|
||||
});
|
||||
|
||||
it('redirects to "/addserver" when the baseUrl is undefined', (): void => {
|
||||
serverMiddleware(INPUT_WITH_SERVERLIST);
|
||||
|
||||
expect(mockRedirect.mock.calls[0][0]).toBe(EXPECTED_REDIRECT);
|
||||
});
|
||||
|
||||
it('does not redirect when a baseUrl is set and a serverlist is defined', (): void => {
|
||||
serverMiddleware(INPUT_WITH_BOTH);
|
||||
|
||||
expect(mockRedirect.mock.calls).toHaveLength(0);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user