// Generated, do not edit. sha256:ba6482c6f8221f445c935cfd65e76c09e943da662ff5dab04e50d8a76e004316 import { describe, it, beforeEach, mock } from 'node:test'; import { toSearchName } from '../../shared/search-name.js'; import assert from 'node:assert/strict'; import { createDbHarness } from '../helpers/db-node.mjs'; import { ACCOUNT_SOURCE_KINDS } from '../../shared/config.js'; const harness = createDbHarness(); mock.module('../../server/db.js', { namedExports: harness.exports }); const { mergeAccounts, mergeCheck } = await import('../../server/data/accounts-merge.js'); const { eventsNetByAccount } = await import('../../server/data/events.js'); let btc; beforeEach(() => { harness.recreate(); harness.exports.run( `INSERT INTO Asset (symbol, name, searchName, kind, unit, subunit, decimals, displayUnit) VALUES ('BTC','Bitcoin','bitcoin','crypto','BTC','sat',8,'unit')`); btc = harness.exports.lastId(); }); function account(naam, kind = 'wallet') { const eigen = ACCOUNT_SOURCE_KINDS[kind].length > 0 ? 1 : 0; harness.exports.run( `INSERT INTO Account (name, searchName, kind, isOwnCustody, scanEnabled, isActive, closedAt) VALUES (?,?,?,?,?,1,NULL)`, [naam, toSearchName(naam), kind, eigen, 0]); return harness.exports.lastId(); } function event({ type = 'buy', from = null, to = null, amount = 1000, at = '2024-01-01T00:00:00', unitFee = null }) { harness.exports.run( `INSERT INTO Event (assetId, type, occurredAt, amount, fiatPrice, unitFee, fromAccountId, toAccountId, source, createdAt) VALUES (?,?,?,?,?,?,?,?,'manual',?)`, [btc, type, at, amount, type === 'buy' || type === 'sell' ? 1 : null, unitFee, from, to, at]); return harness.exports.lastId(); } function waardering({ acc, onDate, balance, rateAt = null }) { harness.exports.run( `INSERT INTO Valuation (assetId, valuedOn, accountId, balance, fiatRate, rateAt, source) VALUES (?,?,?,?,?,?, 'manual')`, [btc, onDate, acc, balance, 50000, rateAt ?? `${onDate}T00:00:00`]); return harness.exports.lastId(); } const tel = (tabel, kolom, id) => harness.exports.one(`SELECT COUNT(*) AS n FROM ${tabel} WHERE ${kolom} = ?`, [id]).n; const bestaatAccount = id => harness.exports.one(`SELECT 1 AS x FROM Account WHERE id=?`, [id]) != null; describe('mergeCheck: compatibiliteit', () => { it('vraagt om twee accounts', () => { const a = account('A'); assert.equal(mergeCheck(a, null).reason, 'pickTwo'); assert.equal(mergeCheck(null, a).reason, 'pickTwo'); assert.equal(mergeCheck(a, null).counts, null); }); it('weigert een account met zichzelf', () => { const a = account('A'); assert.equal(mergeCheck(a, a).reason, 'sameAccount'); assert.equal(mergeCheck(String(a), a).reason, 'sameAccount', 'ook als het id als string binnenkomt (uit een