diff --git a/packages/ringcentral-integration/integration-test/mock/data/messageFaxItem.json b/packages/ringcentral-integration/integration-test/mock/data/messageFaxItem.json new file mode 100644 index 0000000000..74b083f85e --- /dev/null +++ b/packages/ringcentral-integration/integration-test/mock/data/messageFaxItem.json @@ -0,0 +1,26 @@ +{ + "uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020", + "id" : 5475922005, + "from" : { + "phoneNumber" : "+1234567890", + "name" : "Something1 New1", + "location" : "Orange, CA" + }, + "type" : "Fax", + "creationTime" : "2018-02-12T05:20:02.000Z", + "readStatus" : "Read", + "priority" : "Normal", + "attachments" : [ { + "id" : 5475922005, + "uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020/content/937441587020", + "type" : "RenderedDocument", + "contentType" : "application/pdf" + } ], + "direction" : "Inbound", + "availability" : "Alive", + "subject" : "+1234567890", + "messageStatus" : "Received", + "faxResolution" : "High", + "faxPageCount" : 3, + "lastModifiedTime" : "2018-02-12T15:15:35.758Z" +} diff --git a/packages/ringcentral-integration/integration-test/mock/data/messageItem.json b/packages/ringcentral-integration/integration-test/mock/data/messageItem.json index 74b083f85e..ded57b44be 100644 --- a/packages/ringcentral-integration/integration-test/mock/data/messageItem.json +++ b/packages/ringcentral-integration/integration-test/mock/data/messageItem.json @@ -1,26 +1,37 @@ { - "uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020", - "id" : 5475922005, - "from" : { - "phoneNumber" : "+1234567890", - "name" : "Something1 New1", - "location" : "Orange, CA" + "uri": "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/5475922005", + "id": 5475922005, + "to": [ + { + "extensionNumber": "101", + "name": "Something1 New1" + } + ], + "from": { + "extensionNumber": "101", + "name": "Something1 New1" }, - "type" : "Fax", - "creationTime" : "2018-02-12T05:20:02.000Z", - "readStatus" : "Read", - "priority" : "Normal", - "attachments" : [ { - "id" : 5475922005, - "uri" : "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/937441587020/content/937441587020", - "type" : "RenderedDocument", - "contentType" : "application/pdf" - } ], - "direction" : "Inbound", - "availability" : "Alive", - "subject" : "+1234567890", - "messageStatus" : "Received", - "faxResolution" : "High", - "faxPageCount" : 3, - "lastModifiedTime" : "2018-02-12T15:15:35.758Z" + "type": "Pager", + "creationTime": "2017-06-01T02:24:02.000Z", + "readStatus": "Read", + "priority": "Normal", + "attachments": [ + { + "id": 5475922005, + "uri": "https://platform.ringcentral.com/restapi/v1.0/account/208594004/extension/208594004/message-store/5475922005/content/5475922005", + "type": "Text", + "contentType": "text/plain" + } + ], + "direction": "Inbound", + "availability": "Alive", + "subject": "test 2", + "messageStatus": "Sent", + "conversationId": 6015823250778200202, + "conversation": { + "id": "6015823250778200202", + "uri": "https://platform.ringcentral.com/restapi/v1.0/conversation/6015823250778200202" + }, + "lastModifiedTime": "2017-06-30T02:24:08.238Z", + "pgToDepartment": false } diff --git a/packages/ringcentral-integration/integration-test/mock/index.js b/packages/ringcentral-integration/integration-test/mock/index.js index fd9ac090da..8f361ddd85 100644 --- a/packages/ringcentral-integration/integration-test/mock/index.js +++ b/packages/ringcentral-integration/integration-test/mock/index.js @@ -254,7 +254,7 @@ export function messageSync(mockResponse = {}, isOnce = true) { export function messageList(mockResponse = {}) { mockApi({ - url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store`, + url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store?`, body: { ...messageListBody, ...mockResponse, @@ -263,14 +263,15 @@ export function messageList(mockResponse = {}) { }); } -export function updateMessageStatus(mockResponse = {}) { +export function updateMessageStatus(mockResponse = {}, isOnce = true) { mockApi({ - url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store`, + url: `begin:${mockServer}/restapi/v1.0/account/~/extension/~/message-store/`, method: 'PUT', body: { ...messageItemBody, ...mockResponse, - } + }, + isOnce }); } diff --git a/packages/ringcentral-widgets-test/test/integration-test/messages/FaxMessages.spec.js b/packages/ringcentral-widgets-test/test/integration-test/messages/FaxMessages.spec.js index da82437105..9a08b3c271 100644 --- a/packages/ringcentral-widgets-test/test/integration-test/messages/FaxMessages.spec.js +++ b/packages/ringcentral-widgets-test/test/integration-test/messages/FaxMessages.spec.js @@ -414,7 +414,7 @@ describe('fax messages', () => { await panel.find(NavigationBar).props().goTo('Fax'); wrapper.update(); mockUpdateMessageStatusApi({ - id: 0, + id: 1, readStatus: 'Read', messageType: 'Fax', }); @@ -458,7 +458,7 @@ describe('fax messages', () => { await panel.find(NavigationBar).props().goTo('Fax'); wrapper.update(); mockUpdateMessageStatusApi({ - id: 0, + id: 1, readStatus: 'Unread', messageType: 'Fax', }); @@ -482,7 +482,7 @@ describe('fax messages', () => { count: 100, messageType: 'Fax', readStatus: 'Unread', direction: 'Inbound' }); mockUpdateMessageStatusApi({ - id: 0, + id: 1, readStatus: 'Read', messageType: 'Fax', }); @@ -524,7 +524,7 @@ describe('fax messages', () => { count: 100, messageType: 'Fax', readStatus: 'Unread', direction: 'Inbound' }); mockUpdateMessageStatusApi({ - id: 0, + id: 1, readStatus: 'Read', messageType: 'Fax', }); @@ -553,7 +553,7 @@ describe('fax messages', () => { wrapper.update(); mockUpdateMessageStatusApi({ - id: 0, + id: 1, readStatus: 'Unread', messageType: 'Fax', }); diff --git a/packages/ringcentral-widgets-test/test/integration-test/messages/Messages.spec.js b/packages/ringcentral-widgets-test/test/integration-test/messages/Messages.spec.js index cb15e41844..03e9938f2d 100644 --- a/packages/ringcentral-widgets-test/test/integration-test/messages/Messages.spec.js +++ b/packages/ringcentral-widgets-test/test/integration-test/messages/Messages.spec.js @@ -8,6 +8,7 @@ import ConversationPanel from 'ringcentral-widgets/components/ConversationPanel' import LogButton from 'ringcentral-widgets/components/LogButton'; import Button from 'ringcentral-widgets/components/Button'; import Spinner from 'ringcentral-widgets/components/Spinner'; +import * as mock from 'ringcentral-integration/integration-test/mock'; import { getWrapper, timeout } from '../shared'; @@ -54,8 +55,15 @@ describe('messages', () => { }); test('click a message', async () => { + const message = wrapper.props().phone.messageStore.allConversations[0]; + mock.updateMessageStatus({ + ...message, + readStatus: 'Read', + lastModifiedTime: (new Date()).toISOString(), + }, false); const firstMessage = panel.find(MessageItem).first(); await firstMessage.find('.wrapper').first().simulate('click'); + await timeout(200); // wait conversation loaded const conversationPanel = wrapper.find(ConversationPanel); expect(conversationPanel.length > 0).toBe(true); }); @@ -89,16 +97,30 @@ describe('messages', () => { }); test('message log button', async () => { + const message = wrapper.props().phone.messageStore.allConversations[0]; + mock.updateMessageStatus({ + ...message, + readStatus: 'Read', + lastModifiedTime: (new Date()).toISOString(), + }, false); const firstMessage = panel.find(MessageItem).first(); await firstMessage.find('.wrapper').first().simulate('click'); + await timeout(200); // wait conversation loaded const conversationPanel = wrapper.find(ConversationPanel); const logButton = conversationPanel.find(LogButton).first().find(Button); expect(logButton.props().disabled).toBe(false); }); test('message click log button', async () => { + const message = wrapper.props().phone.messageStore.allConversations[0]; + mock.updateMessageStatus({ + ...message, + readStatus: 'Read', + lastModifiedTime: (new Date()).toISOString(), + }, false); const firstMessage = panel.find(MessageItem).first(); await firstMessage.find('.wrapper').first().simulate('click'); + await timeout(200); // wait conversation loaded let conversationPanel = wrapper.find(ConversationPanel); let logButton = conversationPanel.find(LogButton).find(Button); logButton.simulate('click'); diff --git a/packages/ringcentral-widgets-test/test/integration-test/messages/helper.js b/packages/ringcentral-widgets-test/test/integration-test/messages/helper.js index be78dbf089..2d2e4e8138 100644 --- a/packages/ringcentral-widgets-test/test/integration-test/messages/helper.js +++ b/packages/ringcentral-widgets-test/test/integration-test/messages/helper.js @@ -1,4 +1,5 @@ import messageSyncBody from 'ringcentral-integration/integration-test/mock/data/messageSync.json'; +import messageFaxItemBody from 'ringcentral-integration/integration-test/mock/data/messageFaxItem.json'; import subscriptionBody from 'ringcentral-integration/integration-test/mock/data/subscription.json'; import pubnubMsg from 'ringcentral-integration/integration-test/mock/data/pubnub.json'; import * as mock from 'ringcentral-integration/integration-test/mock'; @@ -26,8 +27,8 @@ export function mockGenerateMessageApi({ count = 1, messageType = 'Text', readStatus = 'Unread', direction = 'Inbound' }) { const records = []; - for (let i = 0; i < count; i += 1) { - records.push({ + for (let i = 1; i <= count; i += 1) { + const mockedMessage = { ...messageSyncBody.records[0], type: messageType, readStatus, @@ -44,14 +45,25 @@ export function mockGenerateMessageApi({ }, creationTime: (new Date()).toISOString(), lastModifiedTime: (new Date()).toISOString(), - }); + }; + if (messageType === 'Fax' || messageType === 'VoiceMail') { + // Fax and Voicemail doesn't have conversation + mockedMessage.conversation = undefined; + mockedMessage.conversationId = undefined; + } + records.push(mockedMessage); } mock.messageSync({ records }); } export function mockUpdateMessageStatusApi({ - id = 0, messageType = 'Text', readStatus = 'Unread', direction = 'Inbound' + id = 1, messageType = 'Text', readStatus = 'Unread', direction = 'Inbound' }) { - mock.updateMessageStatus({ + let preDefined = {}; + if (messageType === 'Fax') { + preDefined = messageFaxItemBody; + } + const mockedMessage = { + ...preDefined, type: messageType, id, readStatus, @@ -59,6 +71,12 @@ export function mockUpdateMessageStatusApi({ messageStatus: direction === 'Inbound' ? 'Received' : 'Sent', creationTime: (new Date()).toISOString(), lastModifiedTime: (new Date()).toISOString(), - }); + }; + if (messageType === 'Fax' || messageType === 'VoiceMail') { + // Fax and Voicemail doesn't have conversation + mockedMessage.conversation = undefined; + mockedMessage.conversationId = undefined; + } + mock.updateMessageStatus(mockedMessage); }