diff --git a/src/__tests__/widgetQueries.test.ts b/src/__tests__/widgetQueries.test.ts index 3b159c1e3..4ec69ade0 100644 --- a/src/__tests__/widgetQueries.test.ts +++ b/src/__tests__/widgetQueries.test.ts @@ -119,7 +119,11 @@ describe('widgetQueries', () => { const qry = ` query widgetsMessengerSupporters($integrationId: String!) { widgetsMessengerSupporters(integrationId: $integrationId) { - _id + supporters { + _id + } + isOnline + serverTime } } `; @@ -127,12 +131,12 @@ describe('widgetQueries', () => { try { await graphqlRequest(qry, 'widgetsMessengerSupporters', { integrationId: '_id' }); } catch (e) { - expect(e.message).toBe('Integration not found'); + expect(e[0].message).toBe('Integration not found'); } const response = await graphqlRequest(qry, 'widgetsMessengerSupporters', { integrationId: integration._id }); - expect(response.length).toBe(1); + expect(response.supporters.length).toBe(1); }); test('widgetsTotalUnreadCount', async () => { diff --git a/src/data/resolvers/queries/widgets.ts b/src/data/resolvers/queries/widgets.ts index 2fad34d81..29192f1c1 100644 --- a/src/data/resolvers/queries/widgets.ts +++ b/src/data/resolvers/queries/widgets.ts @@ -147,12 +147,20 @@ export default { const integration = await Integrations.findOne({ _id: integrationId }); if (!integration) { - return []; + return { + supporters: [], + isOnline: false, + serverTime: new Date(), + }; } const messengerData = integration.messengerData || { supporterIds: [] }; - return Users.find({ _id: { $in: messengerData.supporterIds || [] } }); + return { + supporters: await Users.find({ _id: { $in: messengerData.supporterIds || [] } }), + isOnline: await isMessengerOnline(integration), + serverTime: new Date(), + }; }, /** diff --git a/src/data/schema/widget.ts b/src/data/schema/widget.ts index dd89412f8..200e9164f 100644 --- a/src/data/schema/widget.ts +++ b/src/data/schema/widget.ts @@ -33,6 +33,12 @@ export const types = ` text: String } + type MessengerSupportersResponse { + supporters: [User] + isOnline: Boolean + serverTime: String + } + input FieldValueInput { _id: String! type: String @@ -49,7 +55,7 @@ export const queries = ` widgetsMessages(conversationId: String): [ConversationMessage] widgetsUnreadCount(conversationId: String): Int widgetsTotalUnreadCount(integrationId: String!, customerId: String!): Int - widgetsMessengerSupporters(integrationId: String!): [User] + widgetsMessengerSupporters(integrationId: String!): MessengerSupportersResponse widgetsKnowledgeBaseArticles(topicId: String!, searchString: String) : [KnowledgeBaseArticle] widgetsKnowledgeBaseTopicDetail(_id: String!): KnowledgeBaseTopic `;