2022-04-20 19:35:53 +00:00
|
|
|
// Copyright 2022 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
import type { PrimaryDevice, Group } from '@signalapp/mock-server';
|
2023-08-16 20:54:39 +00:00
|
|
|
import { StorageState, Proto, ServiceIdKind } from '@signalapp/mock-server';
|
2022-04-20 19:35:53 +00:00
|
|
|
import createDebug from 'debug';
|
|
|
|
|
|
|
|
import * as durations from '../../util/durations';
|
|
|
|
import { Bootstrap } from '../bootstrap';
|
|
|
|
import type { App } from '../bootstrap';
|
2022-11-10 15:51:39 +00:00
|
|
|
import { MY_STORY_ID } from '../../types/Stories';
|
2022-07-21 00:07:09 +00:00
|
|
|
import { uuidToBytes } from '../../util/uuidToBytes';
|
|
|
|
|
|
|
|
const IdentifierType = Proto.ManifestRecord.Identifier.Type;
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
export const debug = createDebug('mock:test:gv2');
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
describe('pnp/send gv2 invite', function (this: Mocha.Suite) {
|
2022-04-20 19:35:53 +00:00
|
|
|
this.timeout(durations.MINUTE);
|
|
|
|
|
|
|
|
let bootstrap: Bootstrap;
|
|
|
|
let app: App;
|
2022-04-27 00:30:44 +00:00
|
|
|
let aciContact: PrimaryDevice;
|
2022-04-20 19:35:53 +00:00
|
|
|
let pniContact: PrimaryDevice;
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
2023-02-14 17:39:47 +00:00
|
|
|
bootstrap = new Bootstrap({
|
|
|
|
contactCount: 0,
|
|
|
|
});
|
2022-04-20 19:35:53 +00:00
|
|
|
await bootstrap.init();
|
|
|
|
|
2022-04-27 00:30:44 +00:00
|
|
|
const { phone, server } = bootstrap;
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
let state = StorageState.getEmpty();
|
|
|
|
|
|
|
|
state = state.updateAccount({
|
|
|
|
profileKey: phone.profileKey.serialize(),
|
|
|
|
e164: phone.device.number,
|
|
|
|
});
|
|
|
|
|
2022-04-27 00:30:44 +00:00
|
|
|
aciContact = await server.createPrimaryDevice({
|
|
|
|
profileName: 'ACI Contact',
|
|
|
|
});
|
|
|
|
state = state.addContact(aciContact, {
|
2022-04-20 19:35:53 +00:00
|
|
|
identityState: Proto.ContactRecord.IdentityState.VERIFIED,
|
|
|
|
whitelisted: true,
|
|
|
|
|
2022-04-27 00:30:44 +00:00
|
|
|
identityKey: aciContact.publicKey.serialize(),
|
|
|
|
profileKey: aciContact.profileKey.serialize(),
|
2022-04-20 19:35:53 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
pniContact = await server.createPrimaryDevice({
|
2022-04-27 00:30:44 +00:00
|
|
|
profileName: 'My profile is a secret',
|
2022-04-20 19:35:53 +00:00
|
|
|
});
|
2022-08-15 21:53:33 +00:00
|
|
|
state = state.addContact(
|
|
|
|
pniContact,
|
|
|
|
{
|
|
|
|
identityState: Proto.ContactRecord.IdentityState.VERIFIED,
|
|
|
|
whitelisted: true,
|
2022-04-20 19:35:53 +00:00
|
|
|
|
2023-08-16 20:54:39 +00:00
|
|
|
identityKey: pniContact.getPublicKey(ServiceIdKind.PNI).serialize(),
|
2022-04-20 19:35:53 +00:00
|
|
|
|
2022-08-15 21:53:33 +00:00
|
|
|
givenName: 'PNI Contact',
|
|
|
|
},
|
2023-08-16 20:54:39 +00:00
|
|
|
ServiceIdKind.PNI
|
2022-08-15 21:53:33 +00:00
|
|
|
);
|
2022-04-20 19:35:53 +00:00
|
|
|
|
2022-07-21 00:07:09 +00:00
|
|
|
state = state.addRecord({
|
|
|
|
type: IdentifierType.STORY_DISTRIBUTION_LIST,
|
|
|
|
record: {
|
|
|
|
storyDistributionList: {
|
|
|
|
allowsReplies: true,
|
2022-11-10 15:51:39 +00:00
|
|
|
identifier: uuidToBytes(MY_STORY_ID),
|
2022-07-21 00:07:09 +00:00
|
|
|
isBlockList: true,
|
2022-11-10 15:51:39 +00:00
|
|
|
name: MY_STORY_ID,
|
2023-08-16 20:54:39 +00:00
|
|
|
recipientServiceIds: [],
|
2022-07-21 00:07:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-04-20 19:35:53 +00:00
|
|
|
await phone.setStorageState(state);
|
|
|
|
|
|
|
|
app = await bootstrap.link();
|
|
|
|
});
|
|
|
|
|
2023-10-11 19:06:43 +00:00
|
|
|
afterEach(async function (this: Mocha.Context) {
|
2023-07-14 16:53:20 +00:00
|
|
|
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
2022-04-20 19:35:53 +00:00
|
|
|
await app.close();
|
|
|
|
await bootstrap.teardown();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create group and modify it', async () => {
|
2022-04-27 00:30:44 +00:00
|
|
|
const { phone } = bootstrap;
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
let state = await phone.expectStorageState('initial state');
|
|
|
|
|
|
|
|
const window = await app.getWindow();
|
|
|
|
|
2023-07-26 22:23:32 +00:00
|
|
|
const leftPane = window.locator('#LeftPane');
|
|
|
|
const conversationStack = window.locator('.Inbox__conversation-stack');
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
debug('clicking compose and "New group" buttons');
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
await window.getByRole('button', { name: 'New chat' }).click();
|
2022-04-20 19:35:53 +00:00
|
|
|
|
2024-02-08 23:19:03 +00:00
|
|
|
await leftPane.getByTestId('ComposeStepButton--group').click();
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
debug('inviting ACI member');
|
|
|
|
|
|
|
|
await leftPane
|
2022-04-27 00:30:44 +00:00
|
|
|
.locator('.module-left-pane__compose-search-form__input')
|
|
|
|
.fill('ACI');
|
|
|
|
|
2023-01-25 23:51:08 +00:00
|
|
|
await leftPane.locator('.ListTile >> "ACI Contact"').click();
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
debug('inviting PNI member');
|
|
|
|
|
|
|
|
await leftPane
|
|
|
|
.locator('.module-left-pane__compose-search-form__input')
|
2022-04-27 00:30:44 +00:00
|
|
|
.fill('PNI');
|
2022-04-20 19:35:53 +00:00
|
|
|
|
2023-01-25 23:51:08 +00:00
|
|
|
await leftPane.locator('.ListTile >> "PNI Contact"').click();
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
await leftPane
|
|
|
|
.locator('.module-left-pane__footer button >> "Next"')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
debug('entering group title');
|
|
|
|
|
|
|
|
await leftPane.type('My group');
|
|
|
|
|
|
|
|
await leftPane
|
|
|
|
.locator('.module-left-pane__footer button >> "Create"')
|
|
|
|
.click();
|
|
|
|
|
|
|
|
debug('waiting for invitation modal');
|
|
|
|
|
|
|
|
{
|
|
|
|
const modal = window.locator(
|
|
|
|
'.module-GroupDialog:has-text("Invitation sent")'
|
|
|
|
);
|
|
|
|
|
|
|
|
await modal.locator('button >> "Okay"').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('waiting for group data from storage service');
|
|
|
|
|
|
|
|
let group: Group;
|
|
|
|
{
|
|
|
|
state = await phone.waitForStorageState({ after: state });
|
|
|
|
const groups = await phone.getAllGroups(state);
|
|
|
|
assert.strictEqual(groups.length, 1);
|
|
|
|
|
|
|
|
[group] = groups;
|
|
|
|
assert.strictEqual(group.title, 'My group');
|
|
|
|
assert.strictEqual(group.revision, 0);
|
|
|
|
assert.strictEqual(group.state.members?.length, 2);
|
|
|
|
assert.strictEqual(group.state.membersPendingProfileKey?.length, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('opening group settings');
|
|
|
|
|
|
|
|
await conversationStack
|
|
|
|
.locator('button.module-ConversationHeader__button--more')
|
|
|
|
.click();
|
|
|
|
|
2023-10-06 15:45:43 +00:00
|
|
|
await window.locator('.react-contextmenu-item >> "Group settings"').click();
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
debug('editing group title');
|
|
|
|
{
|
|
|
|
const detailsHeader = conversationStack.locator(
|
2023-01-13 00:24:59 +00:00
|
|
|
'[data-testid=ConversationDetailsHeader]'
|
2022-04-20 19:35:53 +00:00
|
|
|
);
|
2022-12-21 18:41:48 +00:00
|
|
|
await detailsHeader.locator('button >> "My group"').click();
|
2022-04-20 19:35:53 +00:00
|
|
|
|
|
|
|
const modal = window.locator('.module-Modal:has-text("Edit group")');
|
|
|
|
|
|
|
|
// Group title should be immediately focused.
|
|
|
|
await modal.type(' (v2)');
|
|
|
|
|
|
|
|
await modal.locator('button >> "Save"').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
debug('waiting for the second group update');
|
|
|
|
group = await phone.waitForGroupUpdate(group);
|
|
|
|
|
|
|
|
assert.strictEqual(group.title, 'My group (v2)');
|
|
|
|
assert.strictEqual(group.revision, 1);
|
|
|
|
});
|
|
|
|
});
|