Skip to content

Commit

Permalink
test(coap-server): add basic tests for property meta operations
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Sep 21, 2023
1 parent d6dc63b commit 641cae5
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/binding-coap/test/coap-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,70 @@ class CoapServerTest {
await coapServer.stop();
await coapClient.stop();
}

@test async "should reject requests for undefined meta operations"() {
const coapServer = new CoapServer();
const servient = new Servient();

await coapServer.start(servient);

const testThingWithoutForms = new ExposedThing(servient, {
title: "Test",
});

await coapServer.expose(testThingWithoutForms);

await new Promise<void>((resolve) => {
const req = request({
host: "localhost",
pathname: "test/properties",
port: coapServer.getPort(),
method: "GET",
});
req.on("response", (res: IncomingMessage) => {
expect(res.code).to.equal("4.04");
resolve();
});
req.end();
});

await coapServer.stop();
await servient.shutdown();
}

@test async "should reject unsupported methods for meta operations"() {
const coapServer = new CoapServer();
const servient = new Servient();

await coapServer.start(servient);

const testThingWithoutForms = new ExposedThing(servient, {
title: "Test",
properties: {
testInteger: {
type: "integer",
forms: [],
},
},
});

await coapServer.expose(testThingWithoutForms);

await new Promise<void>((resolve) => {
const req = request({
host: "localhost",
pathname: "test/properties",
port: coapServer.getPort(),
method: "PUT",
});
req.on("response", (res) => {
expect(res.code).to.equal("4.05");
resolve();
});
req.end();
});

await coapServer.stop();
await servient.shutdown();
}
}

0 comments on commit 641cae5

Please sign in to comment.