Commit 80607371 authored by Dan Jones's avatar Dan Jones
Browse files

Merge branch '20-sort-out-linting-config' into 'dev'

Resolve "Sort out linting config"

Closes #20

See merge request !13
parents a8e98ce4 b9dfcc49
const assert = require('assert');
const { When, Then } = require('@cucumber/cucumber');
When('the getAuthorizationHeader method is called', function() {
When('the getAuthorizationHeader method is called', function () {
this.call = this.adapter.getAuthorizationHeader();
let callCount = this.adapter.getTrackedCalls('getAuthorizationHeader').length;
this.callCounts.getAuthorizationHeader = callCount;
});
Then('a headers object is returned containing a bearer token authorization header', function() {
this.call.then(headers => {
assert.ok('Authorization' in headers);
const authHeaderWords = headers.Authorization.split(" ");
assert.ok(authHeaderWords[0] === 'Bearer');
assert.ok(authHeaderWords[1] === this.adapter.credentials.token);
});
});
Then(
'a headers object is returned containing a bearer token authorization header',
function () {
this.call.then((headers) => {
assert.ok('Authorization' in headers);
const authHeaderWords = headers.Authorization.split(' ');
assert.ok(authHeaderWords[0] === 'Bearer');
assert.ok(authHeaderWords[1] === this.adapter.credentials.token);
});
}
);
......@@ -5,64 +5,73 @@ const { fixtures } = require('../../fixtures/server');
const mockValidConfig = fixtures.get('config-valid');
const xMessageResponse = function(xMessages) {
const xMessageResponse = function (xMessages) {
const message = fixtures.get('message-vehicle-status');
let response = [];
for (let i=0; i<xMessages; i++) {
for (let i = 0; i < xMessages; i++) {
response.push({
topic: "broadcast",
message: JSON.stringify(message)
topic: 'broadcast',
message: JSON.stringify(message),
});
}
return response;
};
When('a mock receive API response is configured to return {int} messages', function(xMessages) {
const response = xMessageResponse(xMessages);
this.mockAxios.onGet(
`${mockValidConfig.api}/receive`,
).reply(200, response);
});
When(
'a mock receive API response is configured to return {int} messages',
function (xMessages) {
const response = xMessageResponse(xMessages);
this.mockAxios.onGet(`${mockValidConfig.api}/receive`).reply(200, response);
}
);
When('a mock receive API response is configured to return a {int} error', function(statusCode) {
const statusMessages = {
403: 'Token expired',
503: 'Service unavailable'
};
this.mockAxios.onGet(
`${mockValidConfig.api}/receive`,
).reply(statusCode, { message: statusMessages[statusCode] })
});
When(
'a mock receive API response is configured to return a {int} error',
function (statusCode) {
const statusMessages = {
403: 'Token expired',
503: 'Service unavailable',
};
this.mockAxios
.onGet(`${mockValidConfig.api}/receive`)
.reply(statusCode, { message: statusMessages[statusCode] });
}
);
When('the poll method is called', function() {
When('the poll method is called', function () {
this.call = this.adapter.poll();
this.callCounts.poll = this.adapter.getTrackedCalls('poll').length;
});
Then('a successful response is returned with {int} messages', function(xMessages) {
this.call
.then(response => {
assert.equal(response.data.length, xMessages);
});
});
Then(
'a successful response is returned with {int} messages',
function (xMessages) {
this.call.then((response) => {
assert.equal(response.data.length, xMessages);
});
}
);
Then('the protocol {string} method is called {int} times', function(method, xInvokes) {
const decodes = this.protocol.getTrackedCalls(method);
assert.equal(decodes.length, xInvokes);
});
Then(
'the protocol {string} method is called {int} times',
function (method, xInvokes) {
const decodes = this.protocol.getTrackedCalls(method);
assert.equal(decodes.length, xInvokes);
}
);
When('the poll method is called with is_retry on', function() {
When('the poll method is called with is_retry on', function () {
this.call = this.adapter.poll(true);
this.callCounts.poll = this.adapter.getTrackedCalls('poll').length;
});
Then('the poll method was called with is_retry on', function() {
Then('the poll method was called with is_retry on', function () {
let pollCalls = this.adapter.getTrackedCalls('poll');
let lastCall = pollCalls[pollCalls.length-1];
let lastCall = pollCalls[pollCalls.length - 1];
assert.ok(lastCall.arguments[1].is_retry);
});
Then('the poll method is not called again', function() {
Then('the poll method is not called again', function () {
let newPollCallCount = this.adapter.getTrackedCalls('poll').length;
assert.equal(this.callCounts.poll, newPollCallCount);
});
......@@ -5,24 +5,25 @@ const { fixtures } = require('../../fixtures/server');
const mockValidConfig = fixtures.get('config-valid');
When('a mock send API response is configured to return success', function() {
When('a mock send API response is configured to return success', function () {
const response = {};
this.mockAxios.onPost(
`${mockValidConfig.api}/send`,
).reply(200, response);
this.mockAxios.onPost(`${mockValidConfig.api}/send`).reply(200, response);
});
When('a mock send API response is configured to return a {int} error', function(statusCode) {
const statusMessages = {
403: 'Token expired',
503: 'Service unavailable'
};
this.mockAxios.onPost(
`${mockValidConfig.api}/send`,
).reply(statusCode, { message: statusMessages[statusCode] })
});
When('the publish method is called', function() {
When(
'a mock send API response is configured to return a {int} error',
function (statusCode) {
const statusMessages = {
403: 'Token expired',
503: 'Service unavailable',
};
this.mockAxios
.onPost(`${mockValidConfig.api}/send`)
.reply(statusCode, { message: statusMessages[statusCode] });
}
);
When('the publish method is called', function () {
const message = fixtures.get('message-vehicle-status');
this.message = message;
const topic = message.metadata.destination;
......@@ -31,7 +32,7 @@ When('the publish method is called', function() {
this.callCounts.publish = this.adapter.getTrackedCalls('publish').length;
});
When('the publish method is called with is_retry on', function() {
When('the publish method is called with is_retry on', function () {
const message = fixtures.get('message-vehicle-status');
this.message = message;
const topic = message.metadata.destination;
......@@ -40,13 +41,13 @@ When('the publish method is called with is_retry on', function() {
this.callCounts.publish = this.adapter.getTrackedCalls('publish').length;
});
Then('the publish method was called with is_retry on', function() {
Then('the publish method was called with is_retry on', function () {
let publishCalls = this.adapter.getTrackedCalls('publish');
let lastCall = publishCalls[publishCalls.length-1];
let lastCall = publishCalls[publishCalls.length - 1];
assert.ok(lastCall.arguments[1].is_retry);
});
Then('the publish method is not called again', function() {
Then('the publish method is not called again', function () {
let newPublishCallCount = this.adapter.getTrackedCalls('publish').length;
assert.equal(this.callCounts.publish, newPublishCallCount);
});
\ No newline at end of file
});
const assert = require('assert');
const { When, Then } = require('@cucumber/cucumber');
When('the token expiry is in the future', function() {
When('the token expiry is in the future', function () {
const expiry = new Date();
expiry.setHours(expiry.getHours()+1);
expiry.setHours(expiry.getHours() + 1);
this.adapter.credentials.expiry = expiry.toISOString();
});
When('the token expiry is in the past', function() {
When('the token expiry is in the past', function () {
const expiry = new Date();
expiry.setHours(expiry.getHours()-1);
this.adapter.credentials.expiry = expiry.toISOString();
expiry.setHours(expiry.getHours() - 1);
this.adapter.credentials.expiry = expiry.toISOString();
});
// Boolean parameters are not supported
// and returns "true" would be misleading
Then('tokenValid returns true', function() {
Then('tokenValid returns true', function () {
const isValid = this.adapter.tokenValid();
assert.ok(isValid);
});
Then('tokenValid returns false', function() {
Then('tokenValid returns false', function () {
const isValid = this.adapter.tokenValid();
assert.ok(!isValid);
});
\ No newline at end of file
});
const assert = require('assert');
const { Given, When, Then } = require('@cucumber/cucumber');
const { Given, When } = require('@cucumber/cucumber');
const { fixtures } = require('../../fixtures/server');
Given('a valid message', function() {
Given('a valid message', function () {
this.message = fixtures.get('message-vehicle-status');
});
Given('an invalid message', function() {
Given('an invalid message', function () {
this.message = fixtures.get('message-vehicle-status-invalid');
});
When('the validate method is called', function() {
When('the validate method is called', function () {
this.validation = this.adapter.validate(this.message);
});
\ No newline at end of file
});
const assert = require('assert');
const { Then } = require('@cucumber/cucumber');
Then('the message is returned unaltered', function() {
Then('the message is returned unaltered', function () {
assert.equal(this.message, this.response);
});
\ No newline at end of file
});
const { When } = require('@cucumber/cucumber');
When('the protocol.decode method is called', function() {
When('the protocol.decode method is called', function () {
const type = this.protocol.getType(this.message);
this.response = this.protocol.decode(type, this.message);
});
\ No newline at end of file
});
const { When } = require('@cucumber/cucumber');
When('the protocol.encode method is called', function() {
When('the protocol.encode method is called', function () {
const type = this.protocol.getType(this.message);
this.response = this.protocol.encode(type, this.message);
});
\ No newline at end of file
});
const assert = require('assert');
const { When, Then } = require('@cucumber/cucumber');
When('protocol getType is called', function() {
When('protocol getType is called', function () {
this.type = this.protocol.getType(this.message);
});
Then('getType returns message.payload.message_type if present', function() {
Then('getType returns message.payload.message_type if present', function () {
assert.equal(this.type, this.message.payload.message_type);
});
Then('getType returns null if message.payload.message_type is not present', function() {
assert.equal(this.type, null);
});
\ No newline at end of file
Then(
'getType returns null if message.payload.message_type is not present',
function () {
assert.equal(this.type, null);
}
);
const assert = require('assert');
const { When, Then } = require('@cucumber/cucumber');
When('the protocol.validate method is called', function() {
When('the protocol.validate method is called', function () {
this.validation = this.protocol.validate(this.message);
});
Then('the message is validated successfully', function() {
Then('the message is validated successfully', function () {
assert.equal(this.validation.valid, true);
assert.equal(this.validation.errorCount, 0);
});
Then('the message fails to validate', function() {
Then('the message fails to validate', function () {
assert.equal(this.validation.valid, false);
assert.notEqual(this.validation.errorCount, 0);
});
\ No newline at end of file
});
......@@ -6,18 +6,18 @@ const fs = require('fs');
const schemaLocation = './test/mock/swagger.json';
Given('the test schema', function() {
Given('the test schema', function () {
this.schema = JSON.parse(fs.readFileSync(schemaLocation));
});
When('it is validated', function() {
When('it is validated', function () {
const validator = new OpenAPISchemaValidator({ version: 3 });
this.validation = validator.validate(this.schema);
});
Then('it matches the OpenAPI specification', function() {
// According to the docs this should return a valid:boolean
// but if you look at the code it just returns a list of errors
Then('it matches the OpenAPI specification', function () {
// According to the docs this should return a valid:boolean
// but if you look at the code it just returns a list of errors
// which is empty for a valid result
assert.equal(this.validation.errors.length, 0);
});
\ No newline at end of file
});
......@@ -4,12 +4,14 @@ const path = require('path');
exports.fixtures = {
get: function (fixtureName) {
try {
let fixtureContent = fs.readFileSync(path.join(__dirname, `${fixtureName}.json`));
let fixtureContent = fs.readFileSync(
path.join(__dirname, `${fixtureName}.json`)
);
let fixture = JSON.parse(fixtureContent);
return fixture;
} catch(e) {
} catch (e) {
console.error('Fixture not found', fixtureName);
return null;
}
}
}
\ No newline at end of file
},
};
......@@ -14,7 +14,7 @@
"longitude": -10.432,
"depth": 50,
"projection": 4326
},
},
"actions": []
}
}
......@@ -17,4 +17,4 @@
},
"battery_percentage": 64
}
}
\ No newline at end of file
}
......@@ -64,7 +64,7 @@
"example": "VehicleStatus"
}
},
"required": ["source","destination","message_id"],
"required": ["source", "destination", "message_id"],
"type": "object"
},
"Coordinates": {
......@@ -128,7 +128,13 @@
"example": 64
}
},
"required": ["message_type", "operator_id", "vehicle_id", "coordinates", "battery_percentage"],
"required": [
"message_type",
"operator_id",
"vehicle_id",
"coordinates",
"battery_percentage"
],
"type": "object"
},
"VehicleMission": {
......@@ -177,7 +183,13 @@
}
}
},
"required": ["message_type", "operator_id", "vehicle_id", "coordinates", "actions"],
"required": [
"message_type",
"operator_id",
"vehicle_id",
"coordinates",
"actions"
],
"type": "object"
},
"AreaOfInterest": {
......@@ -202,7 +214,12 @@
"$ref": "#/components/schemas/Coordinates"
}
},
"required": ["message_type", "operator_id", "vehicle_id", "coordinates"],
"required": [
"message_type",
"operator_id",
"vehicle_id",
"coordinates"
],
"type": "object"
},
"GoToWaypoint": {
......
......@@ -581,14 +581,26 @@
ts-node "^9"
tslib "^2"
"@eslint/eslintrc@^1.4.1":
version "1.4.1"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.4.1.tgz#af58772019a2d271b7e2d4c23ff4ddcba3ccfb3e"
integrity sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA==
"@eslint-community/eslint-utils@^4.2.0":
version "4.3.0"
resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.3.0.tgz#a556790523a351b4e47e9d385f47265eaaf9780a"
integrity sha512-v3oplH6FYCULtFuCeqyuTd9D2WKO937Dxdq+GmHOLL72TTRriLxz2VLlNfkZRsvj6PKnOPAtuT6dwrs/pA5DvA==
dependencies:
eslint-visitor-keys "^3.3.0"
"@eslint-community/regexpp@^4.4.0":
version "4.4.0"
resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.4.0.tgz#3e61c564fcd6b921cb789838631c5ee44df09403"
integrity sha512-A9983Q0LnDGdLPjxyXQ00sbV+K+O+ko2Dr+CZigbHWtX9pNfxlaBkMR8X1CztI73zuEyEBXTVjx7CE+/VSwDiQ==
"@eslint/eslintrc@^2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-2.0.1.tgz#7888fe7ec8f21bc26d646dbd2c11cd776e21192d"
integrity sha512-eFRmABvW2E5Ho6f5fHLqgena46rOj7r7OKHYfLElqcBfGFHHpjBhivyi5+jOEQuSpdc/1phIZJlbC2te+tZNIw==
dependencies:
ajv "^6.12.4"
debug "^4.3.2"
espree "^9.4.0"
espree "^9.5.0"
globals "^13.19.0"
ignore "^5.2.0"
import-fresh "^3.2.1"
......@@ -596,6 +608,11 @@
minimatch "^3.1.2"
strip-json-comments "^3.1.1"
"@eslint/js@8.36.0":
version "8.36.0"
resolved "https://registry.yarnpkg.com/@eslint/js/-/js-8.36.0.tgz#9837f768c03a1e4a30bd304a64fb8844f0e72efe"
integrity sha512-lxJ9R5ygVm8ZWgYdUweoq5ownDlJ4upvoWmO4eLxBYHdMo+vZ/Rx0EN6MbKWDJOSUGrqJy2Gt+Dyv/VKml0fjg==
"@humanwhocodes/config-array@^0.11.8":
version "0.11.8"
resolved "https://registry.yarnpkg.com/@humanwhocodes/config-array/-/config-array-0.11.8.tgz#03595ac2075a4dc0f191cc2131de14fbd7d410b9"
......@@ -1898,14 +1915,7 @@ eslint-scope@^7.1.1:
esrecurse "^4.3.0"
estraverse "^5.2.0"
eslint-utils@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/eslint-utils/-/eslint-utils-3.0.0.tgz#8aebaface7345bb33559db0a1f13a1d2d48c3672"
integrity sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==
dependencies:
eslint-visitor-keys "^2.0.0"
eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0:
eslint-visitor-keys@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
......@@ -1915,12 +1925,15 @@ eslint-visitor-keys@^3.3.0:
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz#f6480fa6b1f30efe2d1968aa8ac745b862469826"
integrity sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==
eslint@^8.4.1:
version "8.31.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.31.0.tgz#75028e77cbcff102a9feae1d718135931532d524"
integrity sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA==
eslint@^8.36.0:
version "8.36.0"
resolved "https://registry.yarnpkg.com/eslint/-/eslint-8.36.0.tgz#1bd72202200a5492f91803b113fb8a83b11285cf"
integrity sha512-Y956lmS7vDqomxlaaQAHVmeb4tNMp2FWIvU/RnU5BD3IKMD/MJPr76xdyr68P8tV1iNMvN2mRK0yy3c+UjL+bw==
dependencies:
"@eslint/eslintrc" "^1.4.1"
"@eslint-community/eslint-utils" "^4.2.0"
"@eslint-community/regexpp" "^4.4.0"
"@eslint/eslintrc" "^2.0.1"
"@eslint/js" "8.36.0"
"@humanwhocodes/config-array" "^0.11.8"
"@humanwhocodes/module-importer" "^1.0.1"
"@nodelib/fs.walk" "^1.2.8"
......@@ -1931,10 +1944,9 @@ eslint@^8.4.1:
doctrine "^3.0.0"
escape-string-regexp "^4.0.0"
eslint-scope "^7.1.1"
eslint-utils "^3.0.0"
eslint-visitor-keys "^3.3.0"
espree "^9.4.0"
esquery "^1.4.0"
espree "^9.5.0"
esquery "^1.4.2"
esutils "^2.0.2"
fast-deep-equal "^3.1.3"
file-entry-cache "^6.0.1"
......@@ -1955,15 +1967,14 @@ eslint@^8.4.1:
minimatch "^3.1.2"
natural-compare "^1.4.0"
optionator "^0.9.1"
regexpp "^3.2.0"
strip-ansi "^6.0.1"
strip-json-comments "^3.1.0"
text-table "^0.2.0"
espree@^9.4.0:
version "9.4.1"
resolved "https://registry.yarnpkg.com/espree/-/espree-9.4.1.tgz#51d6092615567a2c2cff7833445e37c28c0065bd"
integrity sha512-XwctdmTO6SIvCzd9810yyNzIrOrqNYV9Koizx4C/mRhf9uq0o4yHoCEU/670pOxOL/MSraektvSAji79kX90Vg==
espree@^9.5.0:
version "9.5.0"
resolved "https://registry.yarnpkg.com/espree/-/espree-9.5.0.tgz#3646d4e3f58907464edba852fa047e6a27bdf113"
integrity sha512-JPbJGhKc47++oo4JkEoTe2wjy4fmMwvFpgJT9cQzmfXKp22Dr6Hf1tdCteLz1h0P3t+mGvWZ+4Uankvh8+c6zw==
dependencies:
acorn "^8.8.0"
acorn-jsx "^5.3.2"
......@@ -1974,10 +1985,10 @@ esprima@^4.0.0, esprima@^4.0.1:
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71"
integrity sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==
esquery@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.4.0.tgz#2148ffc38b82e8c7057dfed48425b3e61f0f24a5"
integrity sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==
esquery@^1.4.2:
version "1.5.0"
resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.5.0.tgz#6ce17738de8577694edd7361c57182ac8cb0db0b"
integrity sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==
dependencies:
estraverse "^5.1.0"
......@@ -3720,10 +3731,10 @@ prettier-linter-helpers@^1.0.0:
dependencies:
fast-diff "^1.1.2"
prettier@^2.5.1:
version "2.8.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.2.tgz#c4ea1b5b454d7c4b59966db2e06ed7eec5dfd160"
integrity sha512-BtRV9BcncDyI2tsuS19zzhzoxD8Dh8LiCx7j7tHzrkz8GFXAexeWFdi22mjE1d16dftH2qNaytVxqiRTGlMfpw==
prettier@^2.8.4:
version "2.8.4"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.4.tgz#34dd2595629bfbb79d344ac4a91ff948694463c3"
integrity sha512-vIS4Rlc2FNh0BySk3Wkd6xmwxB0FpOndW5fisM5H8hsZSxU2VWVB5CWIkIjWvrHjIhxk2g3bfMKM87zNTrZddw==
pretty-format@^27.5.1:
version "27.5.1"
......@@ -3905,11 +3916,6 @@ regexp-tree@^0.1.11:
resolved "https://registry.yarnpkg.com/regexp-tree/-/regexp-tree-0.1.24.tgz#3d6fa238450a4d66e5bc9c4c14bb720e2196829d"
integrity sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==
regexpp@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"
integrity sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==
repeat-string@^1.5.2, repeat-string@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment