| 1 | import assert from "node:assert/strict"; |
| 2 | import { DatabaseSync } from "node:sqlite"; |
| 3 | import test from "node:test"; |
| 4 | |
| 5 | import { MIGRATIONS } from "./schema.ts"; |
| 6 | |
| 7 | test("an error group linked to an issue keeps its old number when issues become work items", () => { |
| 8 | const db = new DatabaseSync(":memory:"); |
| 9 | for (const step of MIGRATIONS.slice(0, -2)) db.exec(step); |
| 10 | db.exec( |
| 11 | `INSERT INTO error_groups (fingerprint, name, message, service, first_us, last_us, issue_number) |
| 12 | VALUES ('fp_1', 'TypeError', 'boom', 'web', 1, 2, 7), ('fp_2', 'TypeError', 'bang', 'web', 1, 2, NULL)`, |
| 13 | ); |
| 14 | for (const step of MIGRATIONS.slice(-2)) db.exec(step); |
| 15 | const rows = db.prepare("SELECT fingerprint, item, legacy_number FROM error_groups ORDER BY fingerprint").all(); |
| 16 | assert.deepEqual( |
| 17 | rows.map((row) => ({ ...row })), |
| 18 | [ |
| 19 | { fingerprint: "fp_1", item: null, legacy_number: 7 }, |
| 20 | { fingerprint: "fp_2", item: null, legacy_number: null }, |
| 21 | ], |
| 22 | ); |
| 23 | }); |
| 24 | |
| 25 | test("an error group's old number moves to legacy_number", () => { |
| 26 | const db = new DatabaseSync(":memory:"); |
| 27 | for (const step of MIGRATIONS.slice(0, -1)) db.exec(step); |
| 28 | db.exec( |
| 29 | `INSERT INTO error_groups (fingerprint, name, message, service, first_us, last_us, item, legacy_issue) |
| 30 | VALUES ('fp_1', 'TypeError', 'boom', 'web', 1, 2, NULL, 7), ('fp_2', 'TypeError', 'bang', 'web', 1, 2, 3, NULL)`, |
| 31 | ); |
| 32 | db.exec(MIGRATIONS.at(-1)!); |
| 33 | const rows = db.prepare("SELECT fingerprint, item, legacy_number FROM error_groups ORDER BY fingerprint").all(); |
| 34 | assert.deepEqual( |
| 35 | rows.map((row) => ({ ...row })), |
| 36 | [ |
| 37 | { fingerprint: "fp_1", item: null, legacy_number: 7 }, |
| 38 | { fingerprint: "fp_2", item: 3, legacy_number: null }, |
| 39 | ], |
| 40 | ); |
| 41 | }); |