Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10492 dxox #5518

Draft
wants to merge 16 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions types/TEntity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ type TPetitioner = {
hasConsentedToEService?: boolean;
};

type TCaseNote = {
userId: string;
docketNumber: string;
notes: string;
};

interface IValidateRawCollection<I> {
(collection: I[], options: { applicationContext: IApplicationContext }): I[];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import '@web-api/persistence/postgres/userCaseNotes/mocks.jest';
import { ROLES } from '../../../../../shared/src/business/entities/EntityConstants';
import { UnauthorizedError } from '@web-api/errors/errors';
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 @@ -33,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 @@ -60,7 +64,6 @@ describe('deleteUserCaseNoteInteractor', () => {
applicationContext
.getPersistenceGateway()
.getUserById.mockReturnValue(mockUser);
applicationContext.getPersistenceGateway().deleteUserCaseNote = jest.fn();
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(null);
Expand All @@ -72,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 {
import { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { deleteUserCaseNote } from '@web-api/persistence/postgres/userCaseNotes/deleteUserCaseNote';

/**
* deleteUserCaseNoteInteractor
Expand All @@ -31,8 +32,7 @@ export const deleteUserCaseNoteInteractor = async (
userIdMakingRequest: authorizedUser.userId,
});

return await applicationContext.getPersistenceGateway().deleteUserCaseNote({
applicationContext,
return await deleteUserCaseNote({
docketNumber,
userId,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import '@web-api/persistence/postgres/userCaseNotes/mocks.jest';
import { MOCK_CASE } from '../../../../../shared/src/test/mockCase';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { UserCaseNote } from '@shared/business/entities/notes/UserCaseNote';
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext';
import { getUserCaseNoteForCasesInteractor } from './getUserCaseNoteForCasesInteractor';
import { getUserCaseNoteForCases as getUserCaseNoteForCasesMock } from '@web-api/persistence/postgres/userCaseNotes/getUserCaseNoteForCases';
import { mockJudgeUser } from '@shared/test/mockAuthUsers';
import { omit } from 'lodash';

Expand All @@ -21,15 +24,15 @@ describe('getUserCaseNoteForCasesInteractor', () => {
section: 'colvinChambers',
} as UnknownAuthUser;

const getUserCaseNoteForCases = getUserCaseNoteForCasesMock as jest.Mock;

beforeEach(() => {
mockCurrentUser = mockJudge;
mockNote = MOCK_NOTE;
applicationContext
.getPersistenceGateway()
.getUserById.mockImplementation(() => mockCurrentUser);
applicationContext
.getPersistenceGateway()
.getUserCaseNoteForCases.mockResolvedValue([mockNote]);
getUserCaseNoteForCases.mockResolvedValue([new UserCaseNote(mockNote)]);
applicationContext
.getUseCaseHelpers()
.getJudgeInSectionHelper.mockReturnValue(mockJudge);
Expand All @@ -52,9 +55,9 @@ describe('getUserCaseNoteForCasesInteractor', () => {
});

it('throws an error if the entity returned from persistence is invalid', async () => {
applicationContext
.getPersistenceGateway()
.getUserCaseNoteForCases.mockResolvedValue([omit(MOCK_NOTE, 'userId')]);
getUserCaseNoteForCases.mockResolvedValue([
new UserCaseNote([omit(MOCK_NOTE, 'userId')]),
]);

await expect(
getUserCaseNoteForCasesInteractor(
Expand Down Expand Up @@ -100,9 +103,8 @@ describe('getUserCaseNoteForCasesInteractor', () => {
omit(mockUser, 'section'),
);

expect(
applicationContext.getPersistenceGateway().getUserCaseNoteForCases.mock
.calls[0][0].userId,
).toEqual(userIdToExpect);
expect(getUserCaseNoteForCases.mock.calls[0][0].userId).toEqual(
userIdToExpect,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from '../../../../../shared/src/authorization/authorizationClientService';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { UserCaseNote } from '../../../../../shared/src/business/entities/notes/UserCaseNote';
import { getUserCaseNoteForCases } from '@web-api/persistence/postgres/userCaseNotes/getUserCaseNoteForCases';

export const getUserCaseNoteForCasesInteractor = async (
applicationContext,
Expand All @@ -21,13 +21,10 @@ export const getUserCaseNoteForCasesInteractor = async (
userIdMakingRequest: authorizedUser.userId,
});

const caseNotes = await applicationContext
.getPersistenceGateway()
.getUserCaseNoteForCases({
applicationContext,
docketNumbers,
userId,
});
const caseNotes = await getUserCaseNoteForCases({
docketNumbers,
userId,
});

return caseNotes.map(note => new UserCaseNote(note).validate().toRawObject());
return caseNotes.map(note => note.validate().toRawObject());
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import '@web-api/persistence/postgres/userCaseNotes/mocks.jest';
import { MOCK_CASE } from '../../../../../shared/src/test/mockCase';
import { UnauthorizedError } from '@web-api/errors/errors';
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 @@ -19,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 @@ -45,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 @@ -67,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 @@ -89,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 @@ -114,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 { ServerApplicationContext } from '@web-api/applicationContext';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { UserCaseNote } from '../../../../../shared/src/business/entities/notes/UserCaseNote';
import { getUserCaseNote } from '@web-api/persistence/postgres/userCaseNotes/getUserCaseNote';

/**
* getUserCaseNoteInteractor
Expand All @@ -32,13 +33,10 @@ export const getUserCaseNoteInteractor = async (
userIdMakingRequest: authorizedUser.userId,
});

const caseNote = await applicationContext
.getPersistenceGateway()
.getUserCaseNote({
applicationContext,
docketNumber,
userId,
});
const caseNote = await getUserCaseNote({
docketNumber,
userId,
});

if (caseNote) {
return new UserCaseNote(caseNote).validate().toRawObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import '@web-api/persistence/postgres/userCaseNotes/mocks.jest';
import { ROLES } from '../../../../../shared/src/business/entities/EntityConstants';
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext';
import { mockJudgeUser } from '@shared/test/mockAuthUsers';
import { omit } from 'lodash';
import { updateUserCaseNoteInteractor } from './updateUserCaseNoteInteractor';
import { upsertUserCaseNote as upsertUserCaseNoteMock } from '@web-api/persistence/postgres/userCaseNotes/upsertUserCaseNote';

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

const upsertUserCaseNote = upsertUserCaseNoteMock as jest.Mock;

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

expect(
applicationContext.getPersistenceGateway().updateUserCaseNote.mock
.calls[0][0].caseNoteToUpdate.userId,
).toEqual(userIdToExpect);
expect(upsertUserCaseNote.mock.calls[0][0].caseNoteToUpsert.userId).toEqual(
userIdToExpect,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
import { UnauthorizedError } from '@web-api/errors/errors';
import { UnknownAuthUser } from '@shared/business/entities/authUser/AuthUser';
import { UserCaseNote } from '../../../../../shared/src/business/entities/notes/UserCaseNote';
import { upsertUserCaseNote } from '@web-api/persistence/postgres/userCaseNotes/upsertUserCaseNote';

export const updateUserCaseNoteInteractor = async (
applicationContext,
Expand All @@ -27,14 +28,11 @@ export const updateUserCaseNoteInteractor = async (
docketNumber,
notes,
userId,
});

const caseNoteToUpdate = caseNoteEntity.validate().toRawObject();
}).validate();

await applicationContext.getPersistenceGateway().updateUserCaseNote({
applicationContext,
caseNoteToUpdate,
await upsertUserCaseNote({
caseNoteToUpsert: caseNoteEntity,
});

return caseNoteToUpdate;
return caseNoteEntity;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ jest.mock('./processPractitionerMappingEntries');
jest.mock('./processRemoveEntries');
jest.mock('./processWorkItemEntries');
jest.mock('./processCaseEntries');
jest.mock('./processUserCaseNoteEntries');
jest.mock('./processOtherEntries');
import { applicationContext } from '../../../../../shared/src/business/test/createTestApplicationContext';
import { partitionRecords } from './processStreamUtilities';
Expand All @@ -15,6 +16,7 @@ import { processOtherEntries } from './processOtherEntries';
import { processPractitionerMappingEntries } from './processPractitionerMappingEntries';
import { processRemoveEntries } from './processRemoveEntries';
import { processStreamRecordsInteractor } from './processStreamRecordsInteractor';
import { processUserCaseNoteEntries } from './processUserCaseNoteEntries';
import { processWorkItemEntries } from './processWorkItemEntries';

describe('processStreamRecordsInteractor', () => {
Expand All @@ -25,6 +27,7 @@ describe('processStreamRecordsInteractor', () => {
(processWorkItemEntries as jest.Mock).mockResolvedValue([]);
(processMessageEntries as jest.Mock).mockResolvedValue([]);
(processPractitionerMappingEntries as jest.Mock).mockResolvedValue([]);
(processUserCaseNoteEntries as jest.Mock).mockResolvedValue([]);
(processOtherEntries as jest.Mock).mockResolvedValue([]);

(partitionRecords as jest.Mock).mockReturnValue({
Expand All @@ -34,6 +37,7 @@ describe('processStreamRecordsInteractor', () => {
otherRecords: [],
privatePractitionerMappingRecords: [],
removeRecords: [],
userCaseNoteRecords: [],
workItemRecords: [],
});
});
Expand All @@ -60,6 +64,7 @@ describe('processStreamRecordsInteractor', () => {
expect(processDocketEntries).not.toHaveBeenCalled();
expect(processWorkItemEntries).not.toHaveBeenCalled();
expect(processMessageEntries).not.toHaveBeenCalled();
expect(processUserCaseNoteEntries).not.toHaveBeenCalled();
expect(processPractitionerMappingEntries).not.toHaveBeenCalled();
expect(processOtherEntries).not.toHaveBeenCalled();
expect(applicationContext.logger.error).toHaveBeenCalledTimes(2);
Expand Down
Loading
Loading