31 lines
1.7 KiB
JavaScript
31 lines
1.7 KiB
JavaScript
import test from 'node:test'
|
|||
|
|
import assert from 'node:assert/strict'
|
||
|
|
import { run } from './orders.mjs'
|
||
|
|
|
||
|
|
async function loginOnly(fixture, options = {}) {
|
||
|
|
const calls = []
|
||
|
|
const context = { context: { merchantQualificationFixture: fixture }, options,
|
||
|
|
request: async (...args) => { calls.push(args); return {} }, apiSuccess: () => null }
|
||
|
|
await assert.rejects(run(context), /Client 登录未返回 accessToken/)
|
||
|
|
return calls
|
||
|
|
}
|
||
|
|
test('one cached orders module uses each serial run customer, never the first customer', async () => {
|
||
|
|
const first = await loginOnly({ username: 'customer-a', password: 'password-a' })
|
||
|
|
const second = await loginOnly({ username: 'customer-b', password: 'password-b' },
|
||
|
|
{ merchantUsername: 'customer-a', merchantPassword: 'password-a' })
|
||
|
|
assert.deepEqual(first[0].slice(0,3), ['POST','/api/auth/login',{ loginId:'customer-a',password:'password-a' }])
|
||
|
|
assert.deepEqual(second[0].slice(0,3), ['POST','/api/auth/login',{ loginId:'customer-b',password:'password-b' }])
|
||
|
|
assert.equal(first.length, 1); assert.equal(second.length, 1)
|
||
|
|
})
|
||
|
|
test('partial current fixture never combines credentials with configured prior customer', async () => {
|
||
|
|
let requests = 0
|
||
|
|
await assert.rejects(run({ context:{merchantQualificationFixture:{username:'customer-b'}},
|
||
|
|
options:{merchantUsername:'customer-a',merchantPassword:'password-a'},
|
||
|
|
request:async()=>{requests++} }), /缺少完整登录凭据/)
|
||
|
|
assert.equal(requests, 0)
|
||
|
|
})
|
||
|
|
test('explicit paired options are used when no fixture was created', async () => {
|
||
|
|
const calls = await loginOnly(undefined,{merchantUsername:'configured',merchantPassword:'configured-password'})
|
||
|
|
assert.equal(calls[0][2].loginId,'configured')
|
||
|
|
})
|