Skip to content

Commit 0c3bcd5

Browse files
committed
test: apps-engine presence bridge
1 parent 581d29e commit 0c3bcd5

5 files changed

Lines changed: 90 additions & 1 deletion

File tree

apps/meteor/app/apps/server/bridges/users.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class AppUserBridge extends UserBridge {
184184
statusDefault: state.statusDefault as UserStatus,
185185
statusText: state.statusText,
186186
statusSource: state.statusSource as PresenceSource,
187-
statusExpiresAt: state.statusExpiresAt,
187+
...(state.statusExpiresAt && { statusExpiresAt: state.statusExpiresAt }),
188188
});
189189
}
190190

apps/meteor/tests/data/apps/app-packages/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ export const appUpdateStatusTest = path.resolve(__dirname, './update-status-test
1313
export const appExternalIdTest = path.resolve(__dirname, './external-id-test_0.0.1.zip');
1414

1515
export const messageReactionTest = path.resolve(__dirname, './message-updater-test_0.0.1.zip');
16+
17+
export const appPresenceStateTest = path.resolve(__dirname, './presence-state-test_0.0.1.zip');
Binary file not shown.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
});

packages/apps/tests/test-data/bridges/userBridge.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@ export class TestsUserBridge extends UserBridge {
4646
protected deactivate(userId: IUser['id'], confirmRelinquish: boolean, appId: string): Promise<boolean> {
4747
throw new Error('Method not implemented.');
4848
}
49+
50+
protected setActiveState(
51+
userId: IUser['id'],
52+
state: Pick<IUser, 'statusDefault' | 'statusSource' | 'statusText' | 'statusExpiresAt'>,
53+
appId: string,
54+
): Promise<void> {
55+
throw new Error('Method not implemented.');
56+
}
57+
58+
protected endActiveState(userId: IUser['id'], appId: string): Promise<void> {
59+
throw new Error('Method not implemented.');
60+
}
4961
}

0 commit comments

Comments
 (0)