signal-desktop/ts/test-mock/messaging/sender_key_test.ts

91 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-05-15 23:15:43 +00:00
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import createDebug from 'debug';
import { StorageState } from '@signalapp/mock-server';
import type { Group } from '@signalapp/mock-server';
import * as durations from '../../util/durations';
import type { App } from '../playwright';
import { Bootstrap } from '../bootstrap';
export const debug = createDebug('mock:test:senderKey');
describe('senderKey', function (this: Mocha.Suite) {
2023-05-15 23:15:43 +00:00
this.timeout(durations.MINUTE);
let bootstrap: Bootstrap;
let app: App;
let group: Group;
beforeEach(async () => {
bootstrap = new Bootstrap();
await bootstrap.init();
const { contacts, phone } = bootstrap;
const [first] = contacts;
group = await first.createGroup({
title: 'Group',
members: [first, phone],
});
let state = StorageState.getEmpty();
state = state.updateAccount({
profileKey: phone.profileKey.serialize(),
e164: phone.device.number,
givenName: phone.profileName,
});
state = state
.addGroup(group, {
whitelisted: true,
})
.pinGroup(group);
await phone.setStorageState(state);
app = await bootstrap.link();
});
afterEach(async function (this: Mocha.Context) {
2023-05-15 23:15:43 +00:00
if (!bootstrap) {
return;
}
await bootstrap.maybeSaveLogs(this.currentTest, app);
2023-05-15 23:15:43 +00:00
await app.close();
await bootstrap.teardown();
});
it('handles incoming senderKey distributions and messages', async () => {
const { desktop, contacts } = bootstrap;
const [first] = contacts;
const window = await app.getWindow();
const distributionId = await first.sendSenderKey(desktop, {
timestamp: bootstrap.getTimestamp(),
});
await first.sendText(desktop, 'hello', {
timestamp: bootstrap.getTimestamp(),
group,
distributionId,
});
const leftPane = window.locator('#LeftPane');
2023-05-15 23:15:43 +00:00
debug('Opening group');
await leftPane.locator(`[data-testid="${group.id}"]`).click();
const conversationStack = window.locator('.Inbox__conversation-stack');
2023-05-15 23:15:43 +00:00
debug('Verifying message');
await conversationStack
.locator('.module-message--incoming >> "hello"')
.waitFor();
});
});