|
| 1 | +import { assert } from '@open-wc/testing'; |
| 2 | +import { AmfLoader } from '../AmfLoader.js'; |
| 3 | +import { AmfSerializer, ns } from '../../index.js'; |
| 4 | + |
| 5 | +/** @typedef {import('../../src/amf').Server} Server */ |
| 6 | +/** @typedef {import('../../src/types').ApiArrayShape} ApiArrayShape */ |
| 7 | +/** @typedef {import('../../src/types').ApiNodeShape} ApiNodeShape */ |
| 8 | +/** @typedef {import('../../src/types').ApiUnionShape} ApiUnionShape */ |
| 9 | +/** @typedef {import('../../src/types').ApiScalarShape} ApiScalarShape */ |
| 10 | +/** @typedef {import('../../src/types').ApiScalarNode} ApiScalarNode */ |
| 11 | +/** @typedef {import('../../src/types').ApiFileShape} ApiFileShape */ |
| 12 | +/** @typedef {import('../../src/types').ApiRecursiveShape} ApiRecursiveShape */ |
| 13 | +/** @typedef {import('../../src/types').ApiCustomDomainProperty} ApiCustomDomainProperty */ |
| 14 | +/** @typedef {import('../../src/types').ApiSchemaShape} ApiSchemaShape */ |
| 15 | +/** @typedef {import('../../src/types').ApiTupleShape} ApiTupleShape */ |
| 16 | + |
| 17 | +describe('AmfSerializer', () => { |
| 18 | + describe('APIC-483', () => { |
| 19 | + const fileName = 'APIC-483'; |
| 20 | + let api; |
| 21 | + /** @type AmfSerializer */ |
| 22 | + let serializer; |
| 23 | + before(async () => { |
| 24 | + api = await AmfLoader.load(true, fileName); |
| 25 | + serializer = new AmfSerializer(); |
| 26 | + serializer.amf = api; |
| 27 | + }); |
| 28 | + |
| 29 | + it('serializes a TupleShape', () => { |
| 30 | + const expects = AmfLoader.lookupExpects(api, '/banks', 'post'); |
| 31 | + const payload = AmfLoader._computePayload(expects)[0]; |
| 32 | + const shape = payload[serializer._getAmfKey(serializer.ns.aml.vocabularies.shapes.schema)][0]; |
| 33 | + const result = /** @type ApiNodeShape */ (serializer.unknownShape(shape)); |
| 34 | + const { examples, properties } = result; |
| 35 | + assert.lengthOf(examples, 1, 'has the examples'); |
| 36 | + assert.lengthOf(properties, 1, 'has the properties'); |
| 37 | + const array = /** @type ApiTupleShape */ (properties[0].range); |
| 38 | + const { types, items } = array; |
| 39 | + assert.include(types, ns.aml.vocabularies.shapes.TupleShape, 'range has the TupleShape'); |
| 40 | + assert.lengthOf(items, 1, 'range has the items'); |
| 41 | + }); |
| 42 | + }); |
| 43 | +}); |
0 commit comments