|
| 1 | +import type { App } from '@rocket.chat/core-typings'; |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { after, before, describe, it } from 'mocha'; |
| 4 | + |
| 5 | +import { getCredentials, request, credentials } from '../../data/api-data'; |
| 6 | +import { appPresenceStateTest } from '../../data/apps/app-packages'; |
| 7 | +import { apps } from '../../data/apps/apps-data'; |
| 8 | +import { cleanupApps, installLocalTestPackage } from '../../data/apps/helper'; |
| 9 | +import { getUserByUsername } from '../../data/users.helper'; |
| 10 | +import { IS_EE } from '../../e2e/config/constants'; |
| 11 | + |
| 12 | +const ADMIN_USERNAME = 'rocketchat.internal.admin.test'; |
| 13 | + |
| 14 | +(IS_EE ? describe : describe.skip)('Apps - Presence State Bridge', () => { |
| 15 | + let app: App; |
| 16 | + |
| 17 | + before((done) => getCredentials(done)); |
| 18 | + |
| 19 | + before(async () => { |
| 20 | + await cleanupApps(); |
| 21 | + app = await installLocalTestPackage(appPresenceStateTest); |
| 22 | + }); |
| 23 | + |
| 24 | + after(() => cleanupApps()); |
| 25 | + |
| 26 | + describe('[setActiveState]', () => { |
| 27 | + it('should set the user presence with status text and source', async () => { |
| 28 | + const user = await getUserByUsername(ADMIN_USERNAME); |
| 29 | + |
| 30 | + await request |
| 31 | + .post(apps(`/public/${app.id}/set-active-state`)) |
| 32 | + .set(credentials) |
| 33 | + .send({ |
| 34 | + userId: user._id, |
| 35 | + statusDefault: 'busy', |
| 36 | + statusText: 'In a meeting', |
| 37 | + statusSource: 'internal', |
| 38 | + }) |
| 39 | + .expect(200); |
| 40 | + |
| 41 | + const updatedUser = await getUserByUsername(ADMIN_USERNAME); |
| 42 | + expect(updatedUser.statusText).to.equal('In a meeting'); |
| 43 | + expect(updatedUser.statusSource).to.equal('internal'); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('[endActiveState]', () => { |
| 48 | + it('should restore the user presence to previous state', async () => { |
| 49 | + const user = await getUserByUsername(ADMIN_USERNAME); |
| 50 | + |
| 51 | + // First set an active state |
| 52 | + await request |
| 53 | + .post(apps(`/public/${app.id}/set-active-state`)) |
| 54 | + .set(credentials) |
| 55 | + .send({ |
| 56 | + userId: user._id, |
| 57 | + statusDefault: 'busy', |
| 58 | + statusText: 'On a call', |
| 59 | + statusSource: 'internal', |
| 60 | + }) |
| 61 | + .expect(200); |
| 62 | + |
| 63 | + // Then end it |
| 64 | + await request |
| 65 | + .post(apps(`/public/${app.id}/end-active-state`)) |
| 66 | + .set(credentials) |
| 67 | + .send({ userId: user._id }) |
| 68 | + .expect(200); |
| 69 | + |
| 70 | + const updatedUser = await getUserByUsername(ADMIN_USERNAME); |
| 71 | + expect(updatedUser.statusText).to.not.equal('On a call'); |
| 72 | + expect(updatedUser.statusSource).to.not.equal('internal'); |
| 73 | + }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments