Skip to content

Commit

Permalink
add tm tests for new things
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Eroglu <[email protected]>
  • Loading branch information
hasanheroglu committed Sep 6, 2024
1 parent 8fac263 commit eb39f70
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/runTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ return_value=0
for tmd in things/* ; do
tm_test_path="$tmd/*.test.js"
if [ ! -f $tm_test_path ]; then
echo "$tm_test_path does not exist. Continuing with the next thing."
continue
fi

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"@context":[
"https://www.w3.org/2019/wot/td/v1",
"https://www.w3.org/2022/wot/td/v1.1",
{
"@language":"en"
}
],
"@type":"tm:ThingModel",
"title":"{{THING_NAME}}",
"description": "A smart coffee machine with a range of capabilities.\\nA complementary tutorial is available at http: //www.thingweb.io/smart-coffee-machine.html.",
"support": "https://github.com/eclipse-thingweb/node-wot/",
Expand Down
32 changes: 32 additions & 0 deletions things/advanced-coffee-machine/tm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const Ajv = require('ajv')
const chai = require('chai')
const https = require('https')

const ajv = new Ajv({ strict: false, allErrors: true, validateFormats: false })

const expect = chai.expect

describe('Advanced Coffee Machine', () => {
let validate

before((done) => {
https.get('https://raw.githubusercontent.com/w3c/wot-thing-description/main/validation/tm-json-schema-validation.json', function (response) {
const body = []
response.on('data', (chunk) => {
body.push(chunk)
})

response.on('end', () => {
const tmSchema = JSON.parse(Buffer.concat(body).toString())
validate = ajv.compile(tmSchema)
done()
})
})
})

it('should have a valid TM', () => {
const advancedCoffeeMachineTM = require('./advanced-coffee-machine.tm.json')
const valid = validate(advancedCoffeeMachineTM)
expect(valid).to.be.true
})
})
7 changes: 7 additions & 0 deletions things/test-thing/test-thing.tm.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"@context":[
"https://www.w3.org/2019/wot/td/v1",
"https://www.w3.org/2022/wot/td/v1.1",
{
"@language":"en"
}
],
"@type":"tm:ThingModel",
"title":"{{THING_NAME}}",
"description": "Test Thing",
Expand Down
32 changes: 32 additions & 0 deletions things/test-thing/tm.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const Ajv = require('ajv')
const chai = require('chai')
const https = require('https')

const ajv = new Ajv({ strict: false, allErrors: true, validateFormats: false })

const expect = chai.expect

describe('Test Thing', () => {
let validate

before((done) => {
https.get('https://raw.githubusercontent.com/w3c/wot-thing-description/main/validation/tm-json-schema-validation.json', function (response) {
const body = []
response.on('data', (chunk) => {
body.push(chunk)
})

response.on('end', () => {
const tmSchema = JSON.parse(Buffer.concat(body).toString())
validate = ajv.compile(tmSchema)
done()
})
})
})

it('should have a valid TM', () => {
const testThingTM = require('./test-thing.tm.json')
const valid = validate(testThingTM)
expect(valid).to.be.true
})
})

0 comments on commit eb39f70

Please sign in to comment.