menuSync.test.mjs
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
describe('equity menuSyncHelpers', async () => {
const { buildEquityMenuFingerprint, createMenuRebuildCoordinator } =
await import('../services/menuSyncHelpers.js')
const { getMenuFingerprint } = await import('../menu/context.js')
const user = { uuid: 'u1', shopMerchantId: 's1' }
it('IT-EQ-MENU-SYNC-001: force rebuild commits fingerprint then second sync skips', async () => {
const coord = createMenuRebuildCoordinator()
let calls = 0
const fingerprint = buildEquityMenuFingerprint(getMenuFingerprint, user, {
mode: 1,
isStaff: true
})
await coord.sync({
force: true,
fingerprint,
rebuild: async () => {
calls++
}
})
await coord.sync({
fingerprint,
rebuild: async () => {
calls++
}
})
assert.equal(calls, 1)
assert.equal(coord.getStoredFingerprint(), fingerprint)
})
it('IT-EQ-MENU-SYNC-002: coordinator dedupes concurrent rebuilds', async () => {
const coord = createMenuRebuildCoordinator()
let calls = 0
const fingerprint = buildEquityMenuFingerprint(getMenuFingerprint, user, {
mode: 0
})
await Promise.all([
coord.sync({ force: true, fingerprint, rebuild: async () => { calls++ } }),
coord.sync({ force: true, fingerprint, rebuild: async () => { calls++ } })
])
assert.equal(calls, 1)
})
})