serviceCenterNoticeService.test.mjs
2.17 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { describe, it, beforeEach, afterEach } from 'node:test'
import assert from 'node:assert/strict'
describe('serviceCenterNoticeService', async () => {
const {
fetchServiceCenterUnread,
resolveFirstUnreadNotice,
__setListApiForTest,
clearServiceCenterNoticeCache
} = await import('../services/serviceCenterNoticeService.js')
let apiCalls
beforeEach(() => {
apiCalls = []
clearServiceCenterNoticeCache()
if (!Date.prototype.format) {
Date.prototype.format = function () {
return '2026-06-09'
}
}
globalThis.wx = {}
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
return { data: { list: [{ id: 1, msgTitle: '课程', reminderType: 1 }] } }
}
return { data: { list: [] } }
})
})
afterEach(() => {
__setListApiForTest(null)
clearServiceCenterNoticeCache()
})
it('IT-EQ-NOTICE-001: fetchServiceCenterUnread caches within session', async () => {
const a = await fetchServiceCenterUnread()
const b = await fetchServiceCenterUnread()
assert.equal(a, 1)
assert.equal(b, 1)
assert.equal(apiCalls.length, 3)
})
it('IT-EQ-NOTICE-002: resolveFirstUnreadNotice returns first unread by noticeSort', async () => {
const first = await resolveFirstUnreadNotice()
assert.ok(first)
assert.equal(first.moduleType, 6)
clearServiceCenterNoticeCache()
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
return { data: { list: [] } }
}
if (params.moduleType === 7) {
return { data: { list: [{ id: 2, msgTitle: '案例', reminderType: 1 }] } }
}
return { data: { list: [] } }
})
const second = await resolveFirstUnreadNotice()
assert.ok(second)
assert.equal(second.moduleType, 7)
})
it('IT-EQ-NOTICE-003: probe scans all module types once per cache window', async () => {
__setListApiForTest(async params => {
apiCalls.push(params.moduleType)
if (params.moduleType === 6) {
return { data: { list: [{ id: 1, msgTitle: '课程', reminderType: 1 }] } }
}
return { data: { list: [] } }
})
await fetchServiceCenterUnread()
await resolveFirstUnreadNotice()
assert.equal(apiCalls.length, 3)
})
})