mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-23 09:58:12 +01:00
Initial donationReceipts data types
This commit is contained in:
@@ -6,7 +6,6 @@ import { assert } from 'chai';
|
||||
import { sql } from '../../sql/util';
|
||||
import { createDB, explain, updateToVersion } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { DataWriter } from '../../sql/Server';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1360', () => {
|
||||
let db: WritableDB;
|
||||
@@ -14,7 +13,6 @@ describe('SQL/updateToSchemaVersion1360', () => {
|
||||
beforeEach(async () => {
|
||||
db = createDB();
|
||||
updateToVersion(db, 1360);
|
||||
await DataWriter.removeAll(db);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
71
ts/test-node/sql/migration_1380_test.ts
Normal file
71
ts/test-node/sql/migration_1380_test.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import { v1 as getGuid } from 'uuid';
|
||||
|
||||
import { sql } from '../../sql/util';
|
||||
import {
|
||||
updateToVersion,
|
||||
createDB,
|
||||
explain,
|
||||
insertData,
|
||||
getTableData,
|
||||
} from './helpers';
|
||||
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1380', () => {
|
||||
let db: WritableDB;
|
||||
beforeEach(() => {
|
||||
db = createDB();
|
||||
updateToVersion(db, 1380);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
});
|
||||
|
||||
it('creates new donationReceipts table', () => {
|
||||
const [query] = sql`SELECT * FROM donationReceipts`;
|
||||
db.prepare(query).run();
|
||||
});
|
||||
|
||||
it('throws if same id is used for an insert', () => {
|
||||
// Note: this kinda looks like a receipt, but the json field is weird because
|
||||
// insertData and getTableData both have special handling for JSON fields.
|
||||
const receipt = {
|
||||
id: getGuid(),
|
||||
currencyType: 'USD',
|
||||
paymentAmount: 500, // $5.00
|
||||
paymentType: 'CARD',
|
||||
paymentDetailJson: {
|
||||
lastFourDigits: '1111',
|
||||
},
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
|
||||
insertData(db, 'donationReceipts', [receipt]);
|
||||
|
||||
assert.deepStrictEqual(getTableData(db, 'donationReceipts'), [receipt]);
|
||||
|
||||
assert.throws(
|
||||
() => insertData(db, 'donationReceipts', [receipt]),
|
||||
/UNIQUE constraint/
|
||||
);
|
||||
});
|
||||
|
||||
it('creates an index to make order by timestamp efficient', () => {
|
||||
const template = sql`
|
||||
SELECT * FROM donationReceipts
|
||||
ORDER BY timestamp DESC
|
||||
LIMIT 5
|
||||
`;
|
||||
|
||||
const details = explain(db, template);
|
||||
assert.include(details, 'USING INDEX donationReceipts_byTimestamp');
|
||||
assert.notInclude(details, 'TEMP B-TREE');
|
||||
// TODO: are we actually okay with a SCAN?
|
||||
// assert.notInclude(details, 'SCAN');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user