homeRefreshService.test.mjs
1.33 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
48
49
50
51
52
53
54
55
import { describe, it, beforeEach } from 'node:test'
import assert from 'node:assert/strict'
import {
buildHomeRefreshFingerprint,
withHomeRefreshDedup,
clearHomeRefreshState
} from '../services/homeRefreshService.js'
describe('homeRefreshService', () => {
beforeEach(() => {
clearHomeRefreshState()
})
it('IT-EQ-HOME-001: buildHomeRefreshFingerprint includes dataActive merchant isWait', () => {
const fp = buildHomeRefreshFingerprint({
dataActive: 'month',
shopMerchantId: 'store-1',
isWait: true
})
assert.equal(fp, 'month|store-1|1')
})
it('IT-EQ-HOME-002: withHomeRefreshDedup dedupes concurrent calls', async () => {
let runs = 0
const fp = buildHomeRefreshFingerprint({
dataActive: 'today',
shopMerchantId: 'm1',
isWait: false
})
const task = () =>
withHomeRefreshDedup(fp, {}, async () => {
runs++
await new Promise(r => setTimeout(r, 10))
})
await Promise.all([task(), task()])
assert.equal(runs, 1)
})
it('IT-EQ-HOME-003: withHomeRefreshDedup allows sequential tab refresh', async () => {
let runs = 0
const fp = buildHomeRefreshFingerprint({
dataActive: 'today',
shopMerchantId: 'm1',
isWait: true
})
await withHomeRefreshDedup(fp, {}, async () => {
runs++
})
await withHomeRefreshDedup(fp, {}, async () => {
runs++
})
assert.equal(runs, 2)
})
})