negotiationTodayPlanStoreAdapters.test.mjs
2.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const timeUtil = require('../../utils/timeFormat/time-utils.js')
const { NEGOTIATION_DAILY_API_SWITCH } = require('../config/apiSwitch.js')
const {
buildMockTodayPlanStoreList,
fetchTodayPlanStoreCountAdapter,
fetchTodayPlanStoreListAdapter,
normalizeTodayPlanStoreCountResponse,
normalizeTodayPlanStoreListResponse,
extractTodayPlanCount
} = require('../api/negotiationTodayPlanStoreAdapters.js')
describe('negotiationTodayPlanStoreAdapters', () => {
it('IT-PLAN-ADAPTER-001: mock count matches today list length', async () => {
const original = NEGOTIATION_DAILY_API_SWITCH.todayPlanStore
NEGOTIATION_DAILY_API_SWITCH.todayPlanStore = 'mock'
try {
const today = timeUtil.getTodayDateStr()
const expectedLen = buildMockTodayPlanStoreList(today).length
const res = await fetchTodayPlanStoreCountAdapter({
merchantId: '1',
advanceUserId: 'u1',
inviteDate: today
})
const normalized = normalizeTodayPlanStoreCountResponse(res)
assert.equal(normalized.code, 0)
assert.equal(normalized.data, expectedLen)
assert.ok(expectedLen > 0)
} finally {
NEGOTIATION_DAILY_API_SWITCH.todayPlanStore = original
}
})
it('IT-PLAN-ADAPTER-002: mock list empty for non-today inviteDate', async () => {
const original = NEGOTIATION_DAILY_API_SWITCH.todayPlanStore
NEGOTIATION_DAILY_API_SWITCH.todayPlanStore = 'mock'
try {
const res = await fetchTodayPlanStoreListAdapter({
merchantId: '1',
advanceUserId: 'u1',
inviteDate: '2000-01-01'
})
const normalized = normalizeTodayPlanStoreListResponse(res)
assert.equal(normalized.code, 0)
assert.equal(normalized.data.length, 0)
} finally {
NEGOTIATION_DAILY_API_SWITCH.todayPlanStore = original
}
})
it('IT-PLAN-ADAPTER-003: normalize count from scalar data', () => {
assert.equal(extractTodayPlanCount(3), 3)
const ok = normalizeTodayPlanStoreCountResponse({ code: 0, message: 'ok', data: 8 })
assert.equal(ok.data, 8)
})
it('IT-PLAN-ADAPTER-004: normalize list response', () => {
const res = normalizeTodayPlanStoreListResponse({
code: 0,
message: 'ok',
data: [{ customerName: 'A' }]
})
assert.equal(res.data.length, 1)
assert.equal(res.data[0].customerName, 'A')
})
})