fix(order): enforce versioned platform commands and submissions
This commit is contained in:
@@ -323,12 +323,16 @@ function cancellationFixture(change=null) {
|
||||
return cancellationOutbox()
|
||||
}}
|
||||
if(change)change({rootDetail,childDetail,childInbound,tree})
|
||||
context.request=async(method,path,body)=>{
|
||||
calls.push({method,path,body})
|
||||
let frozenCancel
|
||||
context.request=async(method,path,body,token,headers)=>{
|
||||
calls.push({method,path,body,headers})
|
||||
if(method==='POST'){
|
||||
assert.equal(path,'/api/platform/v1/orders/first-leg/101/cancel?tenantId=90')
|
||||
assert.ok(body.reason.includes('offline-only'))
|
||||
if(count++)return {http:200,body:{code:'A0409'}}
|
||||
assert.ok(headers?.['Idempotency-Key'])
|
||||
if(count++)return {http:200,body:{code:headers['Idempotency-Key']===frozenCancel.key && JSON.stringify(body)===frozenCancel.payload ? '200' : 'A0409'}}
|
||||
assert.equal(body.expectedVersion,childDetail.order.version)
|
||||
frozenCancel={key:headers['Idempotency-Key'],payload:JSON.stringify(body)}
|
||||
childDetail.order.status='CANCELLED';childDetail.order.version++
|
||||
childDetail.statusHistory=history('CANCELLED')
|
||||
rootDetail.order.status='COMPLETED';rootDetail.order.version++
|
||||
@@ -352,7 +356,13 @@ test('formal cancellation helper rereads physical eligibility, uses public cance
|
||||
const {context,proof,calls}=cancellationFixture()
|
||||
const result=await cancelUnloadedRemainder(context,proof,'90','100','101','300','301')
|
||||
assert.equal(validRemainderCancellationGate(result),true)
|
||||
assert.equal(calls.filter(row=>row.method==='POST').length,2)
|
||||
const writes=calls.filter(row=>row.method==='POST')
|
||||
assert.equal(writes.length,4)
|
||||
assert.deepEqual(writes[1].body,writes[0].body)
|
||||
assert.deepEqual(writes[1].headers,writes[0].headers)
|
||||
assert.equal(writes[2].headers['Idempotency-Key'],writes[0].headers['Idempotency-Key'])
|
||||
assert.notEqual(writes[3].headers['Idempotency-Key'],writes[0].headers['Idempotency-Key'])
|
||||
assert.ok(writes[3].body.expectedVersion>writes[0].body.expectedVersion)
|
||||
assert.equal(proof.snapshots.length,3)
|
||||
assert.deepEqual(proof.cancelReplayOutbox.before,proof.cancelReplayOutbox.after)
|
||||
assert.equal(context.steps.every(step=>step.passed),true)
|
||||
|
||||
Reference in New Issue
Block a user