Add test for call link storage
This commit is contained in:
parent
9c918e4d62
commit
83f42f3100
7 changed files with 259 additions and 31 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
@ -126,7 +126,7 @@
|
||||||
"@indutny/parallel-prettier": "3.0.0",
|
"@indutny/parallel-prettier": "3.0.0",
|
||||||
"@indutny/rezip-electron": "1.3.2",
|
"@indutny/rezip-electron": "1.3.2",
|
||||||
"@indutny/symbolicate-mac": "2.3.0",
|
"@indutny/symbolicate-mac": "2.3.0",
|
||||||
"@signalapp/mock-server": "8.2.0",
|
"@signalapp/mock-server": "8.3.1",
|
||||||
"@storybook/addon-a11y": "8.1.11",
|
"@storybook/addon-a11y": "8.1.11",
|
||||||
"@storybook/addon-actions": "8.1.11",
|
"@storybook/addon-actions": "8.1.11",
|
||||||
"@storybook/addon-controls": "8.1.11",
|
"@storybook/addon-controls": "8.1.11",
|
||||||
|
@ -7306,9 +7306,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@signalapp/mock-server": {
|
"node_modules/@signalapp/mock-server": {
|
||||||
"version": "8.2.0",
|
"version": "8.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/@signalapp/mock-server/-/mock-server-8.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@signalapp/mock-server/-/mock-server-8.3.1.tgz",
|
||||||
"integrity": "sha512-gHg6sWMxh+VJ6KW5qGPcI+ITwkO45wieT148iTDKaWVchWo7vQh4yEW4B+OLJY29NXlfjf0TZb6ZLoFfnmEUSA==",
|
"integrity": "sha512-w4zMyLwRHZc90bxbWpG7NbtPoLXhjMIcEiqA8a5IR3qDonF/Fpi6rR047iYtfs66pBYP58XsSqRNBVzvP/Pj8Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -210,7 +210,7 @@
|
||||||
"@indutny/parallel-prettier": "3.0.0",
|
"@indutny/parallel-prettier": "3.0.0",
|
||||||
"@indutny/rezip-electron": "1.3.2",
|
"@indutny/rezip-electron": "1.3.2",
|
||||||
"@indutny/symbolicate-mac": "2.3.0",
|
"@indutny/symbolicate-mac": "2.3.0",
|
||||||
"@signalapp/mock-server": "8.2.0",
|
"@signalapp/mock-server": "8.3.1",
|
||||||
"@storybook/addon-a11y": "8.1.11",
|
"@storybook/addon-a11y": "8.1.11",
|
||||||
"@storybook/addon-actions": "8.1.11",
|
"@storybook/addon-actions": "8.1.11",
|
||||||
"@storybook/addon-controls": "8.1.11",
|
"@storybook/addon-controls": "8.1.11",
|
||||||
|
|
|
@ -839,6 +839,7 @@ export function CallsList({
|
||||||
key={key}
|
key={key}
|
||||||
style={style}
|
style={style}
|
||||||
data-type={item.type}
|
data-type={item.type}
|
||||||
|
data-testid={item.peerId}
|
||||||
className={classNames('CallsList__Item', {
|
className={classNames('CallsList__Item', {
|
||||||
'CallsList__Item--selected': isSelected,
|
'CallsList__Item--selected': isSelected,
|
||||||
'CallsList__Item--missed': wasMissed,
|
'CallsList__Item--missed': wasMissed,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { expect } from 'playwright/test';
|
||||||
import * as durations from '../../util/durations';
|
import * as durations from '../../util/durations';
|
||||||
import type { App } from '../playwright';
|
import type { App } from '../playwright';
|
||||||
import { Bootstrap } from '../bootstrap';
|
import { Bootstrap } from '../bootstrap';
|
||||||
|
import { createCallLink } from '../helpers';
|
||||||
|
|
||||||
describe('calling/callLinkAdmin', function (this: Mocha.Suite) {
|
describe('calling/callLinkAdmin', function (this: Mocha.Suite) {
|
||||||
this.timeout(durations.MINUTE);
|
this.timeout(durations.MINUTE);
|
||||||
|
@ -30,41 +31,57 @@ describe('calling/callLinkAdmin', function (this: Mocha.Suite) {
|
||||||
it('can create and edit a call link', async () => {
|
it('can create and edit a call link', async () => {
|
||||||
const window = await app.getWindow();
|
const window = await app.getWindow();
|
||||||
|
|
||||||
await window.locator('[data-testid="NavTabsItem--Calls"]').click();
|
{
|
||||||
|
const name = 'New Name';
|
||||||
|
await createCallLink(window, { name });
|
||||||
|
|
||||||
await window
|
const title = await window
|
||||||
.locator('.NavSidebar__HeaderTitle')
|
.locator('.CallsList__ItemTile')
|
||||||
.getByText('Calls')
|
.getByText(name);
|
||||||
.waitFor();
|
|
||||||
|
|
||||||
await window
|
await expect(title).toContainText(name);
|
||||||
.locator('.CallsList__ItemTile')
|
}
|
||||||
.getByText('Create a Call Link')
|
|
||||||
.click();
|
|
||||||
|
|
||||||
const editModal = window.locator('.CallLinkEditModal');
|
{
|
||||||
await editModal.waitFor();
|
const name = 'Public call link';
|
||||||
|
await createCallLink(window, {
|
||||||
|
name,
|
||||||
|
isAdminApprovalRequired: false,
|
||||||
|
});
|
||||||
|
|
||||||
const restrictionsInput = editModal.getByLabel('Require admin approval');
|
const callLinkItem = await window.getByText(name);
|
||||||
|
await callLinkItem.click();
|
||||||
|
|
||||||
await expect(restrictionsInput).toHaveJSProperty('value', '0');
|
const callLinkDetails = window.locator(
|
||||||
await restrictionsInput.selectOption({ label: 'On' });
|
'.CallsTab__ConversationCallDetails'
|
||||||
await expect(restrictionsInput).toHaveJSProperty('value', '1');
|
);
|
||||||
|
await callLinkDetails.waitFor();
|
||||||
|
|
||||||
await editModal.locator('button', { hasText: 'Add call name' }).click();
|
const restrictionsSelect = await window.locator(
|
||||||
|
'.CallLinkRestrictionsSelect select'
|
||||||
|
);
|
||||||
|
await expect(restrictionsSelect).toHaveJSProperty('value', '0');
|
||||||
|
}
|
||||||
|
|
||||||
const addNameModal = window.locator('.CallLinkAddNameModal');
|
{
|
||||||
await addNameModal.waitFor();
|
const name = 'Restricted call link';
|
||||||
|
await createCallLink(window, {
|
||||||
|
name,
|
||||||
|
isAdminApprovalRequired: true,
|
||||||
|
});
|
||||||
|
|
||||||
const nameInput = addNameModal.getByLabel('Call name');
|
const callLinkItem = await window.getByText(name);
|
||||||
await nameInput.fill('New Name');
|
await callLinkItem.click();
|
||||||
|
|
||||||
const saveBtn = addNameModal.getByText('Save');
|
const callLinkDetails = window.locator(
|
||||||
await saveBtn.click();
|
'.CallsTab__ConversationCallDetails'
|
||||||
|
);
|
||||||
|
await callLinkDetails.waitFor();
|
||||||
|
|
||||||
await editModal.waitFor();
|
const restrictionsSelect = await window.locator(
|
||||||
|
'.CallLinkRestrictionsSelect select'
|
||||||
const title = editModal.locator('.CallLinkEditModal__Header__Title');
|
);
|
||||||
await expect(title).toContainText('New Name');
|
await expect(restrictionsSelect).toHaveJSProperty('value', '1');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -367,3 +367,59 @@ export async function waitForEnabledComposer(page: Page): Promise<Locator> {
|
||||||
|
|
||||||
return composeContainer.locator('.ql-editor');
|
return composeContainer.locator('.ql-editor');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function createCallLink(
|
||||||
|
page: Page,
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
isAdminApprovalRequired = undefined,
|
||||||
|
}: { name: string; isAdminApprovalRequired?: boolean | undefined }
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
await page.locator('[data-testid="NavTabsItem--Calls"]').click();
|
||||||
|
await page.locator('.NavSidebar__HeaderTitle').getByText('Calls').waitFor();
|
||||||
|
|
||||||
|
await page
|
||||||
|
.locator('.CallsList__ItemTile')
|
||||||
|
.getByText('Create a Call Link')
|
||||||
|
.click();
|
||||||
|
|
||||||
|
const editModal = page.locator('.CallLinkEditModal');
|
||||||
|
await editModal.waitFor();
|
||||||
|
|
||||||
|
if (isAdminApprovalRequired !== undefined) {
|
||||||
|
const restrictionsInput = editModal.getByLabel('Require admin approval');
|
||||||
|
if (isAdminApprovalRequired) {
|
||||||
|
await expect(restrictionsInput).toHaveJSProperty('value', '0');
|
||||||
|
await restrictionsInput.selectOption({ label: 'On' });
|
||||||
|
await expect(restrictionsInput).toHaveJSProperty('value', '1');
|
||||||
|
} else {
|
||||||
|
await expect(restrictionsInput).toHaveJSProperty('value', '0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await editModal.locator('button', { hasText: 'Add call name' }).click();
|
||||||
|
|
||||||
|
const addNameModal = page.locator('.CallLinkAddNameModal');
|
||||||
|
await addNameModal.waitFor();
|
||||||
|
|
||||||
|
const nameInput = addNameModal.getByLabel('Call name');
|
||||||
|
await nameInput.fill(name);
|
||||||
|
|
||||||
|
const saveBtn = addNameModal.getByText('Save');
|
||||||
|
await saveBtn.click();
|
||||||
|
|
||||||
|
await editModal.waitFor();
|
||||||
|
|
||||||
|
const doneBtn = editModal.getByText('Done');
|
||||||
|
await doneBtn.click();
|
||||||
|
|
||||||
|
const callLinkTitle = await page
|
||||||
|
.locator('.CallsList__ItemTile')
|
||||||
|
.getByText(name);
|
||||||
|
|
||||||
|
const callLinkItem = await page.locator('.CallsList__Item', {
|
||||||
|
has: callLinkTitle,
|
||||||
|
});
|
||||||
|
const testId = await callLinkItem.getAttribute('data-testid');
|
||||||
|
return testId || undefined;
|
||||||
|
}
|
||||||
|
|
138
ts/test-mock/storage/call_links_test.ts
Normal file
138
ts/test-mock/storage/call_links_test.ts
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
// Copyright 2024 Signal Messenger, LLC
|
||||||
|
// SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
import { assert } from 'chai';
|
||||||
|
import Long from 'long';
|
||||||
|
import { Proto, StorageState } from '@signalapp/mock-server';
|
||||||
|
import * as durations from '../../util/durations';
|
||||||
|
import type { App } from './fixtures';
|
||||||
|
import { Bootstrap, debug, getCallLinkRecordPredicate } from './fixtures';
|
||||||
|
import { createCallLink } from '../helpers';
|
||||||
|
import { uuidToBytes } from '../../util/uuidToBytes';
|
||||||
|
import { MY_STORY_ID } from '../../types/Stories';
|
||||||
|
|
||||||
|
const IdentifierType = Proto.ManifestRecord.Identifier.Type;
|
||||||
|
|
||||||
|
describe('storage service', function (this: Mocha.Suite) {
|
||||||
|
this.timeout(durations.MINUTE);
|
||||||
|
|
||||||
|
let bootstrap: Bootstrap;
|
||||||
|
let app: App;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
bootstrap = new Bootstrap({ contactCount: 0 });
|
||||||
|
await bootstrap.init();
|
||||||
|
|
||||||
|
const { phone } = bootstrap;
|
||||||
|
|
||||||
|
let state = StorageState.getEmpty();
|
||||||
|
|
||||||
|
state = state.updateAccount({
|
||||||
|
profileKey: phone.profileKey.serialize(),
|
||||||
|
e164: phone.device.number,
|
||||||
|
givenName: phone.profileName,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add my story
|
||||||
|
state = state.addRecord({
|
||||||
|
type: IdentifierType.STORY_DISTRIBUTION_LIST,
|
||||||
|
record: {
|
||||||
|
storyDistributionList: {
|
||||||
|
allowsReplies: true,
|
||||||
|
identifier: uuidToBytes(MY_STORY_ID),
|
||||||
|
isBlockList: true,
|
||||||
|
name: MY_STORY_ID,
|
||||||
|
recipientServiceIds: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await phone.setStorageState(state);
|
||||||
|
|
||||||
|
app = await bootstrap.link();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async function (this: Mocha.Context) {
|
||||||
|
if (!bootstrap) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await bootstrap.maybeSaveLogs(this.currentTest, app);
|
||||||
|
if (app) {
|
||||||
|
await app.close();
|
||||||
|
}
|
||||||
|
await bootstrap.teardown();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should save created call links and restore on relink', async () => {
|
||||||
|
const { phone } = bootstrap;
|
||||||
|
|
||||||
|
let state;
|
||||||
|
|
||||||
|
const window = await app.getWindow();
|
||||||
|
state = await phone.expectStorageState('initial state');
|
||||||
|
|
||||||
|
debug('Creating call link');
|
||||||
|
const roomId = await createCallLink(window, { name: 'Fun link' });
|
||||||
|
assert.exists(roomId, 'Call link roomId should exist');
|
||||||
|
|
||||||
|
debug('Waiting for storage update');
|
||||||
|
state = await phone.waitForStorageState({ after: state });
|
||||||
|
|
||||||
|
const record = state.findRecord(getCallLinkRecordPredicate(roomId));
|
||||||
|
assert.ok(record, 'Saves call link record with matching roomId');
|
||||||
|
const deletedAt = Long.fromValue(
|
||||||
|
record.record.callLink?.deletedAtTimestampMs ?? 0
|
||||||
|
).toNumber();
|
||||||
|
assert.notOk(deletedAt, 'deletedAt falsey');
|
||||||
|
|
||||||
|
debug('Creating link then deleting it');
|
||||||
|
const roomIdDelete = await createCallLink(window, {
|
||||||
|
name: 'Link to delete',
|
||||||
|
});
|
||||||
|
assert.exists(roomIdDelete, 'Call link roomId should exist');
|
||||||
|
|
||||||
|
debug('Waiting for storage update');
|
||||||
|
state = await phone.waitForStorageState({ after: state });
|
||||||
|
|
||||||
|
const recordToDelete = state.findRecord(
|
||||||
|
getCallLinkRecordPredicate(roomIdDelete)
|
||||||
|
);
|
||||||
|
assert.ok(recordToDelete, 'Saves call link record with matching roomId');
|
||||||
|
|
||||||
|
const deletedAtBeforeDelete = Long.fromValue(
|
||||||
|
recordToDelete.record.callLink?.deletedAtTimestampMs ?? 0
|
||||||
|
).toNumber();
|
||||||
|
assert.notOk(deletedAtBeforeDelete, 'deletedAt falsey');
|
||||||
|
|
||||||
|
debug('Deleting call link');
|
||||||
|
const callLinkItem = await window.getByText('Link to delete');
|
||||||
|
await callLinkItem.click();
|
||||||
|
const callLinkDetails = await window.locator(
|
||||||
|
'.CallsTab__ConversationCallDetails'
|
||||||
|
);
|
||||||
|
await callLinkDetails.waitFor();
|
||||||
|
const deleteButton = await window.getByText('Delete link');
|
||||||
|
await deleteButton.click();
|
||||||
|
const confirmModal = await window.getByTestId(
|
||||||
|
'ConfirmationDialog.CallLinkDetails__DeleteLinkModal'
|
||||||
|
);
|
||||||
|
await confirmModal.waitFor();
|
||||||
|
const deleteConfirm = await window
|
||||||
|
.locator('.module-Button')
|
||||||
|
.getByText('Delete');
|
||||||
|
await deleteConfirm.click();
|
||||||
|
|
||||||
|
debug('Waiting for storage update');
|
||||||
|
state = await phone.waitForStorageState({ after: state });
|
||||||
|
|
||||||
|
const recordAfterDelete = state.findRecord(
|
||||||
|
getCallLinkRecordPredicate(roomIdDelete)
|
||||||
|
);
|
||||||
|
assert.ok(recordAfterDelete, 'Call link record still present');
|
||||||
|
const deletedAtAfterDelete = Long.fromValue(
|
||||||
|
recordAfterDelete.record.callLink?.deletedAtTimestampMs ?? 0
|
||||||
|
).toNumber();
|
||||||
|
assert.ok(deletedAtAfterDelete, 'deletedAt present');
|
||||||
|
});
|
||||||
|
});
|
|
@ -12,12 +12,14 @@ import { StorageState, Proto } from '@signalapp/mock-server';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs/promises';
|
import fs from 'fs/promises';
|
||||||
import { range } from 'lodash';
|
import { range } from 'lodash';
|
||||||
|
import { CallLinkRootKey } from '@signalapp/ringrtc';
|
||||||
import { App } from '../playwright';
|
import { App } from '../playwright';
|
||||||
import { Bootstrap } from '../bootstrap';
|
import { Bootstrap } from '../bootstrap';
|
||||||
import type { BootstrapOptions } from '../bootstrap';
|
import type { BootstrapOptions } from '../bootstrap';
|
||||||
import { MY_STORY_ID } from '../../types/Stories';
|
import { MY_STORY_ID } from '../../types/Stories';
|
||||||
import { uuidToBytes } from '../../util/uuidToBytes';
|
import { uuidToBytes } from '../../util/uuidToBytes';
|
||||||
import { artAddStickersRoute } from '../../util/signalRoutes';
|
import { artAddStickersRoute } from '../../util/signalRoutes';
|
||||||
|
import { getRoomIdFromRootKey } from '../../util/callLinksRingrtc';
|
||||||
|
|
||||||
export const debug = createDebug('mock:test:storage');
|
export const debug = createDebug('mock:test:storage');
|
||||||
|
|
||||||
|
@ -206,3 +208,17 @@ export async function storeStickerPacks(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getCallLinkRecordPredicate(
|
||||||
|
roomId: string
|
||||||
|
): (record: StorageStateRecord) => boolean {
|
||||||
|
return ({ type, record }: StorageStateRecord): boolean => {
|
||||||
|
const rootKeyBytes = record.callLink?.rootKey;
|
||||||
|
if (type !== IdentifierType.CALL_LINK || rootKeyBytes == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const recordRootKey = CallLinkRootKey.fromBytes(Buffer.from(rootKeyBytes));
|
||||||
|
const recordRoomId = getRoomIdFromRootKey(recordRootKey);
|
||||||
|
return roomId === recordRoomId;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue