|
| 1 | +import { assert } from "@open-wc/testing"; |
| 2 | +import { AmfLoader } from "../AmfLoader.js"; |
| 3 | +import { AmfSerializer } from "../../index.js"; |
| 4 | + |
| 5 | +/** @typedef {import('../../src/types').ApiScalarNode} ApiScalarNode */ |
| 6 | +/** @typedef {import('../../src/types').ApiObjectNode} ApiObjectNode */ |
| 7 | + |
| 8 | +describe("AmfSerializer", () => { |
| 9 | + describe("Annotations", () => { |
| 10 | + [true, ].forEach((compact) => { |
| 11 | + describe(compact ? "Compact model" : "Full model", () => { |
| 12 | + let api; |
| 13 | + /** @type AmfSerializer */ |
| 14 | + let serializer; |
| 15 | + before(async () => { |
| 16 | + api = await AmfLoader.load(compact); |
| 17 | + serializer = new AmfSerializer(); |
| 18 | + serializer.amf = api; |
| 19 | + }); |
| 20 | + |
| 21 | + it("ObjectNode annotations", () => { |
| 22 | + const shape = AmfLoader.lookupOperation(api, "/about", "get"); |
| 23 | + const result = serializer.operation(shape); |
| 24 | + assert.typeOf(result, "object", "returns an object"); |
| 25 | + const { customDomainProperties } = result; |
| 26 | + assert.typeOf(customDomainProperties, 'array', 'has the customDomainProperties'); |
| 27 | + assert.lengthOf(customDomainProperties, 1, 'has a single annotation'); |
| 28 | + const [annotation] = customDomainProperties; |
| 29 | + assert.equal(annotation.extensionName, 'clearanceLevel', 'has the extensionName'); |
| 30 | + const { properties } = /** @type ApiObjectNode */ (/** @type unknown */ (annotation)); |
| 31 | + assert.typeOf(properties, 'object', 'has properties'); |
| 32 | + const { level, signature } = properties; |
| 33 | + assert.typeOf(level, 'object', 'has the level property'); |
| 34 | + assert.typeOf(signature, 'object', 'has the level property'); |
| 35 | + }); |
| 36 | + |
| 37 | + it("ScalarShape annotations", () => { |
| 38 | + const shape = AmfLoader.lookupOperation(api, "/files", "post"); |
| 39 | + const result = serializer.operation(shape); |
| 40 | + assert.typeOf(result, "object", "returns an object"); |
| 41 | + const { customDomainProperties } = result; |
| 42 | + assert.typeOf(customDomainProperties, 'array', 'has the customDomainProperties'); |
| 43 | + assert.lengthOf(customDomainProperties, 1, 'has a single annotation'); |
| 44 | + const [annotation] = customDomainProperties; |
| 45 | + assert.equal(annotation.extensionName, 'deprecated', 'has the extensionName'); |
| 46 | + const { value, dataType, } = /** @type ApiScalarNode */ (/** @type unknown */ (annotation)); |
| 47 | + assert.equal(dataType, 'http://www.w3.org/2001/XMLSchema#string', 'has the dataType'); |
| 48 | + assert.equal(value, 'This operation is deprecated and will be removed.', 'has the value'); |
| 49 | + }); |
| 50 | + }); |
| 51 | + }); |
| 52 | + }); |
| 53 | +}); |
0 commit comments