Introduce incrementMessagesMigrationAttempts query
Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
parent
7db33a6708
commit
67252866cf
5 changed files with 113 additions and 14 deletions
74
ts/test-node/sql/incrementMessagesMigrationAttempts_test.ts
Normal file
74
ts/test-node/sql/incrementMessagesMigrationAttempts_test.ts
Normal file
|
@ -0,0 +1,74 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import {
|
||||
incrementMessagesMigrationAttempts,
|
||||
setupTests,
|
||||
} from '../../sql/Server';
|
||||
import { createDB, insertData, getTableData } from './helpers';
|
||||
|
||||
describe('SQL/incrementMessagesMigrationAttempts', () => {
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createDB();
|
||||
setupTests(db);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
});
|
||||
|
||||
function compactify(
|
||||
message: Record<string, unknown>
|
||||
): Record<string, unknown> {
|
||||
const { id, conversationId, json } = message;
|
||||
|
||||
return {
|
||||
id,
|
||||
conversationId,
|
||||
json,
|
||||
};
|
||||
}
|
||||
|
||||
it('should increment attempts for corrupted messages', () => {
|
||||
insertData(db, 'messages', [
|
||||
{
|
||||
id: 'id',
|
||||
conversationId: 'other',
|
||||
json: {
|
||||
sent_at: { low: 0, high: 0 },
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
incrementMessagesMigrationAttempts(db, ['id']);
|
||||
|
||||
assert.deepStrictEqual(getTableData(db, 'messages').map(compactify), [
|
||||
{
|
||||
id: 'id',
|
||||
conversationId: 'other',
|
||||
json: {
|
||||
schemaMigrationAttempts: 1,
|
||||
sent_at: { low: 0, high: 0 },
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
incrementMessagesMigrationAttempts(db, ['id']);
|
||||
|
||||
assert.deepStrictEqual(getTableData(db, 'messages').map(compactify), [
|
||||
{
|
||||
id: 'id',
|
||||
conversationId: 'other',
|
||||
json: {
|
||||
schemaMigrationAttempts: 2,
|
||||
sent_at: { low: 0, high: 0 },
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue