fix(wecom): 经营报告截账至发送日前一天24点
日报、周报、月报均不含发送当天发生额,避免盘中数据未闭合。
This commit is contained in:
@@ -25,11 +25,12 @@ const emptyStats = {
|
||||
};
|
||||
|
||||
describe('wecomReportPeriod', () => {
|
||||
it('daily is the Shanghai calendar day', () => {
|
||||
it('daily is the previous Shanghai calendar day (closed at send-day 00:00)', () => {
|
||||
const p = wecomReportPeriod('daily', new Date('2026-09-02T20:00:00+08:00'));
|
||||
expect(p.periodKey).toBe('2026-09-02');
|
||||
expect(p.periodKey).toBe('2026-09-01');
|
||||
expect(p.incrementLabel).toBe('当日新增');
|
||||
expect(p.start.toISOString()).toBe(new Date('2026-09-02T00:00:00+08:00').toISOString());
|
||||
expect(p.start.toISOString()).toBe(new Date('2026-09-01T00:00:00+08:00').toISOString());
|
||||
expect(p.endExclusive.toISOString()).toBe(new Date('2026-09-02T00:00:00+08:00').toISOString());
|
||||
});
|
||||
|
||||
it('weekly is the previous natural week', () => {
|
||||
@@ -37,26 +38,28 @@ describe('wecomReportPeriod', () => {
|
||||
expect(p.periodKey).toBe('2026-08-24');
|
||||
expect(p.rangeLabel).toBe('2026-08-24 ~ 2026-08-30');
|
||||
expect(p.incrementLabel).toBe('本期新增');
|
||||
expect(p.endExclusive.toISOString()).toBe(new Date('2026-08-31T00:00:00+08:00').toISOString());
|
||||
});
|
||||
|
||||
it('monthly is the previous natural month', () => {
|
||||
const p = wecomReportPeriod('monthly', new Date('2026-09-01T09:00:00+08:00'));
|
||||
expect(p.periodKey).toBe('2026-08');
|
||||
expect(p.title).toBe('月报(2026年8月)');
|
||||
expect(p.endExclusive.toISOString()).toBe(new Date('2026-09-01T00:00:00+08:00').toISOString());
|
||||
});
|
||||
});
|
||||
|
||||
describe('wecomReportCutoff', () => {
|
||||
it('caps an in-progress daily period at now', () => {
|
||||
it('daily closes at send-day midnight, not send clock time', () => {
|
||||
const now = new Date('2026-09-02T20:00:00+08:00');
|
||||
const p = wecomReportPeriod('daily', now);
|
||||
expect(wecomReportCutoff(p, now).getTime()).toBe(now.getTime());
|
||||
expect(wecomReportCutoff(p).getTime()).toBe(new Date('2026-09-02T00:00:00+08:00').getTime());
|
||||
});
|
||||
|
||||
it('uses period end for a completed week', () => {
|
||||
const now = new Date('2026-09-02T09:00:00+08:00');
|
||||
const p = wecomReportPeriod('weekly', now);
|
||||
expect(wecomReportCutoff(p, now).getTime()).toBe(p.endExclusive.getTime());
|
||||
expect(wecomReportCutoff(p).getTime()).toBe(p.endExclusive.getTime());
|
||||
});
|
||||
});
|
||||
|
||||
@@ -86,7 +89,7 @@ describe('wecomReportShouldFire', () => {
|
||||
expect(
|
||||
wecomReportShouldFire(
|
||||
'daily',
|
||||
{ ...base, lastSentPeriod: '2026-09-02' },
|
||||
{ ...base, lastSentPeriod: '2026-09-01' },
|
||||
new Date('2026-09-02T21:00:00+08:00'),
|
||||
),
|
||||
).toBe(false);
|
||||
@@ -125,7 +128,7 @@ describe('formatWecomReportMarkdown', () => {
|
||||
it('renders stock plus increment lines', () => {
|
||||
const p = wecomReportPeriod('daily', new Date('2026-09-02T20:00:00+08:00'));
|
||||
const md = formatWecomReportMarkdown(p, emptyStats);
|
||||
expect(md).toContain('**杜康好客 · 日报(2026-09-02)**');
|
||||
expect(md).toContain('**杜康好客 · 日报(2026-09-01)**');
|
||||
expect(md).toContain('用户数量:10(当日新增 2)');
|
||||
expect(md).toContain('订单金额:1000.00(当日新增 80.50)');
|
||||
expect(md).toContain('核销单数量:8(当日新增 3)');
|
||||
|
||||
Reference in New Issue
Block a user