2023-03-17 20:38:57 +00:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { v4 as generateUuid } from 'uuid';
|
2023-03-17 20:38:57 +00:00
|
|
|
|
2024-07-22 18:16:33 +00:00
|
|
|
import { DataReader, DataWriter } from '../../sql/Client';
|
2023-08-10 16:43:33 +00:00
|
|
|
import { generateAci } from '../../types/ServiceId';
|
2023-03-17 20:38:57 +00:00
|
|
|
|
|
|
|
import type { MessageAttributesType } from '../../model-types.d';
|
|
|
|
|
2024-07-22 18:16:33 +00:00
|
|
|
const { _getAllMessages, getCallHistoryMessageByCallId } = DataReader;
|
|
|
|
const { removeAll, saveMessages } = DataWriter;
|
2023-03-17 20:38:57 +00:00
|
|
|
|
|
|
|
describe('sql/getCallHistoryMessageByCallId', () => {
|
|
|
|
beforeEach(async () => {
|
|
|
|
await removeAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns a previous call history message', async () => {
|
|
|
|
assert.lengthOf(await _getAllMessages(), 0);
|
|
|
|
|
|
|
|
const now = Date.now();
|
2023-08-10 16:43:33 +00:00
|
|
|
const conversationId = generateUuid();
|
|
|
|
const ourAci = generateAci();
|
2023-03-17 20:38:57 +00:00
|
|
|
|
|
|
|
const callHistoryMessage: MessageAttributesType = {
|
2023-08-10 16:43:33 +00:00
|
|
|
id: generateUuid(),
|
2023-03-17 20:38:57 +00:00
|
|
|
type: 'call-history',
|
|
|
|
conversationId,
|
|
|
|
sent_at: now - 10,
|
|
|
|
received_at: now - 10,
|
|
|
|
timestamp: now - 10,
|
2023-08-09 00:53:06 +00:00
|
|
|
callId: '12345',
|
2023-03-17 20:38:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
await saveMessages([callHistoryMessage], {
|
|
|
|
forceSave: true,
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2023-03-17 20:38:57 +00:00
|
|
|
});
|
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
const allMessages = await _getAllMessages();
|
|
|
|
assert.lengthOf(allMessages, 1);
|
2023-03-17 20:38:57 +00:00
|
|
|
|
2023-08-09 00:53:06 +00:00
|
|
|
const message = await getCallHistoryMessageByCallId({
|
2023-03-17 20:38:57 +00:00
|
|
|
conversationId,
|
2023-08-09 00:53:06 +00:00
|
|
|
callId: '12345',
|
|
|
|
});
|
|
|
|
assert.strictEqual(message?.id, callHistoryMessage.id);
|
2023-03-17 20:38:57 +00:00
|
|
|
});
|
|
|
|
});
|