Convert ConversationModel tests to TypeScript

This commit is contained in:
Evan Hahn 2021-07-02 15:40:36 -05:00 committed by GitHub
parent 3dd850b9b8
commit 4cd3da8f5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 45 deletions

View file

@ -408,8 +408,6 @@
<script type="text/javascript" src="views/whisper_view_test.js"></script>
<script type="text/javascript" src="views/list_view_test.js"></script>
<script type="text/javascript" src="models/conversations_test.js"></script>
<script type="text/javascript" src="libphonenumber_util_test.js"></script>
<script type="text/javascript" src="keychange_listener_test.js"></script>
<script type="text/javascript" src="reliable_trigger_test.js"></script>

View file

@ -1,4 +1,4 @@
// Copyright 2017-2020 Signal Messenger, LLC
// Copyright 2017-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
/* global ConversationController, SignalProtocolStore, Whisper */
@ -10,37 +10,38 @@ describe('KeyChangeListener', () => {
const newKey = window.Signal.Crypto.getRandomBytes(33);
let store;
let convo;
beforeEach(async () => {
window.ConversationController.reset();
await window.ConversationController.load();
await window.ConversationController.loadPromise();
convo = window.ConversationController.dangerouslyCreateAndAdd({
id: phoneNumberWithKeyChange,
type: 'private',
});
await window.Signal.Data.saveConversation(convo.attributes);
store = new SignalProtocolStore();
await store.hydrateCaches();
Whisper.KeyChangeListener.init(store);
return store.saveIdentity(addressString, oldKey);
});
afterEach(() => {
return store.removeIdentityKey(phoneNumberWithKeyChange);
afterEach(async () => {
await window.Signal.Data.removeAllMessagesInConversation(convo.id, {
logId: phoneNumberWithKeyChange,
MessageCollection: Whisper.MessageCollection,
});
await window.Signal.Data.removeConversation(convo.id, {
Conversation: Whisper.Conversation,
});
await store.removeIdentityKey(phoneNumberWithKeyChange);
});
describe('When we have a conversation with this contact', () => {
let convo;
before(async () => {
convo = ConversationController.dangerouslyCreateAndAdd({
id: phoneNumberWithKeyChange,
type: 'private',
});
await window.Signal.Data.saveConversation(convo.attributes);
});
after(async () => {
await window.Signal.Data.removeAllMessagesInConversation(convo.id, {
logId: phoneNumberWithKeyChange,
MessageCollection: Whisper.MessageCollection,
});
await window.Signal.Data.removeConversation(convo.id, {
Conversation: Whisper.Conversation,
});
});
it('generates a key change notice in the private conversation with this contact', done => {
const original = convo.addKeyChange;
convo.addKeyChange = keyChangedId => {
@ -54,21 +55,17 @@ describe('KeyChangeListener', () => {
describe('When we have a group with this contact', () => {
let groupConvo;
let convo;
before(async () => {
convo = ConversationController.dangerouslyCreateAndAdd({
id: phoneNumberWithKeyChange,
type: 'private',
});
beforeEach(async () => {
groupConvo = ConversationController.dangerouslyCreateAndAdd({
id: 'groupId',
type: 'group',
members: [convo.id],
});
await window.Signal.Data.saveConversation(convo.attributes);
await window.Signal.Data.saveConversation(groupConvo.attributes);
});
after(async () => {
afterEach(async () => {
await window.Signal.Data.removeAllMessagesInConversation(groupConvo.id, {
logId: phoneNumberWithKeyChange,
MessageCollection: Whisper.MessageCollection,
@ -76,9 +73,6 @@ describe('KeyChangeListener', () => {
await window.Signal.Data.removeConversation(groupConvo.id, {
Conversation: Whisper.Conversation,
});
await window.Signal.Data.removeConversation(convo.id, {
Conversation: Whisper.Conversation,
});
});
it('generates a key change notice in the group conversation with this contact', done => {

View file

@ -1,83 +0,0 @@
// Copyright 2014-2020 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
describe('Conversations', () => {
it('updates lastMessage even in race conditions with db', async () => {
const ourNumber = '+15550000000';
const ourUuid = window.getGuid();
// Creating a fake conversation
const conversation = new window.Whisper.Conversation({
id: '8c45efca-67a4-4026-b990-9537d5d1a08f',
e164: '+15551234567',
uuid: '2f2734aa-f69d-4c1c-98eb-50eb0fc512d7',
type: 'private',
});
const destinationE164 = '+15557654321';
window.textsecure.storage.user.setNumberAndDeviceId(
ourNumber,
2,
'my device'
);
window.textsecure.storage.user.setUuidAndDeviceId(ourUuid, 2);
window.ConversationController._initialFetchComplete = true;
// Creating a fake message
const now = Date.now();
let message = new window.Whisper.Message({
attachments: [],
body: 'bananas',
conversationId: conversation.id,
delivered: 1,
delivered_to: [destinationE164],
destination: destinationE164,
expirationStartTimestamp: now,
hasAttachments: 0,
hasFileAttachments: 0,
hasVisualMediaAttachments: 0,
id: 'd8f2b435-e2ef-46e0-8481-07e68af251c6',
received_at: now,
recipients: [destinationE164],
sent: true,
sent_at: now,
sent_to: [destinationE164],
timestamp: now,
type: 'outgoing',
});
// Saving to db and updating the convo's last message
await window.Signal.Data.saveMessage(message.attributes, {
forceSave: true,
Message: window.Whisper.Message,
});
message = window.MessageController.register(message.id, message);
await window.Signal.Data.saveConversation(conversation.attributes, {
Conversation: window.Whisper.Conversation,
});
await conversation.updateLastMessage();
// Should be set to bananas because that's the last message sent.
assert.strictEqual(conversation.get('lastMessage'), 'bananas');
// Erasing message contents (DOE)
message.set({
isErased: true,
body: '',
bodyRanges: undefined,
attachments: [],
quote: null,
contact: [],
sticker: null,
preview: [],
});
// Not saving the message to db on purpose
// to simulate that a save hasn't taken place yet.
// Updating convo's last message, should pick it up from memory
await conversation.updateLastMessage();
assert.strictEqual(conversation.get('lastMessage'), '');
});
});