forked from ustaxcourt/ef-cms
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgetInboxMessagesForUserInteractor.test.ts
70 lines (65 loc) · 2.4 KB
/
getInboxMessagesForUserInteractor.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
CASE_STATUS_TYPES,
PETITIONS_SECTION,
ROLES,
} from '../../entities/EntityConstants';
import { UnauthorizedError } from '../../../../../shared/src/errors/errors';
import { applicationContext } from '../../test/createTestApplicationContext';
import { getInboxMessagesForUserInteractor } from './getInboxMessagesForUserInteractor';
import { omit } from 'lodash';
describe('getInboxMessagesForUserInteractor', () => {
it('throws unauthorized for a user without MESSAGES permission', async () => {
applicationContext.getCurrentUser.mockReturnValue({
role: ROLES.petitioner,
userId: '9bd0308c-2b06-4589-b36e-242398bea31b',
});
await expect(
getInboxMessagesForUserInteractor(applicationContext, {
userId: 'bob',
}),
).rejects.toThrow(UnauthorizedError);
});
it('retrieves the messages from persistence and returns them', async () => {
const messageData = {
attachments: [],
caseStatus: CASE_STATUS_TYPES.generalDocket,
caseTitle: 'Bill Burr',
createdAt: '2019-03-01T21:40:46.415Z',
docketNumber: '123-45',
docketNumberWithSuffix: '123-45S',
entityName: 'MessageResult',
from: 'Test Petitionsclerk2',
fromSection: PETITIONS_SECTION,
fromUserId: 'fe6eeadd-e4e8-4e56-9ddf-0ebe9516df6b',
isRepliedTo: false,
message: "How's it going?",
messageId: '9ca37b65-9aac-4621-b5d7-e4a7c8a26a21',
parentMessageId: '9ca37b65-9aac-4621-b5d7-e4a7c8a26a21',
pk: 'case|9ca37b65-9aac-4621-b5d7-e4a7c8a26a21',
sk: 'message|9ca37b65-9aac-4621-b5d7-e4a7c8a26a21',
subject: 'Hey!',
to: 'Test Petitionsclerk',
toSection: PETITIONS_SECTION,
toUserId: 'b427ca37-0df1-48ac-94bb-47aed073d6f7',
trialDate: '2028-03-01T21:40:46.415Z',
trialLocation: 'El Paso, Texas',
};
applicationContext.getCurrentUser.mockReturnValue({
role: ROLES.petitionsClerk,
userId: 'b9fcabc8-3c83-4cbf-9f4a-d2ecbdc591e1',
});
applicationContext
.getPersistenceGateway()
.getUserInboxMessages.mockReturnValue([messageData]);
const returnedMessages = await getInboxMessagesForUserInteractor(
applicationContext,
{
userId: 'bob',
},
);
expect(
applicationContext.getPersistenceGateway().getUserInboxMessages,
).toHaveBeenCalled();
expect(returnedMessages).toMatchObject([omit(messageData, 'pk', 'sk')]);
});
});