diff --git a/ts/test-both/util/retryPlaceholders_test.ts b/ts/test-both/util/retryPlaceholders_test.ts index d8b074aeac..3e2f764d68 100644 --- a/ts/test-both/util/retryPlaceholders_test.ts +++ b/ts/test-both/util/retryPlaceholders_test.ts @@ -26,7 +26,8 @@ describe('RetryPlaceholders', () => { }); }); - afterEach(() => { + afterEach(async () => { + await window.storage.remove(STORAGE_KEY); clock.restore(); }); diff --git a/ts/test-electron/MessageReceipts_test.ts b/ts/test-electron/MessageReceipts_test.ts index d518ebcc5b..0be5690311 100644 --- a/ts/test-electron/MessageReceipts_test.ts +++ b/ts/test-electron/MessageReceipts_test.ts @@ -28,6 +28,11 @@ describe('MessageReceipts', () => { await window.ConversationController.load(); }); + afterEach(async () => { + await DataWriter.removeAll(); + await window.storage.fetch(); + }); + function generateReceipt( sourceConversationId: string, messageSentAt: number, diff --git a/ts/test-electron/SignalProtocolStore_test.ts b/ts/test-electron/SignalProtocolStore_test.ts index 11fa7ec6cc..344a75c3f3 100644 --- a/ts/test-electron/SignalProtocolStore_test.ts +++ b/ts/test-electron/SignalProtocolStore_test.ts @@ -170,6 +170,11 @@ describe('SignalProtocolStore', () => { await window.ConversationController.getOrCreateAndWait(theirAci, 'private'); }); + after(async () => { + await DataWriter.removeAll(); + await window.storage.fetch(); + }); + describe('getLocalRegistrationId', () => { it('retrieves my registration id', async () => { await store.hydrateCaches(); diff --git a/ts/test-electron/background_test.ts b/ts/test-electron/background_test.ts index 79072a798a..2f25ff2127 100644 --- a/ts/test-electron/background_test.ts +++ b/ts/test-electron/background_test.ts @@ -5,6 +5,7 @@ import { assert } from 'chai'; import { pick } from 'lodash'; import { isOverHourIntoPast, cleanupSessionResets } from '../background'; +import { DataWriter } from '../sql/Client'; describe('#isOverHourIntoPast', () => { it('returns false for now', () => { @@ -21,6 +22,11 @@ describe('#isOverHourIntoPast', () => { }); describe('#cleanupSessionResets', () => { + after(async () => { + await DataWriter.removeAll(); + await window.storage.fetch(); + }); + it('leaves empty object alone', async () => { await window.storage.put('sessionResets', {}); await cleanupSessionResets(); diff --git a/ts/test-electron/backup/filePointer_test.ts b/ts/test-electron/backup/filePointer_test.ts index e0ba7a509f..9b666534d0 100644 --- a/ts/test-electron/backup/filePointer_test.ts +++ b/ts/test-electron/backup/filePointer_test.ts @@ -642,6 +642,7 @@ describe('getBackupJobForAttachmentAndFilePointer', async () => { }); afterEach(async () => { await DataWriter.removeAll(); + await window.storage.fetch(); }); const attachment = composeAttachment(); diff --git a/ts/test-electron/models/messages_test.ts b/ts/test-electron/models/messages_test.ts index 066d72d708..d4a394623e 100644 --- a/ts/test-electron/models/messages_test.ts +++ b/ts/test-electron/models/messages_test.ts @@ -11,7 +11,6 @@ import type { ConversationModel } from '../../models/conversations'; import type { MessageAttributesType } from '../../model-types.d'; import { MessageModel } from '../../models/messages'; import type { RawBodyRange } from '../../types/BodyRange'; -import type { StorageAccessType } from '../../types/Storage.d'; import type { WebAPIType } from '../../textsecure/WebAPI'; import { DataWriter } from '../../sql/Client'; import MessageSender from '../../textsecure/SendMessage'; @@ -35,13 +34,6 @@ import { getNotificationTextForMessage } from '../../util/getNotificationTextFor import { send } from '../../messages/send'; describe('Message', () => { - const STORAGE_KEYS_TO_RESTORE: Array = [ - 'number_id', - 'uuid_id', - ]; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const oldStorageValues = new Map(); - const i18n = setupI18n('en', enMessages); const attributes = { @@ -80,9 +72,6 @@ describe('Message', () => { window.ConversationController.reset(); await window.ConversationController.load(); - STORAGE_KEYS_TO_RESTORE.forEach(key => { - oldStorageValues.set(key, window.textsecure.storage.get(key)); - }); await window.textsecure.storage.put('number_id', `${me}.2`); await window.textsecure.storage.put('uuid_id', `${ourServiceId}.2`); }); @@ -90,15 +79,6 @@ describe('Message', () => { after(async () => { await DataWriter.removeAll(); await window.storage.fetch(); - - await Promise.all( - Array.from(oldStorageValues.entries()).map(([key, oldValue]) => { - if (oldValue) { - return window.textsecure.storage.put(key, oldValue); - } - return window.textsecure.storage.remove(key); - }) - ); }); beforeEach(function (this: Mocha.Context) { diff --git a/ts/test-electron/services/AttachmentBackupManager_test.ts b/ts/test-electron/services/AttachmentBackupManager_test.ts index dc71c26d7b..0314d41633 100644 --- a/ts/test-electron/services/AttachmentBackupManager_test.ts +++ b/ts/test-electron/services/AttachmentBackupManager_test.ts @@ -168,6 +168,8 @@ describe('AttachmentBackupManager/JobManager', function attachmentBackupManager( afterEach(async () => { sandbox.restore(); await backupManager?.stop(); + await DataWriter.removeAll(); + await window.storage.fetch(); }); async function addJobs( diff --git a/ts/test-electron/services/AttachmentDownloadManager_test.ts b/ts/test-electron/services/AttachmentDownloadManager_test.ts index 21d6571d53..9cffdb2441 100644 --- a/ts/test-electron/services/AttachmentDownloadManager_test.ts +++ b/ts/test-electron/services/AttachmentDownloadManager_test.ts @@ -121,6 +121,8 @@ describe('AttachmentDownloadManager/JobManager', () => { afterEach(async () => { await downloadManager?.stop(); sandbox.restore(); + await DataWriter.removeAll(); + await window.storage.fetch(); }); async function addJob( diff --git a/ts/test-electron/services/MessageCache_test.ts b/ts/test-electron/services/MessageCache_test.ts index 1e26cf56ad..2f09138fcd 100644 --- a/ts/test-electron/services/MessageCache_test.ts +++ b/ts/test-electron/services/MessageCache_test.ts @@ -8,6 +8,7 @@ import { strictAssert } from '../../util/assert'; import { MessageCache } from '../../services/MessageCache'; import { generateAci } from '../../types/ServiceId'; +import { DataWriter } from '../../sql/Client'; describe('MessageCache', () => { beforeEach(async () => { @@ -16,6 +17,11 @@ describe('MessageCache', () => { await window.ConversationController.load(); }); + afterEach(async () => { + await DataWriter.removeAll(); + await window.storage.fetch(); + }); + describe('findBySentAt', () => { it('returns an empty iterable if no messages match', async () => { const mc = new MessageCache(); diff --git a/ts/test-electron/state/ducks/stories_test.ts b/ts/test-electron/state/ducks/stories_test.ts index 0d176f17b6..95d31460bc 100644 --- a/ts/test-electron/state/ducks/stories_test.ts +++ b/ts/test-electron/state/ducks/stories_test.ts @@ -27,6 +27,7 @@ import { noopAction } from '../../../state/ducks/noop'; import { reducer as rootReducer } from '../../../state/reducer'; import { dropNull } from '../../../util/dropNull'; import { MessageModel } from '../../../models/messages'; +import { DataWriter } from '../../../sql/Client'; describe('both/state/ducks/stories', () => { const ourAci = generateAci(); @@ -36,6 +37,11 @@ describe('both/state/ducks/stories', () => { await window.textsecure.storage.put('uuid_id', `${ourAci}.${deviceId}`); }); + after(async () => { + await DataWriter.removeAll(); + await window.storage.fetch(); + }); + const getEmptyRootState = () => ({ ...rootReducer(undefined, noopAction()), stories: getEmptyState(), diff --git a/ts/test-electron/textsecure/generate_keys_test.ts b/ts/test-electron/textsecure/generate_keys_test.ts index ba43b42455..5e5ca33155 100644 --- a/ts/test-electron/textsecure/generate_keys_test.ts +++ b/ts/test-electron/textsecure/generate_keys_test.ts @@ -9,6 +9,7 @@ import type { UploadKeysType, UploadPreKeyType } from '../../textsecure/WebAPI'; import AccountManager from '../../textsecure/AccountManager'; import { ServiceIdKind } from '../../types/ServiceId'; import { normalizeAci } from '../../util/normalizeAci'; +import { DataWriter } from '../../sql/Client'; const { textsecure } = window; @@ -81,6 +82,9 @@ describe('Key generation', function (this: Mocha.Suite) { await textsecure.storage.protocol.clearPreKeyStore(); await textsecure.storage.protocol.clearKyberPreKeyStore(); await textsecure.storage.protocol.clearSignedPreKeysStore(); + + await DataWriter.removeAll(); + await window.storage.fetch(); }); describe('the first time', () => { diff --git a/ts/test-electron/util/migrateMessageData_test.ts b/ts/test-electron/util/migrateMessageData_test.ts index f1165f7032..2b3e9cc47e 100644 --- a/ts/test-electron/util/migrateMessageData_test.ts +++ b/ts/test-electron/util/migrateMessageData_test.ts @@ -29,6 +29,7 @@ describe('utils/migrateMessageData', async () => { }); after(async () => { await DataWriter.removeAll(); + await window.storage.fetch(); }); it('increments attempts for messages which fail to save', async () => { const messages = new Array(5)