From 238f4f09d82074e4ff2634186d7bd7da77f0267e Mon Sep 17 00:00:00 2001 From: reluc Date: Wed, 30 Mar 2022 14:38:24 +0200 Subject: [PATCH] test(td-tools): add a test for composed types in strings Signed-off-by: reluc --- .../td-tools/test/ThingModelHelperTest.ts | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/packages/td-tools/test/ThingModelHelperTest.ts b/packages/td-tools/test/ThingModelHelperTest.ts index ee3a95b45..2849a097f 100644 --- a/packages/td-tools/test/ThingModelHelperTest.ts +++ b/packages/td-tools/test/ThingModelHelperTest.ts @@ -384,6 +384,40 @@ class ThingModelHelperTest { expect(partialTd).to.be.deep.equal(finalJSON); } + @test async "should correctly fill placeholders with composed types in strings"() { + const thing = { + "@context": ["http://www.w3.org/ns/td"], + "@type": "tm:ThingModel", + data: "data: {{ARRAY}}", + title: "Thermostate No. 4", + versionInfo: "version: {{VERSION_INFO}}", + } as unknown as ThingModel; + const map = { + ARRAY: [1, 2, 3], + VERSION_INFO: { instance: "xyz", model: "ABC" }, + }; + const finalJSON = { + "@context": ["http://www.w3.org/ns/td"], + "@type": "Thing", + title: "Thermostate No. 4", + data: "data: [1,2,3]", + versionInfo: 'version: {"instance":"xyz","model":"ABC"}', + links: [ + { + href: "./ThermostateNo.4.tm.jsonld", + rel: "type", + type: "application/tm+json", + }, + ], + }; + const options: CompositionOptions = { + map, + selfComposition: false, + }; + const [partialTd] = await this.thingModelHelpers.getPartialTDs(thing, options); + expect(partialTd).to.be.deep.equal(finalJSON); + } + @test async "should reject fill placeholders because of missing fields in map"() { const thing = { "@context": ["http://www.w3.org/ns/td"],