Support deferred payments with travel deals
Verify and publish checkpoint container / container (push) Successful in 11m29s
Verify and publish checkpoint container / container (push) Successful in 11m29s
This commit is contained in:
1 parent
9536c77062
commit
5e294215be
16 files changed
+603
-100
No files matched your search
@@ -54,13 +54,18 @@ void test('the offer packet retains legacy two-party terms and validates an expl
|
||||
{type:'dealOffer', targets:['b','c'], terms:'Terms', payment, travel:{...travel, actor:'c'}});
|
||||
assert.deepEqual(publicDealOfferAction(['b','c'], 'Terms', {...payment,payer:'b',recipient:'c'}, 'a', 2, {...travel, actor:'c'}),
|
||||
{type:'dealOffer', targets:['b','c'], terms:'Terms', payment:{...payment,payer:'b',recipient:'c'}, travel:{...travel, actor:'c'}});
|
||||
assert.equal(publicDealOfferAction(['b','c'], 'Terms', {kind:'deferredBribe',payer:'a',recipient:'b',amount:2,dueTurn:2}, 'a', 2, {...travel, actor:'c'}), null);
|
||||
const deferred = {kind:'deferredBribe' as const,payer:'a',recipient:'b',amount:2,dueTurn:2};
|
||||
assert.deepEqual(publicDealOfferAction(['b','c'], 'Terms', deferred, 'a', 2, {...travel, actor:'c'}),
|
||||
{type:'dealOffer', targets:['b','c'], terms:'Terms', payment:deferred, travel:{...travel, actor:'c'}});
|
||||
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', payment, 'a', 2, travel),
|
||||
{type:'dealOffer', target:'b', terms:'Terms', payment, travel});
|
||||
const reverse = {...payment,payer:'b',recipient:'a'};
|
||||
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', reverse, 'a', 2, travel),
|
||||
{type:'dealOffer', target:'b', terms:'Terms', payment:reverse, travel});
|
||||
assert.equal(publicDealOfferAction(['b'], 'Terms', {kind:'deferredBribe',payer:'a',recipient:'b',amount:2,dueTurn:2}, 'a', 2, travel), null);
|
||||
assert.deepEqual(publicDealOfferAction(['b'], 'Terms', deferred, 'a', 2, travel),
|
||||
{type:'dealOffer', target:'b', terms:'Terms', payment:deferred, travel});
|
||||
assert.equal(publicDealOfferAction(['b'], 'Terms', {...deferred,dueTurn:1}, 'a', 2, travel), null);
|
||||
assert.equal(publicDealOfferAction(['b','c'], 'Terms', {...deferred,recipient:'outsider'}, 'a', 2, {...travel,actor:'c'}), null);
|
||||
assert.equal(publicDealOfferAction(['b','c'], 'Terms', payment, 'a', 2, travel), null);
|
||||
assert.equal(publicDealOfferAction(['a'], 'Terms', undefined, 'a', 2, travel), null);
|
||||
assert.equal(publicDealOfferAction(['b'], 'Terms', undefined, undefined, 2, travel), null);
|
||||
@@ -130,7 +135,7 @@ function combinedForm(gameOverride?: GameView) {
|
||||
return {render, check, select, sent};
|
||||
}
|
||||
|
||||
void test('the authoring controls compose a proposer payment with recipient travel and reject invalid combinations', () => {
|
||||
void test('the authoring controls compose immediate or deferred payment with recipient travel', () => {
|
||||
const ui = combinedForm();
|
||||
ui.check(0); // Select recipient.
|
||||
ui.check(1); // Include payment.
|
||||
@@ -146,12 +151,19 @@ void test('the authoring controls compose a proposer payment with recipient trav
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[0])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
payment:{kind:'immediateBribe',payer:'a',recipient:'b',amount:1},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true}});
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,true);
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,false);
|
||||
assert.ok(ui.render().some(node => node.type === 'p' && typeof node.props.children === 'string' &&
|
||||
node.props.children.includes('an immediate payment or a payment due by the end of a selected turn')));
|
||||
const deferredForm = ui.render().find(node => node.type === 'form'); assert.ok(deferredForm);
|
||||
(deferredForm.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[1])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
payment:{kind:'deferredBribe',payer:'a',recipient:'b',amount:1,dueTurn:2},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true}});
|
||||
ui.select(0,'immediateBribe'); ui.select(1,'b'); ui.select(2,'a');
|
||||
assert.equal(button()?.props.disabled,false);
|
||||
const reverseForm = ui.render().find(node => node.type === 'form'); assert.ok(reverseForm);
|
||||
(reverseForm.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[1])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[2])), {type:'dealOffer',target:'b',terms:'Travel for spice',
|
||||
payment:{kind:'immediateBribe',payer:'b',recipient:'a',amount:1},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true}});
|
||||
});
|
||||
@@ -247,7 +259,12 @@ void test('the group offer form selects an invited traveler and revalidates part
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[1])), {type:'dealOffer',targets:['b','d'],terms:'Group travel',
|
||||
payment:{kind:'immediateBribe',payer:'b',recipient:'d',amount:1},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true,actor:'d'}});
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,true, 'Deferred group payment remains unavailable.');
|
||||
ui.select(0,'deferredBribe'); assert.equal(button()?.props.disabled,false);
|
||||
const deferredForm = ui.render().find(node => node.type === 'form'); assert.ok(deferredForm);
|
||||
(deferredForm.props.onSubmit as (event:{preventDefault():void}) => void)({preventDefault() {}});
|
||||
assert.deepEqual(JSON.parse(JSON.stringify(ui.sent[2])), {type:'dealOffer',targets:['b','d'],terms:'Group travel',
|
||||
payment:{kind:'deferredBribe',payer:'b',recipient:'d',amount:1,dueTurn:2},
|
||||
travel:{kind:'ship',territory:'carthag',minimum:1,answer:true,actor:'d'}});
|
||||
});
|
||||
|
||||
void test('the author chooses a future travel turn and can return to the legacy current-turn packet', () => {
|
||||
|
||||
Reference in new issue
Block a user