dashboardService.test.mjs
1.81 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
/**
* IT-EQ-DASH-* 权益首页看板 service 单测
*/
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
buildOutputValueDateRange,
normalizeOutputValueStats,
normalizeQuotationStatistics
} from '../services/dashboardService.js'
describe('dashboardService', () => {
it('IT-EQ-DASH-001: buildOutputValueDateRange today', () => {
const now = new Date('2026-06-09T12:00:00')
now.format = () => '2026-06-09'
const range = buildOutputValueDateRange('today', now)
assert.equal(range.startTime, '2026-06-09 00:00:00')
assert.equal(range.endTime, '2026-06-09 23:59:59')
})
it('IT-EQ-DASH-002: buildOutputValueDateRange month', () => {
const now = new Date('2026-06-09T12:00:00')
now.format = () => '2026-06-09'
const range = buildOutputValueDateRange('month', now)
assert.match(range.startTime, /2026-06-01 00:00:00/)
assert.equal(range.endTime, '2026-06-09 23:59:59')
})
it('IT-EQ-DASH-003: buildOutputValueDateRange total empty', () => {
const range = buildOutputValueDateRange('total')
assert.equal(range.startTime, '')
assert.equal(range.endTime, '')
})
it('IT-EQ-DASH-004: normalizeOutputValueStats scales conversionRate', () => {
const out = normalizeOutputValueStats({
conversionRate: 0.12,
avgPrice: 5000,
totalOutputValue: 12345.6,
avgQuotationPrice: 9999.4
})
assert.equal(out.conversionRate, 12)
assert.equal(out.avgPrice, 50)
assert.equal(out.totalOutputValue, 12346)
})
it('IT-EQ-DASH-005: normalizeQuotationStatistics splits cents', () => {
const out = normalizeQuotationStatistics({
todayTurnover: 12345,
monthTurnover: 99999,
totalTurnover: 10000050
})
assert.equal(out.todayTurnover, '123')
assert.equal(out.todayTurDecimal, '45')
assert.equal(out.monthTurnover, '999')
assert.equal(out.totalTurnover, '100001')
})
})