Skip to content

Commit

Permalink
10492: fix api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pixiwyn committed Oct 4, 2024
1 parent 1313dfe commit 7b5cb98
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { User } from '../../../../../shared/src/business/entities/User';
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext';
import { deleteUserCaseNoteInteractor } from './deleteUserCaseNoteInteractor';
import { deleteUserCaseNote as deleteUserCaseNoteMock } from '@web-api/persistence/postgres/userCaseNotes/deleteUserCaseNote';
import { mockJudgeUser } from '@shared/test/mockAuthUsers';
import { omit } from 'lodash';

describe('deleteUserCaseNoteInteractor', () => {
const deleteUserCaseNote = deleteUserCaseNoteMock as jest.Mock;

it('throws an error if the user is not valid or authorized', async () => {
let user = {} as UnknownAuthUser;

Expand All @@ -34,7 +37,7 @@ describe('deleteUserCaseNoteInteractor', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockReturnValue(mockUser);
applicationContext.getPersistenceGateway().deleteUserCaseNote = v => v;
deleteUserCaseNote.mockImplementation(v => v);
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue({
Expand All @@ -61,7 +64,6 @@ describe('deleteUserCaseNoteInteractor', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockReturnValue(mockUser);
applicationContext.getPersistenceGateway().deleteUserCaseNote = jest.fn();
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(null);
Expand All @@ -73,9 +75,8 @@ describe('deleteUserCaseNoteInteractor', () => {
omit(mockUser, 'section'),
);

expect(
applicationContext.getPersistenceGateway().deleteUserCaseNote.mock
.calls[0][0].userId,
).toEqual(mockJudgeUser.userId);
expect(deleteUserCaseNote.mock.calls[0][0].userId).toEqual(
mockJudgeUser.userId,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { User } from '../../../../../shared/src/business/entities/User';
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext';
import { getUserCaseNoteInteractor } from './getUserCaseNoteInteractor';
import { getUserCaseNote as getUserCaseNoteMock } from '@web-api/persistence/postgres/userCaseNotes/getUserCaseNote';
import { mockJudgeUser } from '@shared/test/mockAuthUsers';
import { omit } from 'lodash';

Expand All @@ -20,13 +21,13 @@ describe('Get case note', () => {
userId: 'unauthorizedUser',
} as unknown as UnknownAuthUser;

const getUserCaseNote = getUserCaseNoteMock as jest.Mock;

it('throws error if user is unauthorized', async () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => new User(mockUnauthorizedUser));
applicationContext
.getPersistenceGateway()
.getUserCaseNote.mockReturnValue({});
getUserCaseNote.mockReturnValue({});
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(null);
Expand All @@ -46,9 +47,7 @@ describe('Get case note', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => new User(mockJudgeUser));
applicationContext
.getPersistenceGateway()
.getUserCaseNote.mockResolvedValue(omit(MOCK_NOTE, 'userId'));
getUserCaseNote.mockResolvedValue(omit(MOCK_NOTE, 'userId'));
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(mockJudgeUser);
Expand All @@ -68,9 +67,7 @@ describe('Get case note', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => new User(mockJudgeUser));
applicationContext
.getPersistenceGateway()
.getUserCaseNote.mockResolvedValue(MOCK_NOTE);
getUserCaseNote.mockResolvedValue(MOCK_NOTE);
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(mockJudgeUser);
Expand All @@ -90,9 +87,7 @@ describe('Get case note', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => new User(mockJudgeUser));
applicationContext
.getPersistenceGateway()
.getUserCaseNote.mockResolvedValue(MOCK_NOTE);
getUserCaseNote.mockResolvedValue(MOCK_NOTE);
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(null);
Expand All @@ -115,9 +110,7 @@ describe('Get case note', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => new User(mockJudgeUser));
applicationContext
.getPersistenceGateway()
.getUserCaseNote.mockReturnValue(null);
getUserCaseNote.mockReturnValue(null);
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(mockJudgeUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { applicationContext } from '../../../../../shared/src/business/test/crea
import { mockJudgeUser } from '@shared/test/mockAuthUsers';
import { omit } from 'lodash';
import { updateUserCaseNoteInteractor } from './updateUserCaseNoteInteractor';
import { updateUserCaseNote as updateUserCaseNoteMock } from '@web-api/persistence/postgres/userCaseNotes/updateUserCaseNote';

describe('updateUserCaseNoteInteractor', () => {
const mockCaseNote = {
Expand All @@ -14,6 +15,8 @@ describe('updateUserCaseNoteInteractor', () => {
userId: '6805d1ab-18d0-43ec-bafb-654e83405416',
};

const updateUserCaseNote = updateUserCaseNoteMock as jest.Mock;

it('throws an error if the user is not valid or authorized', async () => {
await expect(
updateUserCaseNoteInteractor(
Expand All @@ -35,9 +38,7 @@ describe('updateUserCaseNoteInteractor', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => mockUser);
applicationContext
.getPersistenceGateway()
.updateUserCaseNote.mockImplementation(v => v.caseNoteToUpdate);
updateUserCaseNote.mockImplementation(v => v.caseNoteToUpdate);
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue({
Expand Down Expand Up @@ -68,7 +69,6 @@ describe('updateUserCaseNoteInteractor', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => mockUser);
applicationContext.getPersistenceGateway().updateUserCaseNote = jest.fn();
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(null);
Expand All @@ -82,9 +82,8 @@ describe('updateUserCaseNoteInteractor', () => {
omit(mockUser, 'section'),
);

expect(
applicationContext.getPersistenceGateway().updateUserCaseNote.mock
.calls[0][0].caseNoteToUpdate.userId,
).toEqual(userIdToExpect);
expect(updateUserCaseNote.mock.calls[0][0].caseNoteToUpdate.userId).toEqual(
userIdToExpect,
);
});
});

0 comments on commit 7b5cb98

Please sign in to comment.