33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import {
|
|
isDingWorkflowOngoing,
|
|
sourceWorkflowTimestampToIso,
|
|
} from '@/lib/ding-workflow-sync'
|
|
|
|
jest.mock('mssql', () => ({
|
|
__esModule: true,
|
|
default: {},
|
|
}))
|
|
|
|
jest.mock('@/lib/prisma', () => ({ prisma: {} }))
|
|
jest.mock('@/lib/brand-center-access', () => ({ resolveBrandCenterAccessForUser: jest.fn() }))
|
|
|
|
describe('ding workflow snapshot sync semantics', () => {
|
|
test.each([
|
|
['RUNNING', null, true],
|
|
['NEW', '', true],
|
|
['COMPLETED', null, false],
|
|
['TERMINATED', null, false],
|
|
['CANCELED', null, false],
|
|
['RUNNING', '2026-08-20 10:30:00', false],
|
|
['', null, false],
|
|
])('status %s and finish time %s resolves ongoing=%s', (status, finishTime, expected) => {
|
|
expect(isDingWorkflowOngoing(status, finishTime)).toBe(expected)
|
|
})
|
|
|
|
it('interprets upstream timestamps as Asia/Shanghai when no zone is present', () => {
|
|
expect(sourceWorkflowTimestampToIso('2026-08-20 10:30:00')).toBe('2026-08-20T02:30:00.000Z')
|
|
expect(sourceWorkflowTimestampToIso('2026-08-20T10:30:00Z')).toBe('2026-08-20T10:30:00.000Z')
|
|
expect(sourceWorkflowTimestampToIso('invalid')).toBeNull()
|
|
})
|
|
})
|