Skip to content

Commit

Permalink
test(td-tools): add a test for composed types in strings
Browse files Browse the repository at this point in the history
Signed-off-by: reluc <[email protected]>
  • Loading branch information
relu91 committed Mar 30, 2022
1 parent 9c917a2 commit 238f4f0
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/td-tools/test/ThingModelHelperTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 238f4f0

Please sign in to comment.