Skip to content

Commit

Permalink
test: add additional test for raw data
Browse files Browse the repository at this point in the history
  • Loading branch information
Krauskopf Sebastian (DC-AE/EAR2) committed Feb 4, 2025
1 parent 7eaaadd commit 48f1c79
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/CtrlxDatalayerV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ class CtrlxDatalayer {
} else {
payload = {
type: 'raw',
value: buffer,
value: new Uint8Array(buffer),
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/CtrlxCore.nodes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,21 @@ describe('CtrlxCoreDataLayerNodes', function() {

});

it('should return a raw buffer', function(done) {

let ctrlx = new CtrlxCore(getHostname(), getUsername(), getPassword());

ctrlx.logIn()
.then(() => { return ctrlx.datalayerRead('encoding/raw/buffer'); })
.then((data) => {
assert.deepEqual(data.value, new Uint8Array([0x01, 0x02, 0x03, 0x04, 0x05]));
done();
})
.catch((err) => done(err))
.finally(() => ctrlx.logOut());

});

});


Expand Down
2 changes: 1 addition & 1 deletion test/CtrlxCore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('CtrlxCore', function() {
done();
});

it('should parse invalid JSON', function(done) {
it('should throw exception on invalid JSON', function(done) {

const invalidJSON = 'test/invalid/json';
expect(() => CtrlxDatalayer._parseData(invalidJSON)).to.throw(SyntaxError);
Expand Down
11 changes: 11 additions & 0 deletions test/helper/CtrlxMockupV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ class CtrlxMockupV2 {
type: 'bool'
});
});

this.app.get('/automation/api/v2/nodes/framework/metrics/system/cpu-utilisation-percent', authenticateJWT, (req, res) => {
switch (req.query.type) {
case undefined:
Expand Down Expand Up @@ -166,6 +167,7 @@ class CtrlxMockupV2 {
break;
}
});

this.app.get('/automation/api/v2/nodes/framework/metrics/system', authenticateJWT, (req, res) => {
if (req.query.type === 'browse') {
res.statusCode = 200;
Expand Down Expand Up @@ -193,6 +195,7 @@ class CtrlxMockupV2 {
type: 'int16'
});
});

this.app.get('/automation/api/v2/nodes/plc/app/Application/sym/PLC_PRG/i', authenticateJWT, (req, res) => {
res.statusCode = 200;
res.json({
Expand All @@ -213,6 +216,7 @@ class CtrlxMockupV2 {
res.setHeader('content-type', 'application/json');
res.send(`{"type": "int64", "value":${this.var_i64.toString()}}`);
});

this.app.get('/automation/api/v2/nodes/plc/app/Application/sym/PLC_PRG/i64', authenticateJWT, (req, res) => {
res.statusCode = 200;
res.setHeader('content-type', 'application/json');
Expand All @@ -233,6 +237,7 @@ class CtrlxMockupV2 {
type: 'string'
});
});

this.app.get('/automation/api/v2/nodes/plc/app/Application/sym/PLC_PRG/str', authenticateJWT, (req, res) => {
res.statusCode = 200;
res.json({
Expand Down Expand Up @@ -284,6 +289,12 @@ class CtrlxMockupV2 {
});
});

this.app.get('/automation/api/v2/nodes/encoding/raw/buffer', authenticateJWT, (req, res) => {
res.statusCode = 200;
res.setHeader('content-type', 'application/octet-stream');
res.send(Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]));
});


//
// Builtin Data Mockups - Create/Delete
Expand Down

0 comments on commit 48f1c79

Please sign in to comment.