Skip to content

Commit

Permalink
Merge pull request #5522 from flexion/10492-dxox-intermediate-branch-…
Browse files Browse the repository at this point in the history
…to-test-1730910644

10492 dxox updates to test
  • Loading branch information
Mwindo authored Nov 8, 2024
2 parents 7b6bee4 + cecd10c commit 8bfbf92
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 42 deletions.
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
Expand Up @@ -6,7 +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';
import { upsertUserCaseNote as upsertUserCaseNoteMock } from '@web-api/persistence/postgres/userCaseNotes/upsertUserCaseNote';

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

const updateUserCaseNote = updateUserCaseNoteMock as jest.Mock;
const upsertUserCaseNote = upsertUserCaseNoteMock as jest.Mock;

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

expect(updateUserCaseNote.mock.calls[0][0].caseNoteToUpdate.userId).toEqual(
expect(upsertUserCaseNote.mock.calls[0][0].caseNoteToUpsert.userId).toEqual(
userIdToExpect,
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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 { updateUserCaseNote } from '@web-api/persistence/postgres/userCaseNotes/updateUserCaseNote';
import { upsertUserCaseNote } from '@web-api/persistence/postgres/userCaseNotes/upsertUserCaseNote';

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

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

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

return caseNoteToUpdate;
return caseNoteEntity;
};
4 changes: 2 additions & 2 deletions web-api/src/persistence/postgres/userCaseNotes/mocks.jest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jest.mock(
);

jest.mock(
'@web-api/persistence/postgres/userCaseNotes/updateUserCaseNote.ts',
() => mockFactory('updateUserCaseNote'),
'@web-api/persistence/postgres/userCaseNotes/upsertUserCaseNote.ts',
() => mockFactory('upsertUserCaseNote'),
);

jest.mock(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { UserCaseNote } from '@shared/business/entities/notes/UserCaseNote';
import { getDbWriter } from '@web-api/database';

export const upsertUserCaseNote = async ({
caseNoteToUpsert,
}: {
caseNoteToUpsert: UserCaseNote;
}) => {
await getDbWriter(writer =>
writer
.insertInto('dwUserCaseNote')
.values({
docketNumber: caseNoteToUpsert.docketNumber,
notes: caseNoteToUpsert.notes,
userId: caseNoteToUpsert.userId,
})
.onConflict(oc =>
oc.columns(['docketNumber', 'userId']).doUpdateSet({
notes: caseNoteToUpsert.notes,
}),
)
.execute(),
);
};

0 comments on commit 8bfbf92

Please sign in to comment.