Skip to content

Commit fd87745

Browse files
committed
fix: payload should include all expect options
1 parent fcb8aa1 commit fd87745

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/AmfHelperMixin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,16 @@ export const AmfHelperMixin = (base) => class extends base {
524524
* @returns {Payload[]|undefined} Payload model if defined.
525525
*/
526526
_computePayload(expects) {
527+
if (Array.isArray(expects)) {
528+
let payload = []
529+
for (const expect of expects) {
530+
const expectPayload = this._computePropertyArray(expect, this.ns.aml.vocabularies.apiContract.payload)
531+
if (expectPayload) {
532+
payload = payload.concat(expectPayload)
533+
}
534+
}
535+
return payload
536+
}
527537
return this._computePropertyArray(expects, this.ns.aml.vocabularies.apiContract.payload);
528538
}
529539

test/helper/amf-helper-mixin.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,23 @@ describe('AmfHelperMixin', () => {
17931793
});
17941794
assert.equal(spy.args[0][1], element.ns.raml.vocabularies.apiContract.payload);
17951795
});
1796+
1797+
it('Returns payloads of each element in array', () => {
1798+
const spy = sinon.spy(element, '_computePropertyArray');
1799+
const pKey = element._getAmfKey(element.ns.aml.vocabularies.apiContract.payload)
1800+
const expect = {
1801+
'@id': 'amf://1',
1802+
'@type': ['test'],
1803+
[pKey]: [
1804+
{
1805+
'@id': 'amf://2'
1806+
}
1807+
]
1808+
}
1809+
const payloads = element._computePayload([expect, expect])
1810+
assert.equal(spy.args[0][1], element.ns.raml.vocabularies.apiContract.payload);
1811+
assert.lengthOf(payloads, 2);
1812+
});
17961813
});
17971814

17981815
describe('_computeReturns()', () => {

0 commit comments

Comments
 (0)