Skip to content

Commit 0ec8b58

Browse files
authored
update message update api mock data (#1103)
1 parent 955da81 commit 0ec8b58

File tree

6 files changed

+116
-38
lines changed

6 files changed

+116
-38
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020",
3+
"id" : 5475922005,
4+
"from" : {
5+
"phoneNumber" : "+1234567890",
6+
"name" : "Something1 New1",
7+
"location" : "Orange, CA"
8+
},
9+
"type" : "Fax",
10+
"creationTime" : "2018-02-12T05:20:02.000Z",
11+
"readStatus" : "Read",
12+
"priority" : "Normal",
13+
"attachments" : [ {
14+
"id" : 5475922005,
15+
"uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020/content/937441587020",
16+
"type" : "RenderedDocument",
17+
"contentType" : "application/pdf"
18+
} ],
19+
"direction" : "Inbound",
20+
"availability" : "Alive",
21+
"subject" : "+1234567890",
22+
"messageStatus" : "Received",
23+
"faxResolution" : "High",
24+
"faxPageCount" : 3,
25+
"lastModifiedTime" : "2018-02-12T15:15:35.758Z"
26+
}
Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
{
2-
"uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020",
3-
"id" : 5475922005,
4-
"from" : {
5-
"phoneNumber" : "+1234567890",
6-
"name" : "Something1 New1",
7-
"location" : "Orange, CA"
2+
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/5475922005",
3+
"id": 5475922005,
4+
"to": [
5+
{
6+
"extensionNumber": "101",
7+
"name": "Something1 New1"
8+
}
9+
],
10+
"from": {
11+
"extensionNumber": "101",
12+
"name": "Something1 New1"
813
},
9-
"type" : "Fax",
10-
"creationTime" : "2018-02-12T05:20:02.000Z",
11-
"readStatus" : "Read",
12-
"priority" : "Normal",
13-
"attachments" : [ {
14-
"id" : 5475922005,
15-
"uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020/content/937441587020",
16-
"type" : "RenderedDocument",
17-
"contentType" : "application/pdf"
18-
} ],
19-
"direction" : "Inbound",
20-
"availability" : "Alive",
21-
"subject" : "+1234567890",
22-
"messageStatus" : "Received",
23-
"faxResolution" : "High",
24-
"faxPageCount" : 3,
25-
"lastModifiedTime" : "2018-02-12T15:15:35.758Z"
14+
"type": "Pager",
15+
"creationTime": "2017-06-01T02:24:02.000Z",
16+
"readStatus": "Read",
17+
"priority": "Normal",
18+
"attachments": [
19+
{
20+
"id": 5475922005,
21+
"uri": "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/5475922005/content/5475922005",
22+
"type": "Text",
23+
"contentType": "text/plain"
24+
}
25+
],
26+
"direction": "Inbound",
27+
"availability": "Alive",
28+
"subject": "test 2",
29+
"messageStatus": "Sent",
30+
"conversationId": 6015823250778200202,
31+
"conversation": {
32+
"id": "6015823250778200202",
33+
"uri": "https://platform.ringcentral.com/restapi/v1.0/conversation/6015823250778200202"
34+
},
35+
"lastModifiedTime": "2017-06-30T02:24:08.238Z",
36+
"pgToDepartment": false
2637
}

packages/ringcentral-integration/integration-test/mock/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export function messageSync(mockResponse = {}, isOnce = true) {
254254

255255
export function messageList(mockResponse = {}) {
256256
mockApi({
257-
url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store`,
257+
url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store?`,
258258
body: {
259259
...messageListBody,
260260
...mockResponse,
@@ -263,14 +263,15 @@ export function messageList(mockResponse = {}) {
263263
});
264264
}
265265

266-
export function updateMessageStatus(mockResponse = {}) {
266+
export function updateMessageStatus(mockResponse = {}, isOnce = true) {
267267
mockApi({
268-
url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store`,
268+
url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store/`,
269269
method: 'PUT',
270270
body: {
271271
...messageItemBody,
272272
...mockResponse,
273-
}
273+
},
274+
isOnce
274275
});
275276
}
276277

packages/ringcentral-widgets-test/test/integration-test/messages/FaxMessages.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ describe('fax messages', () => {
414414
await panel.find(NavigationBar).props().goTo('Fax');
415415
wrapper.update();
416416
mockUpdateMessageStatusApi({
417-
id: 0,
417+
id: 1,
418418
readStatus: 'Read',
419419
messageType: 'Fax',
420420
});
@@ -458,7 +458,7 @@ describe('fax messages', () => {
458458
await panel.find(NavigationBar).props().goTo('Fax');
459459
wrapper.update();
460460
mockUpdateMessageStatusApi({
461-
id: 0,
461+
id: 1,
462462
readStatus: 'Unread',
463463
messageType: 'Fax',
464464
});
@@ -482,7 +482,7 @@ describe('fax messages', () => {
482482
count: 100, messageType: 'Fax', readStatus: 'Unread', direction: 'Inbound'
483483
});
484484
mockUpdateMessageStatusApi({
485-
id: 0,
485+
id: 1,
486486
readStatus: 'Read',
487487
messageType: 'Fax',
488488
});
@@ -524,7 +524,7 @@ describe('fax messages', () => {
524524
count: 100, messageType: 'Fax', readStatus: 'Unread', direction: 'Inbound'
525525
});
526526
mockUpdateMessageStatusApi({
527-
id: 0,
527+
id: 1,
528528
readStatus: 'Read',
529529
messageType: 'Fax',
530530
});
@@ -553,7 +553,7 @@ describe('fax messages', () => {
553553

554554
wrapper.update();
555555
mockUpdateMessageStatusApi({
556-
id: 0,
556+
id: 1,
557557
readStatus: 'Unread',
558558
messageType: 'Fax',
559559
});

packages/ringcentral-widgets-test/test/integration-test/messages/Messages.spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ConversationPanel from 'ringcentral-widgets/components/ConversationPanel'
88
import LogButton from 'ringcentral-widgets/components/LogButton';
99
import Button from 'ringcentral-widgets/components/Button';
1010
import Spinner from 'ringcentral-widgets/components/Spinner';
11+
import * as mock from 'ringcentral-integration/integration-test/mock';
1112

1213
import { getWrapper, timeout } from '../shared';
1314

@@ -54,8 +55,15 @@ describe('messages', () => {
5455
});
5556

5657
test('click a message', async () => {
58+
const message = wrapper.props().phone.messageStore.allConversations[0];
59+
mock.updateMessageStatus({
60+
...message,
61+
readStatus: 'Read',
62+
lastModifiedTime: (new Date()).toISOString(),
63+
}, false);
5764
const firstMessage = panel.find(MessageItem).first();
5865
await firstMessage.find('.wrapper').first().simulate('click');
66+
await timeout(200); // wait conversation loaded
5967
const conversationPanel = wrapper.find(ConversationPanel);
6068
expect(conversationPanel.length > 0).toBe(true);
6169
});
@@ -89,16 +97,30 @@ describe('messages', () => {
8997
});
9098

9199
test('message log button', async () => {
100+
const message = wrapper.props().phone.messageStore.allConversations[0];
101+
mock.updateMessageStatus({
102+
...message,
103+
readStatus: 'Read',
104+
lastModifiedTime: (new Date()).toISOString(),
105+
}, false);
92106
const firstMessage = panel.find(MessageItem).first();
93107
await firstMessage.find('.wrapper').first().simulate('click');
108+
await timeout(200); // wait conversation loaded
94109
const conversationPanel = wrapper.find(ConversationPanel);
95110
const logButton = conversationPanel.find(LogButton).first().find(Button);
96111
expect(logButton.props().disabled).toBe(false);
97112
});
98113

99114
test('message click log button', async () => {
115+
const message = wrapper.props().phone.messageStore.allConversations[0];
116+
mock.updateMessageStatus({
117+
...message,
118+
readStatus: 'Read',
119+
lastModifiedTime: (new Date()).toISOString(),
120+
}, false);
100121
const firstMessage = panel.find(MessageItem).first();
101122
await firstMessage.find('.wrapper').first().simulate('click');
123+
await timeout(200); // wait conversation loaded
102124
let conversationPanel = wrapper.find(ConversationPanel);
103125
let logButton = conversationPanel.find(LogButton).find(Button);
104126
logButton.simulate('click');

packages/ringcentral-widgets-test/test/integration-test/messages/helper.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import messageSyncBody from 'ringcentral-integration/integration-test/mock/data/messageSync.json';
2+
import messageFaxItemBody from 'ringcentral-integration/integration-test/mock/data/messageFaxItem.json';
23
import subscriptionBody from 'ringcentral-integration/integration-test/mock/data/subscription.json';
34
import pubnubMsg from 'ringcentral-integration/integration-test/mock/data/pubnub.json';
45
import * as mock from 'ringcentral-integration/integration-test/mock';
@@ -26,8 +27,8 @@ export function mockGenerateMessageApi({
2627
count = 1, messageType = 'Text', readStatus = 'Unread', direction = 'Inbound'
2728
}) {
2829
const records = [];
29-
for (let i = 0; i < count; i += 1) {
30-
records.push({
30+
for (let i = 1; i <= count; i += 1) {
31+
const mockedMessage = {
3132
...messageSyncBody.records[0],
3233
type: messageType,
3334
readStatus,
@@ -44,21 +45,38 @@ export function mockGenerateMessageApi({
4445
},
4546
creationTime: (new Date()).toISOString(),
4647
lastModifiedTime: (new Date()).toISOString(),
47-
});
48+
};
49+
if (messageType === 'Fax' || messageType === 'VoiceMail') {
50+
// Fax and Voicemail doesn't have conversation
51+
mockedMessage.conversation = undefined;
52+
mockedMessage.conversationId = undefined;
53+
}
54+
records.push(mockedMessage);
4855
}
4956
mock.messageSync({ records });
5057
}
5158
export function mockUpdateMessageStatusApi({
52-
id = 0, messageType = 'Text', readStatus = 'Unread', direction = 'Inbound'
59+
id = 1, messageType = 'Text', readStatus = 'Unread', direction = 'Inbound'
5360
}) {
54-
mock.updateMessageStatus({
61+
let preDefined = {};
62+
if (messageType === 'Fax') {
63+
preDefined = messageFaxItemBody;
64+
}
65+
const mockedMessage = {
66+
...preDefined,
5567
type: messageType,
5668
id,
5769
readStatus,
5870
direction,
5971
messageStatus: direction === 'Inbound' ? 'Received' : 'Sent',
6072
creationTime: (new Date()).toISOString(),
6173
lastModifiedTime: (new Date()).toISOString(),
62-
});
74+
};
75+
if (messageType === 'Fax' || messageType === 'VoiceMail') {
76+
// Fax and Voicemail doesn't have conversation
77+
mockedMessage.conversation = undefined;
78+
mockedMessage.conversationId = undefined;
79+
}
80+
mock.updateMessageStatus(mockedMessage);
6381
}
6482

0 commit comments

Comments
 (0)