33 lines
2.2 KiB
JavaScript
33 lines
2.2 KiB
JavaScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
import ts from 'typescript'
|
|
import { ref } from 'vue'
|
|
|
|
const source = readFileSync(new URL('./customsEligibility.ts', import.meta.url), 'utf8')
|
|
const exports = {}
|
|
new Function('exports', ts.transpileModule(source, { compilerOptions: { module: ts.ModuleKind.CommonJS } }).outputText)(exports)
|
|
|
|
test('upload queue contains only customer uploads still required, while completed documents stay accessible', () => {
|
|
const states = [null, {}, { status: 'WAITING_CUSTOMER_DOCUMENTS', merchantStatus: 'DOCUMENT_UPLOADED' },
|
|
{ status: 'READY_TO_START', merchantStatus: 'DOCUMENT_UPLOADED' },
|
|
{ status: 'DECLARING', merchantStatus: 'DECLARING' }, { status: 'COMPLETED', merchantStatus: 'CUSTOMS_COMPLETED' }]
|
|
for (const detail of states) assert.equal(exports.needsCustomsUpload(detail), false)
|
|
assert.equal(exports.needsCustomsUpload({ status: 'WAITING_CUSTOMER_DOCUMENTS', merchantStatus: 'WAITING_UPLOAD' }), true)
|
|
for (const status of ['LOADED', 'DELIVERED', 'COMPLETED']) assert.equal(exports.isCustomsOrderCandidate({ status, taxMode: 'TAX_REFUND' }), true)
|
|
})
|
|
|
|
test('upload status changes refresh server counts while initial detail reads do not reload the list', async () => {
|
|
const page = readFileSync(new URL('../views/FirstLegOrdersView.vue', import.meta.url), 'utf8')
|
|
const block = page.slice(page.indexOf('function updateCustomsDetail('), page.indexOf('const detailOrder ='))
|
|
const js = ts.transpileModule(block, { compilerOptions: { target: ts.ScriptTarget.ES2022 } }).outputText
|
|
const states = {}, id = ref('one'), create = ref(false), detail = ref(false)
|
|
let reloads = 0
|
|
const update = new Function('customsByOrder', 'customsDialogOrderId', 'isCreatePage', 'isDetailPage', 'loadOrderPage', js + ';return updateCustomsDetail')(states, id, create, detail, async () => reloads++)
|
|
update({ merchantStatus: 'WAITING_UPLOAD' }); assert.equal(reloads, 0)
|
|
update({ merchantStatus: 'WAITING_UPLOAD' }); assert.equal(reloads, 0)
|
|
update({ merchantStatus: 'DOCUMENT_UPLOADED' }); assert.equal(reloads, 1)
|
|
assert.equal(states.one.merchantStatus, 'DOCUMENT_UPLOADED')
|
|
detail.value = true; update({ merchantStatus: 'WAITING_UPLOAD' }); assert.equal(reloads, 1)
|
|
})
|