Introduce Service Id Types
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
414c0a58d3
commit
366b875fd2
269 changed files with 5832 additions and 5550 deletions
|
@ -2,10 +2,11 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { v4 as generateUuid } from 'uuid';
|
||||
|
||||
import dataInterface from '../../sql/Client';
|
||||
import { UUID } from '../../types/UUID';
|
||||
import type { UUIDStringType } from '../../types/UUID';
|
||||
import { generateAci } from '../../types/ServiceId';
|
||||
import { generateStoryDistributionId } from '../../types/StoryDistributionId';
|
||||
|
||||
import type { StoryDistributionWithMembersType } from '../../sql/Interface';
|
||||
|
||||
|
@ -21,10 +22,6 @@ const {
|
|||
modifyStoryDistributionWithMembers,
|
||||
} = dataInterface;
|
||||
|
||||
function getUuid(): UUIDStringType {
|
||||
return UUID.generate().toString();
|
||||
}
|
||||
|
||||
describe('sql/storyDistribution', () => {
|
||||
beforeEach(async () => {
|
||||
await _deleteAllStoryDistributions();
|
||||
|
@ -32,17 +29,17 @@ describe('sql/storyDistribution', () => {
|
|||
|
||||
it('roundtrips with create/fetch/delete', async () => {
|
||||
const list: StoryDistributionWithMembersType = {
|
||||
id: getUuid(),
|
||||
id: generateStoryDistributionId(),
|
||||
name: 'My Story',
|
||||
allowsReplies: true,
|
||||
isBlockList: false,
|
||||
members: [getUuid(), getUuid()],
|
||||
members: [generateAci(), generateAci()],
|
||||
senderKeyInfo: {
|
||||
createdAtDate: Date.now(),
|
||||
distributionId: getUuid(),
|
||||
distributionId: generateUuid(),
|
||||
memberDevices: [],
|
||||
},
|
||||
storageID: getUuid(),
|
||||
storageID: generateUuid(),
|
||||
storageVersion: 1,
|
||||
storageNeedsSync: false,
|
||||
storageUnknownFields: undefined,
|
||||
|
@ -66,20 +63,20 @@ describe('sql/storyDistribution', () => {
|
|||
});
|
||||
|
||||
it('updates core fields with modifyStoryDistribution', async () => {
|
||||
const UUID_1 = getUuid();
|
||||
const UUID_2 = getUuid();
|
||||
const SERVICE_ID_1 = generateAci();
|
||||
const SERVICE_ID_2 = generateAci();
|
||||
const list: StoryDistributionWithMembersType = {
|
||||
id: getUuid(),
|
||||
id: generateStoryDistributionId(),
|
||||
name: 'My Story',
|
||||
allowsReplies: true,
|
||||
isBlockList: false,
|
||||
members: [UUID_1, UUID_2],
|
||||
members: [SERVICE_ID_1, SERVICE_ID_2],
|
||||
senderKeyInfo: {
|
||||
createdAtDate: Date.now(),
|
||||
distributionId: getUuid(),
|
||||
distributionId: generateUuid(),
|
||||
memberDevices: [],
|
||||
},
|
||||
storageID: getUuid(),
|
||||
storageID: generateUuid(),
|
||||
storageVersion: 1,
|
||||
storageNeedsSync: false,
|
||||
storageUnknownFields: undefined,
|
||||
|
@ -96,11 +93,11 @@ describe('sql/storyDistribution', () => {
|
|||
name: 'Updated story',
|
||||
senderKeyInfo: {
|
||||
createdAtDate: Date.now() + 10,
|
||||
distributionId: getUuid(),
|
||||
distributionId: generateUuid(),
|
||||
memberDevices: [
|
||||
{
|
||||
id: 1,
|
||||
identifier: UUID_1,
|
||||
identifier: SERVICE_ID_1,
|
||||
registrationId: 232,
|
||||
},
|
||||
],
|
||||
|
@ -118,22 +115,22 @@ describe('sql/storyDistribution', () => {
|
|||
});
|
||||
|
||||
it('adds and removes with modifyStoryDistributionMembers', async () => {
|
||||
const UUID_1 = getUuid();
|
||||
const UUID_2 = getUuid();
|
||||
const UUID_3 = getUuid();
|
||||
const UUID_4 = getUuid();
|
||||
const SERVICE_ID_1 = generateAci();
|
||||
const SERVICE_ID_2 = generateAci();
|
||||
const SERVICE_ID_3 = generateAci();
|
||||
const SERVICE_ID_4 = generateAci();
|
||||
const list: StoryDistributionWithMembersType = {
|
||||
id: getUuid(),
|
||||
id: generateStoryDistributionId(),
|
||||
name: 'My Story',
|
||||
allowsReplies: true,
|
||||
isBlockList: false,
|
||||
members: [UUID_1, UUID_2],
|
||||
members: [SERVICE_ID_1, SERVICE_ID_2],
|
||||
senderKeyInfo: {
|
||||
createdAtDate: Date.now(),
|
||||
distributionId: getUuid(),
|
||||
distributionId: generateUuid(),
|
||||
memberDevices: [],
|
||||
},
|
||||
storageID: getUuid(),
|
||||
storageID: generateUuid(),
|
||||
storageVersion: 1,
|
||||
storageNeedsSync: false,
|
||||
storageUnknownFields: undefined,
|
||||
|
@ -146,8 +143,8 @@ describe('sql/storyDistribution', () => {
|
|||
assert.lengthOf(await _getAllStoryDistributionMembers(), 2);
|
||||
|
||||
await modifyStoryDistributionMembers(list.id, {
|
||||
toAdd: [UUID_3, UUID_4],
|
||||
toRemove: [UUID_1],
|
||||
toAdd: [SERVICE_ID_3, SERVICE_ID_4],
|
||||
toRemove: [SERVICE_ID_1],
|
||||
});
|
||||
|
||||
assert.lengthOf(await _getAllStoryDistributions(), 1);
|
||||
|
@ -157,27 +154,27 @@ describe('sql/storyDistribution', () => {
|
|||
assert.lengthOf(allHydratedLists, 1);
|
||||
assert.deepEqual(allHydratedLists[0], {
|
||||
...list,
|
||||
members: [UUID_2, UUID_3, UUID_4],
|
||||
members: [SERVICE_ID_2, SERVICE_ID_3, SERVICE_ID_4],
|
||||
});
|
||||
});
|
||||
|
||||
it('adds and removes with modifyStoryDistributionWithMembers', async () => {
|
||||
const UUID_1 = getUuid();
|
||||
const UUID_2 = getUuid();
|
||||
const UUID_3 = getUuid();
|
||||
const UUID_4 = getUuid();
|
||||
const SERVICE_ID_1 = generateAci();
|
||||
const SERVICE_ID_2 = generateAci();
|
||||
const SERVICE_ID_3 = generateAci();
|
||||
const SERVICE_ID_4 = generateAci();
|
||||
const list: StoryDistributionWithMembersType = {
|
||||
id: getUuid(),
|
||||
id: generateStoryDistributionId(),
|
||||
name: 'My Story',
|
||||
allowsReplies: true,
|
||||
isBlockList: false,
|
||||
members: [UUID_1, UUID_2],
|
||||
members: [SERVICE_ID_1, SERVICE_ID_2],
|
||||
senderKeyInfo: {
|
||||
createdAtDate: Date.now(),
|
||||
distributionId: getUuid(),
|
||||
distributionId: generateUuid(),
|
||||
memberDevices: [],
|
||||
},
|
||||
storageID: getUuid(),
|
||||
storageID: generateUuid(),
|
||||
storageVersion: 1,
|
||||
storageNeedsSync: false,
|
||||
storageUnknownFields: undefined,
|
||||
|
@ -190,8 +187,8 @@ describe('sql/storyDistribution', () => {
|
|||
assert.lengthOf(await _getAllStoryDistributionMembers(), 2);
|
||||
|
||||
await modifyStoryDistributionWithMembers(list, {
|
||||
toAdd: [UUID_3, UUID_4],
|
||||
toRemove: [UUID_1],
|
||||
toAdd: [SERVICE_ID_3, SERVICE_ID_4],
|
||||
toRemove: [SERVICE_ID_1],
|
||||
});
|
||||
|
||||
assert.lengthOf(await _getAllStoryDistributions(), 1);
|
||||
|
@ -201,25 +198,25 @@ describe('sql/storyDistribution', () => {
|
|||
assert.lengthOf(allHydratedLists, 1);
|
||||
assert.deepEqual(allHydratedLists[0], {
|
||||
...list,
|
||||
members: [UUID_2, UUID_3, UUID_4],
|
||||
members: [SERVICE_ID_2, SERVICE_ID_3, SERVICE_ID_4],
|
||||
});
|
||||
});
|
||||
|
||||
it('eliminates duplicates without complaint in createNewStoryDistribution', async () => {
|
||||
const UUID_1 = getUuid();
|
||||
const UUID_2 = getUuid();
|
||||
const SERVICE_ID_1 = generateAci();
|
||||
const SERVICE_ID_2 = generateAci();
|
||||
const list: StoryDistributionWithMembersType = {
|
||||
id: getUuid(),
|
||||
id: generateStoryDistributionId(),
|
||||
name: 'My Story',
|
||||
allowsReplies: true,
|
||||
isBlockList: false,
|
||||
members: [UUID_1, UUID_1, UUID_2],
|
||||
members: [SERVICE_ID_1, SERVICE_ID_1, SERVICE_ID_2],
|
||||
senderKeyInfo: {
|
||||
createdAtDate: Date.now(),
|
||||
distributionId: getUuid(),
|
||||
distributionId: generateUuid(),
|
||||
memberDevices: [],
|
||||
},
|
||||
storageID: getUuid(),
|
||||
storageID: generateUuid(),
|
||||
storageVersion: 1,
|
||||
storageNeedsSync: false,
|
||||
storageUnknownFields: undefined,
|
||||
|
@ -233,6 +230,6 @@ describe('sql/storyDistribution', () => {
|
|||
|
||||
const allHydratedLists = await getAllStoryDistributionsWithMembers();
|
||||
assert.lengthOf(allHydratedLists, 1);
|
||||
assert.deepEqual(allHydratedLists[0].members, [UUID_1, UUID_2]);
|
||||
assert.deepEqual(allHydratedLists[0].members, [SERVICE_ID_1, SERVICE_ID_2]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue