Repository navigation
Develop #295
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
Merged
Develop #295
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { type GetTerminologyResult } from '@/models/v4/configs/getTerminologyResult'; | ||
|
|
||
| import { createApiEndpoint } from '../common/client'; | ||
|
|
||
| const getTerminologyApi = createApiEndpoint('/Config/GetTerminology'); | ||
|
|
||
| /** The department's own names for modules and built-in record types (setting 118). */ | ||
| export const getTerminology = async () => { | ||
| const response = await getTerminologyApi.get<GetTerminologyResult>(); | ||
| return response.data; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { deleteMessage, getUnitSubscriberHash } from '../inbox'; | ||
|
|
||
| jest.mock('../../common/client', () => { | ||
| const del = jest.fn(); | ||
| const get = jest.fn(); | ||
| return { | ||
| createApiEndpoint: jest.fn(() => ({ get, post: jest.fn(), put: jest.fn(), delete: del })), | ||
| __mockDelete: del, | ||
| __mockGet: get, | ||
| }; | ||
| }); | ||
|
|
||
| const { __mockDelete: mockDelete, __mockGet: mockGet } = jest.requireMock('../../common/client') as { __mockDelete: jest.Mock; __mockGet: jest.Mock }; | ||
|
|
||
| describe('inbox deleteMessage api', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockDelete.mockResolvedValue({ data: undefined }); | ||
| }); | ||
|
|
||
| // The server only deletes from an inbox the caller owns; the Unit app's inbox is the active unit's, so | ||
| // without the unit it looks in the user's own inbox and answers 404. | ||
| it('sends the active unit so the server deletes from the unit inbox', async () => { | ||
| await deleteMessage('66f1c2a9e4b0a1b2c3d4e5f6', '15298'); | ||
|
|
||
| expect(mockDelete).toHaveBeenCalledWith({ messageId: '66f1c2a9e4b0a1b2c3d4e5f6', unitId: '15298' }); | ||
| }); | ||
|
|
||
| it('leaves unitId out when there is no active unit', async () => { | ||
| await deleteMessage('66f1c2a9e4b0a1b2c3d4e5f6', null); | ||
|
|
||
| expect(mockDelete).toHaveBeenCalledWith({ messageId: '66f1c2a9e4b0a1b2c3d4e5f6' }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('inbox getUnitSubscriberHash api', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('asks for the unit inbox hash and returns the response body', async () => { | ||
| mockGet.mockResolvedValue({ data: { Data: { UnitId: '15298', SubscriberHash: 'abc123' } } }); | ||
|
|
||
| const result = await getUnitSubscriberHash('15298'); | ||
|
|
||
| expect(mockGet).toHaveBeenCalledWith({ unitId: '15298' }); | ||
| expect(result.Data.SubscriberHash).toBe('abc123'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,30 @@ | ||
| import { createApiEndpoint } from '../common/client'; | ||
|
|
||
| const getGroupsApi = createApiEndpoint('/Inbox/DeleteMessage'); | ||
| const getUnitSubscriberHashApi = createApiEndpoint('/Inbox/GetUnitSubscriberHash'); | ||
|
|
||
| export const deleteMessage = async (messageId: string) => { | ||
| export interface UnitSubscriberHashResult { | ||
| Data: { | ||
| UnitId: string; | ||
| SubscriberHash?: string | null; | ||
| }; | ||
| } | ||
|
|
||
| // The inbox belongs to the active unit's Novu subscriber, so the server needs the unit to find the message. | ||
| // Without one it only looks in the signed-in user's own inbox and answers 404. | ||
| export const deleteMessage = async (messageId: string, unitId?: string | null) => { | ||
| const response = await getGroupsApi.delete({ | ||
| messageId: encodeURIComponent(messageId), | ||
| ...(unitId ? { unitId } : {}), | ||
| }); | ||
| return response.data; | ||
| }; | ||
|
|
||
| // The Novu subscriberHash for the unit's inbox ({DepartmentCode}_Unit_{unitId}). Novu refuses an inbox session | ||
| // without it once HMAC is enforced on the environment. | ||
| export const getUnitSubscriberHash = async (unitId: string) => { | ||
| const response = await getUnitSubscriberHashApi.get<UnitSubscriberHashResult>({ | ||
| unitId, | ||
| }); | ||
| return response.data; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.