Skip to content

Commit a869f72

Browse files
committed
refactor: avoid hardcoded roles in Reply in DM e2e tests
1 parent d433a1d commit a869f72

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

apps/meteor/tests/e2e/message-actions.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ADMIN_CREDENTIALS } from './config/constants';
22
import { Users } from './fixtures/userStates';
33
import { HomeChannel } from './page-objects';
44
import { CreateNewDiscussionModal } from './page-objects/fragments';
5-
import { createTargetChannel, createTargetTeam, sendTargetChannelMessage } from './utils';
5+
import { createTargetChannel, createTargetTeam, getPermissionRoles, sendTargetChannelMessage } from './utils';
66
import { setUserPreferences } from './utils/setUserPreferences';
77
import { expect, test } from './utils/test';
88

@@ -165,7 +165,11 @@ test.describe.serial('message-actions', () => {
165165
test.describe.serial('expect reply in direct message', () => {
166166
test.use({ storageState: Users.user2.state });
167167

168+
let originalCreateDRoles: string[];
169+
168170
test.beforeAll(async ({ api }) => {
171+
originalCreateDRoles = await getPermissionRoles(api, 'create-d');
172+
169173
await sendTargetChannelMessage(api, targetChannel, { msg: 'message from admin for reply in DM' });
170174
});
171175

@@ -177,9 +181,9 @@ test.describe.serial('message-actions', () => {
177181
});
178182

179183
test('expect option be visible and redirect to DM', async ({ page, api }) => {
180-
expect(
181-
(await api.post('/permissions.update', { permissions: [{ _id: 'create-d', roles: ['admin', 'user', 'bot', 'app'] }] })).status(),
182-
).toBe(200);
184+
expect((await api.post('/permissions.update', { permissions: [{ _id: 'create-d', roles: originalCreateDRoles }] })).status()).toBe(
185+
200,
186+
);
183187

184188
await poHomeChannel.content.openLastMessageMenu();
185189
await poHomeChannel.content.btnOptionReplyInDm.click();
@@ -188,9 +192,9 @@ test.describe.serial('message-actions', () => {
188192
});
189193

190194
test.afterAll(async ({ api }) => {
191-
expect(
192-
(await api.post('/permissions.update', { permissions: [{ _id: 'create-d', roles: ['admin', 'user', 'bot', 'app'] }] })).status(),
193-
).toBe(200);
195+
expect((await api.post('/permissions.update', { permissions: [{ _id: 'create-d', roles: originalCreateDRoles }] })).status()).toBe(
196+
200,
197+
);
194198
});
195199
});
196200

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { BaseTest } from './test';
2+
3+
export const getPermissionRoles = async (api: BaseTest['api'], permissionId: string): Promise<string[]> => {
4+
const res = await api.get('/permissions.listAll');
5+
const { update } = await res.json();
6+
return update.find((p: { _id: string }) => p._id === permissionId)?.roles ?? [];
7+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './create-target-channel';
22
export * from './setSettingValueById';
33
export * from './getSettingValueById';
4+
export * from './getPermissionRoles';
45
export * from './setUserPreferences';
56
export * from './updateOwnUserInfo';

0 commit comments

Comments
 (0)