forked from verdnatura/salix-front
Updated unit test
This commit is contained in:
parent
7b2a4d75c6
commit
c16ef7e783
|
@ -1,8 +1,12 @@
|
|||
import { jest, describe, expect, it, beforeAll } from '@jest/globals';
|
||||
import { createWrapper } from 'app/tests/jest/jestHelpers';
|
||||
import App from '../App.vue';
|
||||
import { useSession } from 'src/composables/useSession';
|
||||
|
||||
const mockPush = jest.fn();
|
||||
const mockLoggedIn = jest.fn();
|
||||
const mockDestroy = jest.fn();
|
||||
const session = useSession();
|
||||
|
||||
jest.mock('vue-router', () => ({
|
||||
useRouter: () => ({
|
||||
|
@ -11,12 +15,19 @@ jest.mock('vue-router', () => ({
|
|||
}),
|
||||
}));
|
||||
|
||||
// jest.mock('vue-i18n', () => ({
|
||||
// createI18n: () => { },
|
||||
// useI18n: () => ({
|
||||
// t: () => { }
|
||||
// }),
|
||||
// }));
|
||||
jest.mock('src/composables/useSession', () => ({
|
||||
useSession: () => ({
|
||||
isLoggedIn: mockLoggedIn,
|
||||
destroy: mockDestroy
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('vue-i18n', () => ({
|
||||
createI18n: () => { },
|
||||
useI18n: () => ({
|
||||
t: () => { }
|
||||
}),
|
||||
}));
|
||||
|
||||
describe('App', () => {
|
||||
let vm;
|
||||
|
@ -27,33 +38,64 @@ describe('App', () => {
|
|||
}
|
||||
};
|
||||
vm = createWrapper(App, options).vm;
|
||||
|
||||
});
|
||||
|
||||
it('should not set the token into session if any error occurred', async () => {
|
||||
// jest.spyOn(vm.routerView).mockReturnValue(routerView);
|
||||
jest.spyOn(vm.quasar, 'notify')
|
||||
it('should return a login error message', async () => {
|
||||
jest.spyOn(vm.quasar, 'notify');
|
||||
|
||||
session.isLoggedIn.mockReturnValue(false);
|
||||
|
||||
const response = {
|
||||
response: {
|
||||
status: 401
|
||||
}
|
||||
};
|
||||
|
||||
let error;
|
||||
try {
|
||||
const response = {
|
||||
response: {
|
||||
status: 403
|
||||
}
|
||||
};
|
||||
await vm.responseError(response);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//await vm.onSubmit();
|
||||
|
||||
expect(error).toEqual(expect.objectContaining(response));
|
||||
expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining(
|
||||
{
|
||||
type: 'negative',
|
||||
message: 'test'
|
||||
message: 'login.loginError'
|
||||
}
|
||||
));
|
||||
});
|
||||
|
||||
it('should return an unauthorized error message', async () => {
|
||||
jest.spyOn(vm.quasar, 'notify');
|
||||
|
||||
session.isLoggedIn.mockReturnValue(true);
|
||||
|
||||
const response = {
|
||||
response: {
|
||||
status: 401
|
||||
}
|
||||
};
|
||||
|
||||
let error;
|
||||
try {
|
||||
await vm.responseError(response);
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
|
||||
expect(error).toEqual(expect.objectContaining(response));
|
||||
expect(vm.quasar.notify).toHaveBeenCalledWith(expect.objectContaining(
|
||||
{
|
||||
type: 'negative',
|
||||
message: 'errors.statusUnauthorized'
|
||||
}
|
||||
));
|
||||
|
||||
expect(session.destroy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue