Satellite Web store test coverage (#948)

* Added 100% test coverage for Users store module.

* Added 100% coverage for Projects store module.

* Added 100% coverage for ProjectMembers store module.
This commit is contained in:
Bogdan Artemenko 2019-01-08 17:14:00 +02:00 committed by GitHub
parent dfeaf406f0
commit 6f931759a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 796 additions and 19 deletions

View File

@ -0,0 +1,9 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
import { GlobalWithFetchMock } from 'jest-fetch-mock';
const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
customGlobal.fetch = require('jest-fetch-mock');
customGlobal.fetchMock = customGlobal.fetch;

View File

@ -39,6 +39,7 @@
"css-loader": "^1.0.0",
"eslint": "^5.9.0",
"eslint-plugin-vue": "^5.0.0",
"jest-fetch-mock": "^2.1.0",
"node-sass": "^4.9.0",
"sass-loader": "^7.0.1",
"sinon": "^7.0.0",
@ -68,6 +69,15 @@
"not ie <= 8"
],
"jest": {
"automock": false,
"setupFiles": [
"./jestSetup.ts"
],
"globals": {
"ts-jest": {
"diagnostics": false
}
},
"moduleFileExtensions": [
"js",
"jsx",
@ -76,12 +86,16 @@
"ts",
"tsx"
],
"collectCoverage": true,
"transform": {
"^.+\\.js$": "babel-jest",
"^.+\\.vue$": "vue-jest",
".+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$": "jest-transform-stub",
"^.+\\.tsx?$": "ts-jest"
},
"transformIgnorePatterns": [
"/node_modules/(?!(apollo-client|apollo-link))"
],
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},

View File

@ -6,7 +6,7 @@ import gql from 'graphql-tag';
// Performs graqhQL request.
// Throws an exception if error occurs
export async function addProjectMembers(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
export async function addProjectMembersRequest(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
let result: RequestResponse<null> = {
errorMessage: '',
isSuccess: false,
@ -42,7 +42,7 @@ export async function addProjectMembers(projectID: string, emails: string[]): Pr
// Performs graqhQL request.
// Throws an exception if error occurs
export async function deleteProjectMembers(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
export async function deleteProjectMembersRequest(projectID: string, emails: string[]): Promise<RequestResponse<null>> {
let result: RequestResponse<null> = {
errorMessage: '',
isSuccess: false,
@ -78,7 +78,7 @@ export async function deleteProjectMembers(projectID: string, emails: string[]):
// Performs graqhQL request.
// Throws an exception if error occurs
export async function fetchProjectMembers(projectID: string, limit: string, offset: string): Promise<RequestResponse<TeamMemberModel[]>> {
export async function fetchProjectMembersRequest(projectID: string, limit: string, offset: string): Promise<RequestResponse<TeamMemberModel[]>> {
let result: RequestResponse<TeamMemberModel[]> = {
errorMessage: '',
isSuccess: false,

View File

@ -5,7 +5,7 @@ import apollo from '@/utils/apolloManager';
import gql from 'graphql-tag';
// Performs graqhQL request for project creation.
export async function createProject(project: Project): Promise<RequestResponse<Project>> {
export async function createProjectRequest(project: Project): Promise<RequestResponse<Project>> {
let result: RequestResponse<Project> = {
errorMessage: '',
isSuccess: false,
@ -44,7 +44,7 @@ export async function createProject(project: Project): Promise<RequestResponse<P
}
// Performs graqhQL request for fetching all projects of current user.
export async function fetchProjects(): Promise<RequestResponse<Project[]>> {
export async function fetchProjectsRequest(): Promise<RequestResponse<Project[]>> {
let result: RequestResponse<Project[]> = {
errorMessage: '',
isSuccess: false,
@ -82,7 +82,7 @@ export async function fetchProjects(): Promise<RequestResponse<Project[]>> {
}
// Performs graqhQL request for updating selected project description
export async function updateProject(projectID: string, description: string): Promise<RequestResponse<null>> {
export async function updateProjectRequest(projectID: string, description: string): Promise<RequestResponse<null>> {
let result: RequestResponse<null> = {
errorMessage: '',
isSuccess: false,
@ -117,7 +117,7 @@ export async function updateProject(projectID: string, description: string): Pro
}
// Performs graqhQL request for deleting selected project
export async function deleteProject(projectID: string): Promise<RequestResponse<null>> {
export async function deleteProjectRequest(projectID: string): Promise<RequestResponse<null>> {
let result: RequestResponse<null> = {
errorMessage: '',
isSuccess: false,

View File

@ -2,7 +2,11 @@
// See LICENSE for copying information.
import { PROJECT_MEMBER_MUTATIONS } from '../mutationConstants';
import { addProjectMembers, deleteProjectMembers, fetchProjectMembers } from '@/api/projectMembers';
import {
addProjectMembersRequest,
deleteProjectMembersRequest,
fetchProjectMembersRequest
} from '@/api/projectMembers';
export const projectMembersModule = {
state: {
@ -45,14 +49,12 @@ export const projectMembersModule = {
addProjectMembers: async function ({rootGetters}: any, emails: string[]): Promise<RequestResponse<null>> {
const projectId = rootGetters.selectedProject.id;
const response = await addProjectMembers(projectId, emails);
return response;
return await addProjectMembersRequest(projectId, emails);
},
deleteProjectMembers: async function ({commit, rootGetters}: any, projectMemberEmails: string[]): Promise<RequestResponse<null>> {
const projectId = rootGetters.selectedProject.id;
const response = await deleteProjectMembers(projectId, projectMemberEmails);
const response = await deleteProjectMembersRequest(projectId, projectMemberEmails);
if (response.isSuccess) {
commit(PROJECT_MEMBER_MUTATIONS.DELETE, projectMemberEmails);
@ -68,7 +70,7 @@ export const projectMembersModule = {
},
fetchProjectMembers: async function ({commit, rootGetters}: any, limitoffset: any): Promise<RequestResponse<TeamMemberModel[]>> {
const projectId = rootGetters.selectedProject.id;
const response = await fetchProjectMembers(projectId, limitoffset.limit, limitoffset.offset);
const response = await fetchProjectMembersRequest(projectId, limitoffset.limit, limitoffset.offset);
if (response.isSuccess) {
commit(PROJECT_MEMBER_MUTATIONS.FETCH, response.data);

View File

@ -2,7 +2,7 @@
// See LICENSE for copying information.
import { PROJECTS_MUTATIONS } from '../mutationConstants';
import { createProject, deleteProject, fetchProjects, updateProject } from '@/api/projects';
import { createProjectRequest, deleteProjectRequest, fetchProjectsRequest, updateProjectRequest } from '@/api/projects';
export const projectsModule = {
state: {
@ -63,7 +63,7 @@ export const projectsModule = {
},
actions: {
fetchProjects: async function ({commit}: any): Promise<RequestResponse<Project[]>> {
let response: RequestResponse<Project[]> = await fetchProjects();
let response: RequestResponse<Project[]> = await fetchProjectsRequest();
if (response.isSuccess) {
commit(PROJECTS_MUTATIONS.FETCH, response.data);
@ -72,7 +72,7 @@ export const projectsModule = {
return response;
},
createProject: async function ({commit}: any, project: Project): Promise<RequestResponse<Project>> {
let response = await createProject(project);
let response = await createProjectRequest(project);
if (response.isSuccess) {
commit(PROJECTS_MUTATIONS.CREATE, response.data);
@ -84,7 +84,7 @@ export const projectsModule = {
commit(PROJECTS_MUTATIONS.SELECT, projectID);
},
updateProjectDescription: async function ({commit}: any, updateProjectModel: UpdateProjectModel): Promise<RequestResponse<null>> {
let response = await updateProject(updateProjectModel.id, updateProjectModel.description);
let response = await updateProjectRequest(updateProjectModel.id, updateProjectModel.description);
if (response.isSuccess) {
commit(PROJECTS_MUTATIONS.UPDATE, updateProjectModel);
@ -93,7 +93,7 @@ export const projectsModule = {
return response;
},
deleteProject: async function ({commit}: any, projectID: string): Promise<RequestResponse<null>> {
let response = await deleteProject(projectID);
let response = await deleteProjectRequest(projectID);
if (response.isSuccess) {
commit(PROJECTS_MUTATIONS.DELETE, projectID);

View File

@ -27,7 +27,6 @@ export const usersModule = {
state.user.firstName = '';
state.user.lastName = '';
state.user.email = '';
state.user.id = '';
},
[USER_MUTATIONS.UPDATE_USER_INFO](state: any, user: User): void {

View File

@ -10,6 +10,7 @@ import { getToken } from '@/utils/tokenManager';
// Satellite url
const satelliteUrl = new HttpLink({
uri: 'http://localhost:8081/api/graphql/v0',
});
// Adding auth headers

View File

@ -0,0 +1,232 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
import { projectMembersModule } from '@/store/modules/projectMembers';
import {
addProjectMembersRequest,
deleteProjectMembersRequest,
fetchProjectMembersRequest
} from '@/api/projectMembers';
import { PROJECT_MEMBER_MUTATIONS } from '@/store/mutationConstants';
describe('mutations', () => {
it('success delete project members', () => {
const state = {
projectMembers: [{user: {email: '1'}}, {user: {email: '2'}}]
};
const membersToDelete = ['1', '2'];
projectMembersModule.mutations.DELETE_MEMBERS(state, membersToDelete);
expect(state.projectMembers.length).toBe(0);
});
it('error delete project members', () => {
const state = {
projectMembers: [{user: {email: '1'}}, {user: {email: '2'}}]
};
const membersToDelete = ['3', '4'];
projectMembersModule.mutations.DELETE_MEMBERS(state, membersToDelete);
expect(state.projectMembers.length).toBe(2);
});
it('toggle selection', () => {
const state = {
projectMembers: [{
user: {id: '1'},
isSelected: false
}, {
user: {id: '2'},
isSelected: false
}]
};
const memberId = '1';
projectMembersModule.mutations.TOGGLE_SELECTION(state, memberId);
expect(state.projectMembers[0].isSelected).toBeTruthy();
expect(state.projectMembers[1].isSelected).toBeFalsy();
});
it('clear selection', () => {
const state = {
projectMembers: [{
user: {id: '1'},
isSelected: true
}, {
user: {id: '2'},
isSelected: true
}]
};
projectMembersModule.mutations.CLEAR_SELECTION(state);
expect(state.projectMembers[0].isSelected).toBeFalsy();
expect(state.projectMembers[1].isSelected).toBeFalsy();
});
it('fetch team members', () => {
const state = {
projectMembers: []
};
const teamMembers = [{
user: {id: '1'}
}];
projectMembersModule.mutations.FETCH_MEMBERS(state, teamMembers);
expect(state.projectMembers.length).toBe(1);
});
});
describe('actions', () => {
it('success add project members', async function () {
const rootGetters = {
selectedProject: {
id: '1'
}
};
addProjectMembersRequest = jest.fn().mockReturnValue({isSuccess: true});
const emails = ['1', '2'];
const dispatchResponse = await projectMembersModule.actions.addProjectMembers({rootGetters}, emails);
expect(dispatchResponse.isSuccess).toBeTruthy();
});
it('error add project members', async function () {
const rootGetters = {
selectedProject: {
id: '1'
}
};
addProjectMembersRequest = jest.fn().mockReturnValue({isSuccess: false});
const emails = ['1', '2'];
const dispatchResponse = await projectMembersModule.actions.addProjectMembers({rootGetters}, emails);
expect(dispatchResponse.isSuccess).toBeFalsy();
});
it('success delete project members', async () => {
const rootGetters = {
selectedProject: {
id: '1'
}
}
;
deleteProjectMembersRequest = jest.fn().mockReturnValue({isSuccess: true});
const commit = jest.fn();
const emails = ['1', '2'];
const dispatchResponse = await projectMembersModule.actions.deleteProjectMembers({commit, rootGetters}, emails);
expect(dispatchResponse.isSuccess).toBeTruthy();
expect(commit).toHaveBeenCalledWith(PROJECT_MEMBER_MUTATIONS.DELETE, emails);
});
it('error delete project members', async () => {
const rootGetters = {
selectedProject: {
id: '1'
}
};
deleteProjectMembersRequest = jest.fn().mockReturnValue({isSuccess: false});
const commit = jest.fn();
const emails = ['1', '2'];
const dispatchResponse = await projectMembersModule.actions.deleteProjectMembers({commit, rootGetters}, emails);
expect(dispatchResponse.isSuccess).toBeFalsy();
expect(commit).toHaveBeenCalledTimes(0);
});
it('toggle selection', function () {
const commit = jest.fn();
const projectMemberId = '1';
projectMembersModule.actions.toggleProjectMemberSelection({commit}, projectMemberId);
expect(commit).toHaveBeenCalledWith(PROJECT_MEMBER_MUTATIONS.TOGGLE_SELECTION, projectMemberId);
});
it('clear selection', function () {
const commit = jest.fn();
projectMembersModule.actions.clearProjectMemberSelection({commit});
expect(commit).toHaveBeenCalledTimes(1);
});
it('success fetch project members', async function () {
const rootGetters = {
selectedProject: {
id: '1'
}
};
const commit = jest.fn();
const projectMemberMockModel: TeamMemberModel = {
user: {
id: '1',
email: '1',
firstName: '1',
lastName: '1'
},
joinedAt: '1'
};
fetchProjectMembersRequest = jest.fn().mockReturnValue({isSuccess: true, data: [projectMemberMockModel]});
const dispatchResponse = await projectMembersModule.actions.fetchProjectMembers({
commit,
rootGetters
}, {limit: '1', offset: '0'});
expect(dispatchResponse.isSuccess).toBeTruthy();
expect(commit).toHaveBeenCalledWith(PROJECT_MEMBER_MUTATIONS.FETCH, [projectMemberMockModel]);
});
it('error fetch project members', async function () {
const rootGetters = {
selectedProject: {
id: '1'
}
};
const commit = jest.fn();
fetchProjectMembersRequest = jest.fn().mockReturnValue({isSuccess: false});
const dispatchResponse = await projectMembersModule.actions.fetchProjectMembers({
commit,
rootGetters
}, {limit: '1', offset: '0'});
expect(dispatchResponse.isSuccess).toBeFalsy();
expect(commit).toHaveBeenCalledTimes(0);
});
});
describe('getters', () => {
it('project members', function () {
const state = {
projectMembers: [{user: {email: '1'}}]
};
const retrievedProjectMembers = projectMembersModule.getters.projectMembers(state);
expect(retrievedProjectMembers.length).toBe(1);
});
it('selected project members', function () {
const state = {
projectMembers: [
{isSelected: false},
{isSelected: true},
{isSelected: true},
{isSelected: true},
{isSelected: false},
]
};
const retrievedSelectedProjectMembers = projectMembersModule.getters.selectedProjectMembers(state);
expect(retrievedSelectedProjectMembers.length).toBe(3);
});
});

View File

@ -0,0 +1,335 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
import { projectsModule } from '@/store/modules/projects';
import { createProjectRequest, deleteProjectRequest, fetchProjectsRequest, updateProjectRequest } from '@/api/projects';
import { PROJECTS_MUTATIONS } from '@/store/mutationConstants';
describe('mutations', () => {
it('create project', () => {
const state = {
projects: [],
};
const project = {
name: 'testName',
};
projectsModule.mutations.CREATE_PROJECT(state, project);
expect(state.projects.length).toBe(1);
const mutatedProject: Project = state.projects[0];
expect(mutatedProject.name).toBe('testName');
});
it('fetch project', () => {
const state = {
projects: []
};
const projectsToPush = [{id: '1'}, {id: '2'}];
projectsModule.mutations.FETCH_PROJECTS(state, projectsToPush);
expect(state.projects.length).toBe(2);
});
it('success select project', () => {
const state = {
projects: [{id: '1'}, {id: 'testId'}, {id: '2'},],
selectedProject: {
id: ''
}
};
const projectId = 'testId';
projectsModule.mutations.SELECT_PROJECT(state, projectId);
expect(state.selectedProject.id).toBe('testId');
});
it('error select project', () => {
const state = {
projects: [{id: '1'}, {id: 'testId'}, {id: '2'},],
selectedProject: {
id: 'old'
}
};
const projectId = '3';
projectsModule.mutations.SELECT_PROJECT(state, projectId);
expect(state.selectedProject.id).toBe('old');
});
it('error update project not exist', () => {
const state = {
projects: [{id: '1'}, {id: 'testId'}, {id: '2'},],
selectedProject: {
id: 'old'
}
};
const projectId = {id: '3'};
projectsModule.mutations.UPDATE_PROJECT(state, projectId);
expect(state.selectedProject.id).toBe('old');
});
it('error update project not selected', () => {
const state = {
projects: [{id: '1'}, {id: 'testId'}, {id: '2'},],
selectedProject: {
id: 'old',
description: 'oldD'
}
};
const project = {id: '2', description: 'newD'};
projectsModule.mutations.UPDATE_PROJECT(state, project);
expect(state.selectedProject.id).toBe('old');
expect(state.selectedProject.description).toBe('oldD');
});
it('success update project', () => {
const state = {
projects: [{id: '1'}, {id: 'testId'}, {id: '2'}],
selectedProject: {
id: '2',
description: 'oldD'
}
};
const project = {id: '2', description: 'newD'};
projectsModule.mutations.UPDATE_PROJECT(state, project);
expect(state.selectedProject.id).toBe('2');
expect(state.selectedProject.description).toBe('newD');
});
it('error delete project', () => {
const state = {
selectedProject: {
id: '1',
}
};
const projectId = '2';
projectsModule.mutations.DELETE_PROJECT(state, projectId);
expect(state.selectedProject.id).toBe('1');
});
it('success delete project', () => {
const state = {
selectedProject: {
id: '2',
}
};
const projectId = '2';
projectsModule.mutations.DELETE_PROJECT(state, projectId);
expect(state.selectedProject.id).toBe('');
});
});
describe('actions', () => {
it('success fetch project', async () => {
fetchProjectsRequest = jest.fn().mockReturnValue({isSuccess: true, data: [{id: '1'}, {id: '2'}]});
const commit = jest.fn();
const dispatchResponse = await projectsModule.actions.fetchProjects({commit});
expect(dispatchResponse.isSuccess).toBeTruthy();
expect(commit).toHaveBeenCalledWith(PROJECTS_MUTATIONS.FETCH, [{id: '1'}, {id: '2'}]);
});
it('error fetch project', async () => {
fetchProjectsRequest = jest.fn().mockReturnValue({isSuccess: false});
const commit = jest.fn();
const dispatchResponse = await projectsModule.actions.fetchProjects({commit});
expect(dispatchResponse.isSuccess).toBeFalsy();
expect(commit).toHaveBeenCalledTimes(0);
});
it('success create project', async () => {
createProjectRequest = jest.fn().mockReturnValue({isSuccess: true, data: {id: '1'}});
const commit = jest.fn();
const project: Project = {
name: '',
id: '',
description: '',
isTermsAccepted: false,
isSelected: false,
createdAt: ''
};
const dispatchResponse = await projectsModule.actions.createProject({commit}, project);
expect(dispatchResponse.isSuccess).toBeTruthy();
expect(commit).toHaveBeenCalledWith(PROJECTS_MUTATIONS.CREATE, {id: '1'});
});
it('error create project', async () => {
createProjectRequest = jest.fn().mockReturnValue({isSuccess: false});
const commit = jest.fn();
const project: Project = {
name: '',
id: '',
description: '',
isTermsAccepted: false,
isSelected: false,
createdAt: ''
};
const dispatchResponse = await projectsModule.actions.createProject({commit}, project);
expect(dispatchResponse.isSuccess).toBeFalsy();
expect(commit).toHaveBeenCalledTimes(0);
});
it('success select project', () => {
const commit = jest.fn();
projectsModule.actions.selectProject({commit}, 'id');
expect(commit).toHaveBeenCalledWith(PROJECTS_MUTATIONS.SELECT, 'id');
});
it('success update project description', async () => {
updateProjectRequest = jest.fn().mockReturnValue({isSuccess: true});
const commit = jest.fn();
const project: Project = {
name: '',
id: 'id',
description: 'desc',
isTermsAccepted: false,
isSelected: false,
createdAt: ''
};
const dispatchResponse = await projectsModule.actions.updateProjectDescription({commit}, project);
expect(dispatchResponse.isSuccess).toBeTruthy();
expect(commit).toBeCalledWith(PROJECTS_MUTATIONS.UPDATE, project);
});
it('error update project description', async () => {
updateProjectRequest = jest.fn().mockReturnValue({isSuccess: false});
const commit = jest.fn();
const project: Project = {
name: '',
id: '',
description: '',
isTermsAccepted: false,
isSelected: false,
createdAt: ''
};
const dispatchResponse = await projectsModule.actions.updateProjectDescription({commit}, project);
expect(dispatchResponse.isSuccess).toBeFalsy();
expect(commit).toHaveBeenCalledTimes(0);
});
it('success delete project', async () => {
deleteProjectRequest = jest.fn().mockReturnValue({isSuccess: true});
const commit = jest.fn();
const project = 'id';
const dispatchResponse = await projectsModule.actions.deleteProject({commit}, project);
expect(dispatchResponse.isSuccess).toBeTruthy();
expect(commit).toHaveBeenCalledWith(PROJECTS_MUTATIONS.DELETE, project);
});
it('error delete project', async () => {
deleteProjectRequest = jest.fn().mockReturnValue({isSuccess: false});
const commit = jest.fn();
const dispatchResponse = await projectsModule.actions.deleteProject({commit}, 'id');
expect(dispatchResponse.isSuccess).toBeFalsy();
expect(commit).toHaveBeenCalledTimes(0);
});
});
describe('getters', () => {
it('getter projects', () => {
const state = {
projects: [{
name: '1',
id: '1',
companyName: '1',
description: '1',
isTermsAccepted: true,
createdAt: '1',
}],
selectedProject: {
id: '1'
}
};
const projectsGetterArray = projectsModule.getters.projects(state);
expect(projectsGetterArray.length).toBe(1);
const firstProject = projectsGetterArray[0];
expect(firstProject.name).toBe('1');
expect(firstProject.id).toBe('1');
expect(firstProject.description).toBe('1');
expect(firstProject.isTermsAccepted).toBe(true);
expect(firstProject.createdAt).toBe('1');
});
it('getter projects', () => {
const state = {
projects: [{
name: '1',
id: '1',
companyName: '1',
description: '1',
isTermsAccepted: true,
createdAt: '1',
}],
selectedProject: {
id: '2'
}
};
const projectsGetterArray = projectsModule.getters.projects(state);
expect(projectsGetterArray.length).toBe(1);
const firstProject = projectsGetterArray[0];
expect(firstProject.name).toBe('1');
expect(firstProject.id).toBe('1');
expect(firstProject.description).toBe('1');
expect(firstProject.isTermsAccepted).toBe(true);
expect(firstProject.createdAt).toBe('1');
});
it('getters selected project', () => {
const state = {
selectedProject: {
name: '1',
id: '1',
description: '1',
isTermsAccepted: true,
createdAt: '1',
}
};
const selectedProjectGetterObject = projectsModule.getters.selectedProject(state);
expect(selectedProjectGetterObject.name).toBe('1');
expect(selectedProjectGetterObject.id).toBe('1');
expect(selectedProjectGetterObject.description).toBe('1');
expect(selectedProjectGetterObject.isTermsAccepted).toBe(true);
expect(selectedProjectGetterObject.createdAt).toBe('1');
});
});

View File

@ -0,0 +1,185 @@
// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
import { usersModule } from '@/store/modules/users';
import { changePasswordRequest, deleteAccountRequest, getUserRequest, updateAccountRequest } from '@/api/users';
import { USER_MUTATIONS } from '@/store/mutationConstants';
describe('mutations', () => {
it('Set user info', () => {
const state = {
user: {
firstName: '',
lastName: '',
email: ''
}
};
const user = {
firstName: 'firstName',
lastName: 'lastName',
email: 'email'
};
usersModule.mutations.SET_USER_INFO(state, user);
expect(state.user.email).toBe('email');
expect(state.user.firstName).toBe('firstName');
expect(state.user.lastName).toBe('lastName');
});
it('clear user info', () => {
const state = {
user: {
firstName: 'firstName',
lastName: 'lastName',
email: 'email',
}
};
usersModule.mutations.REVERT_TO_DEFAULT_USER_INFO(state);
expect(state.user.email).toBe('');
expect(state.user.firstName).toBe('');
expect(state.user.lastName).toBe('');
});
it('Update user info', () => {
const state = {
user: {
firstName: '',
lastName: '',
email: ''
}
};
const user = {
firstName: 'firstName',
lastName: 'lastName',
email: 'email'
};
usersModule.mutations.UPDATE_USER_INFO(state, user);
expect(state.user.email).toBe('email');
expect(state.user.firstName).toBe('firstName');
expect(state.user.lastName).toBe('lastName');
});
});
describe('actions', () => {
it('success update account', async () => {
updateAccountRequest = jest.fn().mockReturnValue({
isSuccess: true, data: {
firstName: 'firstName',
lastName: 'lastName',
email: 'email',
}
});
const commit = jest.fn();
const user = {
firstName: '',
lastName: '',
email: ''
};
await usersModule.actions.updateAccount({commit}, user);
expect(commit).toHaveBeenCalledWith(USER_MUTATIONS.UPDATE_USER_INFO, {
firstName: 'firstName',
lastName: 'lastName',
email: 'email'
});
});
it('error update account', async () => {
updateAccountRequest = jest.fn().mockReturnValue({
isSuccess: false
});
const commit = jest.fn();
const user = {
firstName: '',
lastName: '',
email: ''
};
await usersModule.actions.updateAccount({commit}, user);
expect(commit).toHaveBeenCalledTimes(0);
});
it('password change', async () => {
changePasswordRequest = jest.fn().mockReturnValue({isSuccess: true});
const commit = jest.fn();
const updatePasswordModel = {oldPassword: 'o', newPassword: 'n'};
const requestResponse = await usersModule.actions.changePassword({commit}, updatePasswordModel);
expect(requestResponse.isSuccess).toBeTruthy();
});
it('delete account', async () => {
deleteAccountRequest = jest.fn().mockReturnValue({isSuccess: true});
const commit = jest.fn();
const password = '';
const requestResponse = await usersModule.actions.deleteAccount(commit, password);
expect(requestResponse.isSuccess).toBeTruthy();
});
it('success get user', async () => {
getUserRequest = jest.fn().mockReturnValue({
isSuccess: true,
data: {
firstName: '',
lastName: '',
email: ''
}
});
const commit = jest.fn();
const requestResponse = await usersModule.actions.getUser({commit});
expect(requestResponse.isSuccess).toBeTruthy();
});
it('error get user', async () => {
getUserRequest = jest.fn().mockReturnValue({isSuccess: false});
const commit = jest.fn();
const requestResponse = await usersModule.actions.getUser({commit});
expect(requestResponse.isSuccess).toBeFalsy();
});
});
describe('getters', () => {
it('user model', function () {
const state = {
user: {
firstName: 'firstName',
lastName: 'lastName',
email: 'email',
}
};
const retrievedUser = usersModule.getters.user(state);
expect(retrievedUser.firstName).toBe('firstName');
expect(retrievedUser.lastName).toBe('lastName');
expect(retrievedUser.email).toBe('email');
});
it('user name', function () {
const state = {
user: {
firstName: 'John',
lastName: 'Doe'
}
};
const retrievedUserName = usersModule.getters.userName(state);
expect(retrievedUserName).toBe('John Doe');
});
});