From 71aafb060b1864ac63797ec1d127b851070384f2 Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Mon, 8 Sep 2025 15:02:22 -0300 Subject: [PATCH 1/4] chore!: Remove deprecated `hideRoomsWithNoActivity` param from `admin/engagement-dashboard/channels/list` --- .../channels/useChannelsList.ts | 1 - .../api/engagementDashboard/channels.ts | 16 +--- .../lib/engagementDashboard/channels.ts | 57 +------------ .../end-to-end/api/34-engagement-dashboard.ts | 85 +------------------ 4 files changed, 6 insertions(+), 153 deletions(-) diff --git a/apps/meteor/client/views/admin/engagementDashboard/channels/useChannelsList.ts b/apps/meteor/client/views/admin/engagementDashboard/channels/useChannelsList.ts index 571786b39ce4c..c8e9c82e74698 100644 --- a/apps/meteor/client/views/admin/engagementDashboard/channels/useChannelsList.ts +++ b/apps/meteor/client/views/admin/engagementDashboard/channels/useChannelsList.ts @@ -25,7 +25,6 @@ export const useChannelsList = ({ period, offset, count }: UseChannelsListOption end: end.toISOString(), offset, count, - hideRoomsWithNoActivity: true, }); return response diff --git a/apps/meteor/ee/server/api/engagementDashboard/channels.ts b/apps/meteor/ee/server/api/engagementDashboard/channels.ts index 9b224c63bb1ab..1bb5cb5f3e6eb 100644 --- a/apps/meteor/ee/server/api/engagementDashboard/channels.ts +++ b/apps/meteor/ee/server/api/engagementDashboard/channels.ts @@ -3,7 +3,6 @@ import { check, Match } from 'meteor/check'; import { API } from '../../../../app/api/server'; import { getPaginationItems } from '../../../../app/api/server/helpers/getPaginationItems'; -import { apiDeprecationLogger } from '../../../../app/lib/server/lib/deprecationWarningLogger'; import { findChannelsWithNumberOfMessages } from '../../lib/engagementDashboard/channels'; import { isDateISOString, mapDateForAPI } from '../../lib/engagementDashboard/date'; @@ -47,30 +46,17 @@ API.v1.addRoute( Match.ObjectIncluding({ start: Match.Where(isDateISOString), end: Match.Where(isDateISOString), - hideRoomsWithNoActivity: Match.Maybe(String), offset: Match.Maybe(String), count: Match.Maybe(String), }), ); - const { start, end, hideRoomsWithNoActivity } = this.queryParams; + const { start, end } = this.queryParams; const { offset, count } = await getPaginationItems(this.queryParams); - if (hideRoomsWithNoActivity === undefined) { - apiDeprecationLogger.deprecatedParameterUsage( - this.route, - 'hideRoomsWithNoActivity', - '7.0.0', - this.response, - ({ parameter, endpoint, version }) => - `Returning rooms that had no activity in ${endpoint} is deprecated and will be removed on version ${version} along with the \`${parameter}\` param. Set \`${parameter}\` as \`true\` to check how the endpoint will behave starting on ${version}`, - ); - } - const { channels, total } = await findChannelsWithNumberOfMessages({ start: mapDateForAPI(start), end: mapDateForAPI(end), - hideRoomsWithNoActivity: hideRoomsWithNoActivity === 'true', options: { offset, count }, }); diff --git a/apps/meteor/ee/server/lib/engagementDashboard/channels.ts b/apps/meteor/ee/server/lib/engagementDashboard/channels.ts index b302f4c586ae3..a71d7c99b21df 100644 --- a/apps/meteor/ee/server/lib/engagementDashboard/channels.ts +++ b/apps/meteor/ee/server/lib/engagementDashboard/channels.ts @@ -1,5 +1,5 @@ import type { IDirectMessageRoom, IRoom } from '@rocket.chat/core-typings'; -import { Analytics, Rooms } from '@rocket.chat/models'; +import { Analytics } from '@rocket.chat/models'; import moment from 'moment'; import { convertDateToInt, diffBetweenDaysInclusive } from './date'; @@ -8,12 +8,10 @@ import { roomCoordinator } from '../../../../server/lib/rooms/roomCoordinator'; export const findChannelsWithNumberOfMessages = async ({ start, end, - hideRoomsWithNoActivity, options = {}, }: { start: Date; end: Date; - hideRoomsWithNoActivity: boolean; options: { offset?: number; count?: number; @@ -34,10 +32,6 @@ export const findChannelsWithNumberOfMessages = async ({ }[]; total: number; }> => { - if (!hideRoomsWithNoActivity) { - return findAllChannelsWithNumberOfMessages({ start, end, options }); - } - const daysBetweenDates = diffBetweenDaysInclusive(end, start); const endOfLastWeek = moment(start).subtract(1, 'days').toDate(); const startOfLastWeek = moment(endOfLastWeek).subtract(daysBetweenDates, 'days').toDate(); @@ -63,52 +57,3 @@ export const findChannelsWithNumberOfMessages = async ({ total, }; }; - -export const findAllChannelsWithNumberOfMessages = async ({ - start, - end, - options = {}, -}: { - start: Date; - end: Date; - options: { - offset?: number; - count?: number; - }; -}): Promise<{ - channels: { - room: { - _id: IRoom['_id']; - name: IRoom['name'] | IRoom['fname']; - ts: IRoom['ts']; - t: IRoom['t']; - _updatedAt: IRoom['_updatedAt']; - usernames?: IDirectMessageRoom['usernames']; - }; - messages: number; - lastWeekMessages: number; - diffFromLastWeek: number; - }[]; - total: number; -}> => { - const daysBetweenDates = diffBetweenDaysInclusive(end, start); - const endOfLastWeek = moment(start).subtract(1, 'days').toDate(); - const startOfLastWeek = moment(endOfLastWeek).subtract(daysBetweenDates, 'days').toDate(); - const roomTypes = roomCoordinator.getTypesToShowOnDashboard() as Array; - - const channels = await Rooms.findChannelsByTypesWithNumberOfMessagesBetweenDate({ - types: roomTypes, - start: convertDateToInt(start), - end: convertDateToInt(end), - startOfLastWeek: convertDateToInt(startOfLastWeek), - endOfLastWeek: convertDateToInt(endOfLastWeek), - options, - }).toArray(); - - const total = await Rooms.countDocuments({ t: { $in: roomTypes } }); - - return { - channels, - total, - }; -}; diff --git a/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts b/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts index c1fc685d11f93..a9723226f3395 100644 --- a/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts +++ b/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts @@ -4,7 +4,6 @@ import { after, before, describe, it } from 'mocha'; import type { Response } from 'supertest'; import { getCredentials, api, request, credentials } from '../../data/api-data'; -import { sendSimpleMessage } from '../../data/chat.helper'; import { updatePermission } from '../../data/permissions.helper'; import { createRoom, deleteRoom } from '../../data/rooms.helper'; @@ -148,7 +147,7 @@ describe('[Engagement Dashboard]', function () { }); }); - it('should not return empty rooms when the hideRoomsWithNoActivity param is provided', async () => { + it('should fail when the deprecated hideRoomsWithNoActivity param is provided', async () => { await request .get(api('engagement-dashboard/channels/list')) .set(credentials) @@ -158,15 +157,10 @@ describe('[Engagement Dashboard]', function () { hideRoomsWithNoActivity: true, }) .expect('Content-Type', 'application/json') - .expect(200) + .expect(400) .expect((res: Response) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('offset', 0); - expect(res.body).to.have.property('count'); - expect(res.body).to.have.property('total'); - expect(res.body).to.have.property('channels'); - const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); - expect(channelRecord).to.be.undefined; + expect(res.body).to.have.property('success', false); + expect(res.body.error).to.include('Match error'); }); }); @@ -205,42 +199,6 @@ describe('[Engagement Dashboard]', function () { }); }); - it('should correctly count messages diff compared to last week when the hideRoomsWithNoActivity param is provided and there are messages in a room', async () => { - await sendSimpleMessage({ roomId: testRoom._id }); - await request - .get(api('engagement-dashboard/channels/list')) - .set(credentials) - .query({ - end: new Date().toISOString(), - start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), - hideRoomsWithNoActivity: true, - }) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res: Response) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('offset', 0); - expect(res.body).to.have.property('count'); - expect(res.body).to.have.property('total'); - expect(res.body).to.have.property('channels'); - expect(res.body.channels).to.be.an('array').that.is.not.empty; - - const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); - expect(channelRecord).not.to.be.undefined; - - expect(channelRecord).to.be.an('object').that.is.not.empty; - expect(channelRecord).to.have.property('messages', 1); - expect(channelRecord).to.have.property('lastWeekMessages', 0); - expect(channelRecord).to.have.property('diffFromLastWeek', 1); - expect(channelRecord.room).to.be.an('object').that.is.not.empty; - - expect(channelRecord.room).to.have.property('_id', testRoom._id); - expect(channelRecord.room).to.have.property('name', testRoom.name); - expect(channelRecord.room).to.have.property('ts', testRoom.ts); - expect(channelRecord.room).to.have.property('t', testRoom.t); - }); - }); - it('should correctly count messages diff compared to last week when there are messages in a room', async () => { await request .get(api('engagement-dashboard/channels/list')) @@ -275,41 +233,6 @@ describe('[Engagement Dashboard]', function () { }); }); - it('should correctly count messages from last week and diff when moving to the next week and providing the hideRoomsWithNoActivity param', async () => { - await request - .get(api('engagement-dashboard/channels/list')) - .set(credentials) - .query({ - end: new Date(Date.now() + 8 * 24 * 60 * 60 * 1000).toISOString(), - start: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), - hideRoomsWithNoActivity: true, - }) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res: Response) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('offset', 0); - expect(res.body).to.have.property('count'); - expect(res.body).to.have.property('total'); - expect(res.body).to.have.property('channels'); - expect(res.body.channels).to.be.an('array').that.is.not.empty; - - const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); - expect(channelRecord).not.to.be.undefined; - - expect(channelRecord).to.be.an('object').that.is.not.empty; - expect(channelRecord).to.have.property('messages', 0); - expect(channelRecord).to.have.property('lastWeekMessages', 1); - expect(channelRecord).to.have.property('diffFromLastWeek', -1); - expect(channelRecord.room).to.be.an('object').that.is.not.empty; - - expect(channelRecord.room).to.have.property('_id', testRoom._id); - expect(channelRecord.room).to.have.property('name', testRoom.name); - expect(channelRecord.room).to.have.property('ts', testRoom.ts); - expect(channelRecord.room).to.have.property('t', testRoom.t); - }); - }); - it('should correctly count messages from last week and diff when moving to the next week', async () => { await request .get(api('engagement-dashboard/channels/list')) From 4cc76659ce105aa55dc4b55f5786ceb92ddbcd6a Mon Sep 17 00:00:00 2001 From: Martin Schoeler Date: Mon, 8 Sep 2025 15:05:53 -0300 Subject: [PATCH 2/4] Create warm-boats-care.md --- .changeset/warm-boats-care.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/warm-boats-care.md diff --git a/.changeset/warm-boats-care.md b/.changeset/warm-boats-care.md new file mode 100644 index 0000000000000..8785d2235164b --- /dev/null +++ b/.changeset/warm-boats-care.md @@ -0,0 +1,5 @@ +--- +"@rocket.chat/meteor": major +--- + +Removes the deprecated `hideRoomsWithNoActivity` param from `admin/engagement-dashboard/channels/list` From d429e492a9e3fb67aaa8e76c38b7f50301ed58ab Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Tue, 9 Sep 2025 14:31:15 -0300 Subject: [PATCH 3/4] test: update and remove tests with old behavior --- .../end-to-end/api/34-engagement-dashboard.ts | 92 +------------------ 1 file changed, 5 insertions(+), 87 deletions(-) diff --git a/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts b/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts index a9723226f3395..7808feb054d1a 100644 --- a/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts +++ b/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts @@ -164,7 +164,8 @@ describe('[Engagement Dashboard]', function () { }); }); - it('should correctly count messages in an empty room', async () => { + // Counting messages in rooms with no activity was deprecated and no longer a desired behavior + it('should not count messages in an empty room', async () => { await request .get(api('engagement-dashboard/channels/list')) .set(credentials) @@ -177,93 +178,10 @@ describe('[Engagement Dashboard]', function () { .expect((res: Response) => { expect(res.body).to.have.property('success', true); expect(res.body).to.have.property('offset', 0); - expect(res.body).to.have.property('count'); - expect(res.body).to.have.property('total'); - expect(res.body).to.have.property('channels'); - expect(res.body.channels).to.be.an('array').that.is.not.empty; - - const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); - expect(channelRecord).not.to.be.undefined; - - expect(channelRecord).to.be.an('object').that.is.not.empty; - expect(channelRecord).to.have.property('messages', 0); - expect(channelRecord).to.have.property('lastWeekMessages', 0); - expect(channelRecord).to.have.property('diffFromLastWeek', 0); - expect(channelRecord.room).to.be.an('object').that.is.not.empty; - - expect(channelRecord.room).to.have.property('_id', testRoom._id); - expect(channelRecord.room).to.have.property('name', testRoom.name); - expect(channelRecord.room).to.have.property('ts', testRoom.ts); - expect(channelRecord.room).to.have.property('t', testRoom.t); - expect(channelRecord.room).to.have.property('_updatedAt', testRoom._updatedAt); - }); - }); - - it('should correctly count messages diff compared to last week when there are messages in a room', async () => { - await request - .get(api('engagement-dashboard/channels/list')) - .set(credentials) - .query({ - end: new Date().toISOString(), - start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), - }) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res: Response) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('offset', 0); - expect(res.body).to.have.property('count'); - expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('count', 0); + expect(res.body).to.have.property('total', 0); expect(res.body).to.have.property('channels'); - expect(res.body.channels).to.be.an('array').that.is.not.empty; - - const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); - expect(channelRecord).not.to.be.undefined; - - expect(channelRecord).to.be.an('object').that.is.not.empty; - expect(channelRecord).to.have.property('messages', 1); - expect(channelRecord).to.have.property('lastWeekMessages', 0); - expect(channelRecord).to.have.property('diffFromLastWeek', 1); - expect(channelRecord.room).to.be.an('object').that.is.not.empty; - - expect(channelRecord.room).to.have.property('_id', testRoom._id); - expect(channelRecord.room).to.have.property('name', testRoom.name); - expect(channelRecord.room).to.have.property('ts', testRoom.ts); - expect(channelRecord.room).to.have.property('t', testRoom.t); - }); - }); - - it('should correctly count messages from last week and diff when moving to the next week', async () => { - await request - .get(api('engagement-dashboard/channels/list')) - .set(credentials) - .query({ - end: new Date(Date.now() + 8 * 24 * 60 * 60 * 1000).toISOString(), - start: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), - }) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res: Response) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('offset', 0); - expect(res.body).to.have.property('count'); - expect(res.body).to.have.property('total'); - expect(res.body).to.have.property('channels'); - expect(res.body.channels).to.be.an('array').that.is.not.empty; - - const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); - expect(channelRecord).not.to.be.undefined; - - expect(channelRecord).to.be.an('object').that.is.not.empty; - expect(channelRecord).to.have.property('messages', 0); - expect(channelRecord).to.have.property('lastWeekMessages', 1); - expect(channelRecord).to.have.property('diffFromLastWeek', -1); - expect(channelRecord.room).to.be.an('object').that.is.not.empty; - - expect(channelRecord.room).to.have.property('_id', testRoom._id); - expect(channelRecord.room).to.have.property('name', testRoom.name); - expect(channelRecord.room).to.have.property('ts', testRoom.ts); - expect(channelRecord.room).to.have.property('t', testRoom.t); + expect(res.body.channels).to.be.an('array').that.is.empty; }); }); }); From 2f3ec5dbdbedadfca7ae7fe4aba9882c554c6e5c Mon Sep 17 00:00:00 2001 From: MartinSchoeler Date: Mon, 15 Sep 2025 17:26:04 -0300 Subject: [PATCH 4/4] test: fix test --- .../api/engagementDashboard/channels.ts | 2 +- .../end-to-end/api/34-engagement-dashboard.ts | 176 +++++++++++++++++- 2 files changed, 167 insertions(+), 11 deletions(-) diff --git a/apps/meteor/ee/server/api/engagementDashboard/channels.ts b/apps/meteor/ee/server/api/engagementDashboard/channels.ts index 1bb5cb5f3e6eb..96f2d5776ac02 100644 --- a/apps/meteor/ee/server/api/engagementDashboard/channels.ts +++ b/apps/meteor/ee/server/api/engagementDashboard/channels.ts @@ -10,7 +10,7 @@ declare module '@rocket.chat/rest-typings' { // eslint-disable-next-line @typescript-eslint/naming-convention interface Endpoints { '/v1/engagement-dashboard/channels/list': { - GET: (params: { start: string; end: string; offset?: number; count?: number; hideRoomsWithNoActivity?: boolean }) => { + GET: (params: { start: string; end: string; offset?: number; count?: number }) => { channels: { room: { _id: IRoom['_id']; diff --git a/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts b/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts index 7808feb054d1a..c6acb38dbbb17 100644 --- a/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts +++ b/apps/meteor/tests/end-to-end/api/34-engagement-dashboard.ts @@ -4,6 +4,7 @@ import { after, before, describe, it } from 'mocha'; import type { Response } from 'supertest'; import { getCredentials, api, request, credentials } from '../../data/api-data'; +import { sendSimpleMessage } from '../../data/chat.helper'; import { updatePermission } from '../../data/permissions.helper'; import { createRoom, deleteRoom } from '../../data/rooms.helper'; @@ -147,25 +148,98 @@ describe('[Engagement Dashboard]', function () { }); }); - it('should fail when the deprecated hideRoomsWithNoActivity param is provided', async () => { + it('should not return empty rooms', async () => { await request .get(api('engagement-dashboard/channels/list')) .set(credentials) .query({ end: new Date().toISOString(), start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), - hideRoomsWithNoActivity: true, }) .expect('Content-Type', 'application/json') - .expect(400) + .expect(200) .expect((res: Response) => { - expect(res.body).to.have.property('success', false); - expect(res.body.error).to.include('Match error'); + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('offset', 0); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('channels'); + const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); + expect(channelRecord).to.be.undefined; + }); + }); + + it('should correctly count messages in an empty room', async () => { + await request + .get(api('engagement-dashboard/channels/list')) + .set(credentials) + .query({ + end: new Date().toISOString(), + start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res: Response) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('offset', 0); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('channels'); + expect(res.body.channels).to.be.an('array').that.is.not.empty; + + const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); + expect(channelRecord).not.to.be.undefined; + + expect(channelRecord).to.be.an('object').that.is.not.empty; + expect(channelRecord).to.have.property('messages', 0); + expect(channelRecord).to.have.property('lastWeekMessages', 0); + expect(channelRecord).to.have.property('diffFromLastWeek', 0); + expect(channelRecord.room).to.be.an('object').that.is.not.empty; + + expect(channelRecord.room).to.have.property('_id', testRoom._id); + expect(channelRecord.room).to.have.property('name', testRoom.name); + expect(channelRecord.room).to.have.property('ts', testRoom.ts); + expect(channelRecord.room).to.have.property('t', testRoom.t); + expect(channelRecord.room).to.have.property('_updatedAt', testRoom._updatedAt); + }); + }); + + it('should correctly count messages diff compared to last week when the param is provided and there are messages in a room', async () => { + await sendSimpleMessage({ roomId: testRoom._id }); + await request + .get(api('engagement-dashboard/channels/list')) + .set(credentials) + .query({ + end: new Date().toISOString(), + start: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString(), + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res: Response) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('offset', 0); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('channels'); + expect(res.body.channels).to.be.an('array').that.is.not.empty; + + const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); + expect(channelRecord).not.to.be.undefined; + + expect(channelRecord).to.be.an('object').that.is.not.empty; + expect(channelRecord).to.have.property('messages', 1); + expect(channelRecord).to.have.property('lastWeekMessages', 0); + expect(channelRecord).to.have.property('diffFromLastWeek', 1); + expect(channelRecord.room).to.be.an('object').that.is.not.empty; + + expect(channelRecord.room).to.have.property('_id', testRoom._id); + expect(channelRecord.room).to.have.property('name', testRoom.name); + expect(channelRecord.room).to.have.property('ts', testRoom.ts); + expect(channelRecord.room).to.have.property('t', testRoom.t); }); }); - // Counting messages in rooms with no activity was deprecated and no longer a desired behavior - it('should not count messages in an empty room', async () => { + it('should correctly count messages diff compared to last week when there are messages in a room', async () => { await request .get(api('engagement-dashboard/channels/list')) .set(credentials) @@ -178,10 +252,92 @@ describe('[Engagement Dashboard]', function () { .expect((res: Response) => { expect(res.body).to.have.property('success', true); expect(res.body).to.have.property('offset', 0); - expect(res.body).to.have.property('count', 0); - expect(res.body).to.have.property('total', 0); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('channels'); + expect(res.body.channels).to.be.an('array').that.is.not.empty; + + const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); + expect(channelRecord).not.to.be.undefined; + + expect(channelRecord).to.be.an('object').that.is.not.empty; + expect(channelRecord).to.have.property('messages', 1); + expect(channelRecord).to.have.property('lastWeekMessages', 0); + expect(channelRecord).to.have.property('diffFromLastWeek', 1); + expect(channelRecord.room).to.be.an('object').that.is.not.empty; + + expect(channelRecord.room).to.have.property('_id', testRoom._id); + expect(channelRecord.room).to.have.property('name', testRoom.name); + expect(channelRecord.room).to.have.property('ts', testRoom.ts); + expect(channelRecord.room).to.have.property('t', testRoom.t); + }); + }); + + it('should correctly count messages from last week and diff when moving to the next week', async () => { + await request + .get(api('engagement-dashboard/channels/list')) + .set(credentials) + .query({ + end: new Date(Date.now() + 8 * 24 * 60 * 60 * 1000).toISOString(), + start: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res: Response) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('offset', 0); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); expect(res.body).to.have.property('channels'); - expect(res.body.channels).to.be.an('array').that.is.empty; + expect(res.body.channels).to.be.an('array').that.is.not.empty; + + const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); + expect(channelRecord).not.to.be.undefined; + + expect(channelRecord).to.be.an('object').that.is.not.empty; + expect(channelRecord).to.have.property('messages', 0); + expect(channelRecord).to.have.property('lastWeekMessages', 1); + expect(channelRecord).to.have.property('diffFromLastWeek', -1); + expect(channelRecord.room).to.be.an('object').that.is.not.empty; + + expect(channelRecord.room).to.have.property('_id', testRoom._id); + expect(channelRecord.room).to.have.property('name', testRoom.name); + expect(channelRecord.room).to.have.property('ts', testRoom.ts); + expect(channelRecord.room).to.have.property('t', testRoom.t); + }); + }); + + it('should correctly count messages from last week and diff when moving to the next week', async () => { + await request + .get(api('engagement-dashboard/channels/list')) + .set(credentials) + .query({ + end: new Date(Date.now() + 8 * 24 * 60 * 60 * 1000).toISOString(), + start: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res: Response) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('offset', 0); + expect(res.body).to.have.property('count'); + expect(res.body).to.have.property('total'); + expect(res.body).to.have.property('channels'); + expect(res.body.channels).to.be.an('array').that.is.not.empty; + + const channelRecord = res.body.channels.find(({ room }: { room: { _id: string } }) => room._id === testRoom._id); + expect(channelRecord).not.to.be.undefined; + + expect(channelRecord).to.be.an('object').that.is.not.empty; + expect(channelRecord).to.have.property('messages', 0); + expect(channelRecord).to.have.property('lastWeekMessages', 1); + expect(channelRecord).to.have.property('diffFromLastWeek', -1); + expect(channelRecord.room).to.be.an('object').that.is.not.empty; + + expect(channelRecord.room).to.have.property('_id', testRoom._id); + expect(channelRecord.room).to.have.property('name', testRoom.name); + expect(channelRecord.room).to.have.property('ts', testRoom.ts); + expect(channelRecord.room).to.have.property('t', testRoom.t); }); }); });