Introduce Service Id Types

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
Fedor Indutny 2023-08-10 18:43:33 +02:00 committed by Jamie Kyle
parent 414c0a58d3
commit 366b875fd2
269 changed files with 5832 additions and 5550 deletions

View file

@ -2,20 +2,16 @@
// 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 type { MessageAttributesType } from '../../model-types.d';
const { removeAll, _getAllMessages, saveMessages, getAllStories } =
dataInterface;
function getUuid(): UUIDStringType {
return UUID.generate().toString();
}
describe('sql/stories', () => {
beforeEach(async () => {
await removeAll();
@ -26,55 +22,55 @@ describe('sql/stories', () => {
assert.lengthOf(await _getAllMessages(), 0);
const now = Date.now();
const conversationId = getUuid();
const sourceUuid = getUuid();
const ourUuid = getUuid();
const conversationId = generateUuid();
const sourceUuid = generateAci();
const ourAci = generateAci();
const story1: MessageAttributesType = {
id: getUuid(),
id: generateUuid(),
body: 'story 1',
type: 'story',
conversationId,
sent_at: now - 20,
received_at: now - 20,
timestamp: now - 20,
sourceUuid: getUuid(),
sourceUuid: generateAci(),
};
const story2: MessageAttributesType = {
id: getUuid(),
id: generateUuid(),
body: 'story 2',
type: 'story',
conversationId: getUuid(),
conversationId: generateUuid(),
sent_at: now - 10,
received_at: now - 10,
timestamp: now - 10,
sourceUuid,
};
const story3: MessageAttributesType = {
id: getUuid(),
id: generateUuid(),
body: 'message 3',
type: 'incoming',
conversationId: getUuid(),
conversationId: generateUuid(),
sent_at: now,
received_at: now,
timestamp: now,
sourceUuid,
};
const story4: MessageAttributesType = {
id: getUuid(),
id: generateUuid(),
body: 'story 4',
type: 'story',
conversationId,
sent_at: now,
received_at: now,
timestamp: now,
sourceUuid: getUuid(),
sourceUuid: generateAci(),
};
const story5: MessageAttributesType = {
id: getUuid(),
id: generateUuid(),
body: 'story 5',
type: 'story',
conversationId: getUuid(),
conversationId: generateUuid(),
sent_at: now,
received_at: now,
timestamp: now,
@ -83,7 +79,7 @@ describe('sql/stories', () => {
await saveMessages([story1, story2, story3, story4, story5], {
forceSave: true,
ourUuid,
ourAci,
});
assert.lengthOf(await _getAllMessages(), 5);