Skip to content

Commit

Permalink
fix eslint issues and run prettier
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Eroglu <[email protected]>
  • Loading branch information
hasanheroglu committed Sep 27, 2024
1 parent 3468cbf commit c03e13a
Show file tree
Hide file tree
Showing 9 changed files with 181 additions and 86 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actionsx/prettier@v2
- uses: actionsx/prettier@v3
with:
args: --check .
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
* Document License (2015-05-13) which is available at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

const coap = require("coap");
const cbor = require("cbor");
const hostname = "localhost";
const portNumber = 5684;
const thingName = "coap-calculator-content-negotiation";

const fullTDEndpoint = `/${thingName}`,
resultEndPoint = `/${thingName}/properties/result`,
lastChangeEndPoint = `/${thingName}/properties/lastChange`,
additionEndPoint = `/${thingName}/actions/add`,
subtractionEndPoint = `/${thingName}/actions/subtract`,
updateEndPoint = `/${thingName}/events/update`;
const fullTDEndpoint = `/${thingName}`;
const resultEndPoint = `/${thingName}/properties/result`;
const lastChangeEndPoint = `/${thingName}/properties/lastChange`;
const additionEndPoint = `/${thingName}/actions/add`;
const subtractionEndPoint = `/${thingName}/actions/subtract`;
const updateEndPoint = `/${thingName}/events/update`;

/****************************************/
/****** Thing Description Endpoint ******/
/** **** Thing Description Endpoint ******/
/****************************************/

// GET request to retrieve thing description
Expand All @@ -28,7 +43,7 @@ function getFullTD(acceptType) {
});

getThingDescription.on("response", (res) => {
//TODO: Fix the problem with block wise transfer to be able to parse the response accordingly
// TODO: Fix the problem with block wise transfer to be able to parse the response accordingly
if (res.code === "2.05") {
if (
acceptType === "application/json" ||
Expand All @@ -53,7 +68,7 @@ function getFullTD(acceptType) {
}

/****************************************/
/*********** Result Endpoint ************/
/** ********* Result Endpoint ************/
/****************************************/

// GET request to retrieve a property (result)
Expand Down Expand Up @@ -131,7 +146,7 @@ function observeResultProperty(acceptType) {
}

/****************************************/
/********** lastChange Endpoint *********/
/** ******** lastChange Endpoint *********/
/****************************************/

// GET request to retrieve a property (lastChange)
Expand Down Expand Up @@ -208,7 +223,7 @@ function observeLastChangeProperty(acceptType) {
}

/****************************************/
/*********** Addition Endpoint **********/
/** ********* Addition Endpoint **********/
/****************************************/

// POST request to perform the addition action
Expand Down Expand Up @@ -252,7 +267,7 @@ function addNumber(acceptType, contentType, numberToAdd) {
}

/****************************************/
/********** Subtraction Endpoint ********/
/** ******** Subtraction Endpoint ********/
/****************************************/

// POST request to perform the subtract action
Expand Down Expand Up @@ -296,7 +311,7 @@ function subtractNumber(acceptType, contentType, numberToSubtract) {
}

/****************************************/
/*********** Update Endpoint ************/
/** ********* Update Endpoint ************/
/****************************************/

/**
Expand Down Expand Up @@ -339,24 +354,24 @@ function observeUpdateEvent(acceptType) {
observeUpdate.end();
}

//Test the main functionality of the content-negotiation-calculator-thing
// Test the main functionality of the content-negotiation-calculator-thing
function runCalculatorInteractions() {
//Main GET and POST requests
// Main GET and POST requests
getFullTD("application/json");
getResult("application/cbor");
getLastChange("application/json");
addNumber("application/cbor", "application/cbor", 3);
subtractNumber("application/json", "application/json", 2);

//Observation of properties and events after 1 second
// Observation of properties and events after 1 second
setTimeout(() => {
console.log("\n-------- Start observation --------\n");
observeResultProperty("application/json");
observeLastChangeProperty("application/cbor");
observeUpdateEvent("application/json");
}, 1000);

//Update the property result after 2.5 seconds to test the observation
// Update the property result after 2.5 seconds to test the observation
setTimeout(() => {
addNumber("application/cbor", "application/json", 1);
}, 2500);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
* Document License (2015-05-13) which is available at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

const { Servient } = require("@node-wot/core");
const { CoapClientFactory } = require("@node-wot/binding-coap");

Expand All @@ -17,18 +32,18 @@ servient
console.log(td);

// read property result
let result = await thing.readProperty("result", { formIndex: 2 });
const result = await thing.readProperty("result", { formIndex: 2 });
console.log("result: ", await result.value());

// read property lastChange
let lastChange = await thing.readProperty("lastChange", {
const lastChange = await thing.readProperty("lastChange", {
formIndex: 2,
});
console.log("lastChange: ", await lastChange.value());

console.log("\n ---------- \n");

//Observe properties
// Observe properties
thing.observeProperty("result", async (data) => {
console.log("Result observe:", await data.value());
});
Expand All @@ -41,11 +56,11 @@ servient
console.log("Update event:", await data.value());
});

//Invoke addition action
let add = await thing.invokeAction("add", 3, { formIndex: 1 });
// Invoke addition action
const add = await thing.invokeAction("add", 3, { formIndex: 1 });
console.log("Addition value:", await add.value());
//Invoke subtraction action
let subtract = await thing.invokeAction("subtract", 1, {
// Invoke subtraction action
const subtract = await thing.invokeAction("subtract", 1, {
formIndex: 3,
});
console.log("Subtraction value:", await subtract.value());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
// example-client.js
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
* Document License (2015-05-13) which is available at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

const { Servient } = require("@node-wot/core");
const { CoapClientFactory } = require("@node-wot/binding-coap");

Expand All @@ -18,11 +32,11 @@ servient
console.log(td);

// read property result
let result = await thing.readProperty("result");
const result = await thing.readProperty("result");
console.log("result: ", await result.value());

// read property lastChange
let lastChange = await thing.readProperty("lastChange");
const lastChange = await thing.readProperty("lastChange");
console.log("lastChange: ", await lastChange.value());

console.log("\n------------\n");
Expand All @@ -40,11 +54,11 @@ servient
console.log("Update event:", await data.value());
});

//Invoke addition action
let addition = await thing.invokeAction("add", 2);
// Invoke addition action
const addition = await thing.invokeAction("add", 2);
console.log("Addition result: ", await addition.value());
//Invoke addition subtraction
let subtraction = await thing.invokeAction("subtract", 3);
// Invoke addition subtraction
const subtraction = await thing.invokeAction("subtract", 3);
console.log("Subtraction result: ", await subtraction.value());

console.log("\n------------\n");
Expand Down
14 changes: 7 additions & 7 deletions things/calculator/coap/js/client-tests/simple-coap-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const subtractionEndPoint = `/${thingName}/actions/subtract`;
const updateEndPoint = `/${thingName}/events/update`;

/****************************************/
/****** Thing Description Endpoint ******/
/** **** Thing Description Endpoint ******/
/****************************************/

function getThingDescription() {
Expand Down Expand Up @@ -113,7 +113,7 @@ function observeResultProperty() {
}

/****************************************/
/********** lastChange Endpoint *********/
/** ******** lastChange Endpoint *********/
/****************************************/

function getLastChange() {
Expand Down Expand Up @@ -171,7 +171,7 @@ function observeLastChangeProperty() {
}

/****************************************/
/*********** Addition Endpoint **********/
/** ********* Addition Endpoint **********/
/****************************************/

function addNumber(numberToAdd) {
Expand Down Expand Up @@ -202,7 +202,7 @@ function addNumber(numberToAdd) {
}

/****************************************/
/********** Subtraction Endpoint ********/
/** ******** Subtraction Endpoint ********/
/****************************************/

function subtractNumber(numberToSubtract) {
Expand Down Expand Up @@ -236,7 +236,7 @@ function subtractNumber(numberToSubtract) {
}

/****************************************/
/*********** Update Endpoint ************/
/** ********* Update Endpoint ************/
/****************************************/

/**
Expand Down Expand Up @@ -279,15 +279,15 @@ function runCalculatorInteractions() {
addNumber(3);
subtractNumber(2);

//Start the observation of properties and events after 1 second
// Start the observation of properties and events after 1 second
setTimeout(() => {
console.log("\n-------- Start observation --------\n");
observeResultProperty();
observeLastChangeProperty();
observeUpdateEvent();
}, 1000);

//Update the property result after 2.5 seconds to test the observation
// Update the property result after 2.5 seconds to test the observation
setTimeout(() => {
addNumber(1);
}, 2500);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
/**
* @file The `content-negotiation-http-client.js` file acts as a client for the content-negotiation-calculator.js.
* This client is mostly used for testing the content negotiation functionality of the http thing.
* Requests as well as responses can be sent and received in JSON and CBOR formats.
*/
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
* Document License (2015-05-13) which is available at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

const cbor = require("cbor");
const EventSource = require("eventsource");

const url = "http://localhost:3000/http-express-calculator-content-negotiation",
resultEndPoint = "/properties/result",
resultEndPointObserve = `${resultEndPoint}/observe`,
lastChangeEndPoint = "/properties/lastChange",
lastChangeEndPointObserve = `${lastChangeEndPoint}/observe`,
additionEndPoint = "/actions/add",
subtractionEndPoint = "/actions/subtract",
updateEndPoint = "/events/update";
const url = "http://localhost:3000/http-express-calculator-content-negotiation";
const resultEndPoint = "/properties/result";
const resultEndPointObserve = `${resultEndPoint}/observe`;
const lastChangeEndPoint = "/properties/lastChange";
const lastChangeEndPointObserve = `${lastChangeEndPoint}/observe`;
const additionEndPoint = "/actions/add";
const subtractionEndPoint = "/actions/subtract";
const updateEndPoint = "/events/update";

/**
* Return the Full TD
Expand Down Expand Up @@ -90,7 +99,7 @@ function listenToResultProperty(acceptType) {
console.error("Error with Result property SSE:", error);
};

//Closing the event source after 6 seconds
// Closing the event source after 6 seconds
setTimeout(() => {
resultEventSource.close();
console.log("- Closing Result Property SSE");
Expand Down Expand Up @@ -150,7 +159,7 @@ function listenToLastChangeProperty(acceptType) {
console.error("Error with lastChange property SSE:", error);
};

//Closing the event source after 6 seconds
// Closing the event source after 6 seconds
setTimeout(() => {
lastChangeEventSource.close();
console.log("- Closing lastChange Property SSE");
Expand Down Expand Up @@ -257,7 +266,7 @@ function listenToUpdateEvent(acceptType) {
console.error("Error with Update event SSE:", error);
};

//Closing the event source after 6 seconds
// Closing the event source after 6 seconds
setTimeout(() => {
updateEventSource.close();
console.log("- Closing Update Event SSE");
Expand Down
Loading

0 comments on commit c03e13a

Please sign in to comment.