diff --git a/web-api/src/business/useCases/caseNote/deleteUserCaseNoteInteractor.test.ts b/web-api/src/business/useCases/caseNote/deleteUserCaseNoteInteractor.test.ts index a54b34e0d96..38d94ce23f8 100644 --- a/web-api/src/business/useCases/caseNote/deleteUserCaseNoteInteractor.test.ts +++ b/web-api/src/business/useCases/caseNote/deleteUserCaseNoteInteractor.test.ts @@ -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; @@ -34,7 +37,7 @@ describe('deleteUserCaseNoteInteractor', () => { applicationContext .getPersistenceGateway() .getUserById.mockReturnValue(mockUser); - applicationContext.getPersistenceGateway().deleteUserCaseNote = v => v; + deleteUserCaseNote.mockImplementation(v => v); applicationContext .getUseCaseHelpers() .getJudgeInSectionHelper.mockReturnValue({ @@ -61,7 +64,6 @@ describe('deleteUserCaseNoteInteractor', () => { applicationContext .getPersistenceGateway() .getUserById.mockReturnValue(mockUser); - applicationContext.getPersistenceGateway().deleteUserCaseNote = jest.fn(); applicationContext .getUseCaseHelpers() .getJudgeInSectionHelper.mockReturnValue(null); @@ -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, + ); }); }); diff --git a/web-api/src/business/useCases/caseNote/getUserCaseNoteInteractor.test.ts b/web-api/src/business/useCases/caseNote/getUserCaseNoteInteractor.test.ts index a5845bcb286..4d441df7265 100644 --- a/web-api/src/business/useCases/caseNote/getUserCaseNoteInteractor.test.ts +++ b/web-api/src/business/useCases/caseNote/getUserCaseNoteInteractor.test.ts @@ -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'; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); diff --git a/web-api/src/business/useCases/caseNote/updateUserCaseNoteInteractor.test.ts b/web-api/src/business/useCases/caseNote/updateUserCaseNoteInteractor.test.ts index 47d86525197..a4db9894ba0 100644 --- a/web-api/src/business/useCases/caseNote/updateUserCaseNoteInteractor.test.ts +++ b/web-api/src/business/useCases/caseNote/updateUserCaseNoteInteractor.test.ts @@ -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 = { @@ -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( @@ -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({ @@ -68,7 +69,6 @@ describe('updateUserCaseNoteInteractor', () => { applicationContext .getPersistenceGateway() .getUserById.mockImplementation(() => mockUser); - applicationContext.getPersistenceGateway().updateUserCaseNote = jest.fn(); applicationContext .getUseCaseHelpers() .getJudgeInSectionHelper.mockReturnValue(null); @@ -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, + ); }); });