From 1f867eaf0b538a216965ee2e3b4b6feed3624d35 Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Wed, 30 Aug 2023 13:10:37 -0600 Subject: [PATCH] tests --- .../end-to-end/api/livechat/09-visitors.ts | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts index a3ca544de20c..55ef4402da39 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts @@ -2,7 +2,8 @@ import { faker } from '@faker-js/faker'; import type { ILivechatVisitor } from '@rocket.chat/core-typings'; import { expect } from 'chai'; import { before, describe, it } from 'mocha'; -import type { Response } from 'supertest'; +import moment from 'moment'; +import { type Response } from 'supertest'; import { getCredentials, api, request, credentials } from '../../../data/api-data'; import { createCustomField, deleteCustomField } from '../../../data/livechat/custom-fields'; @@ -334,6 +335,27 @@ describe('LIVECHAT - visitors', function () { }); }); + it('should return visitor activity field when visitor was active on month', async () => { + // Activity is determined by a conversation in which an agent has engaged (sent a message) + // For a visitor to be considered active, they must have had a conversation in the last 30 days + const period = moment().format('YYYY-MM'); + const { visitor, room } = await startANewLivechatRoomAndTakeIt(); + // agent should send a message on the room + await request + .post(api('chat.sendMessage')) + .set(credentials) + .send({ + message: { + rid: room._id, + msg: 'test', + }, + }); + + const activeVisitor = await getLivechatVisitorByToken(visitor.token); + expect(activeVisitor).to.have.property('activity'); + expect(activeVisitor.activity).to.include(period); + }); + it("should return a 'error-removing-visitor' error when removeGuest's result is false", async () => { await request .delete(api('livechat/visitor/123'))