Unverified Commit 73db2678 authored by Dan Jones's avatar Dan Jones
Browse files

test: add coverage for protocol methods

parent 73605335
......@@ -50,7 +50,11 @@ class GenericProtocol {
* @returns {string}
*/
getType(message) {
return message.message_type;
try {
return message.payload.message_type;
} catch(error) {
return null;
}
}
/**
......
......@@ -52,7 +52,11 @@ class GenericProtocol {
* @returns {string}
*/
getType(message) {
return message.message_type;
try {
return message.payload.message_type;
} catch(error) {
return null;
}
}
/**
......
# Decode and encode are provided as stubs which are intended to be overridden
# These can be used to translate the message or to invoke other functions
# to take action based on the type and content of messages
Feature: Decode stubs passthru message unchanged
The protocol decode method works as expected
Scenario: Decode passes the message through unaltered
Given a valid message
When the protocol.decode method is called
Then the message is returned unaltered
# Decode and encode are provided as stubs which are intended to be overridden
# These can be used to translate the message or to invoke other functions
# to take action based on the type and content of messages
Feature: Encode stubs passthru message unchanged
The protocol encode method works as expected
Scenario: Encode passes the message through unaltered
Given a valid message
When the protocol.encode method is called
Then the message is returned unaltered
\ No newline at end of file
Feature: Can the protocol determine message type
The protocol getType method works as expected
Scenario: A valid message is successfully typed
Given a valid message
When protocol getType is called
Then getType returns message.payload.message_type if present
Scenario: An invalid message returns type:null
Given an invalid message
When protocol getType is called
Then getType returns null if message.payload.message_type is not present
Feature: Can the protocol validate messages?
The adapter validate method works as expected
Scenario: A valid message is successfully validated against the protocol schema
Given a valid message
When the protocol.validate method is called
Then the message is validated successfully
Scenario: An invalid message fails to validate against the protocol schema
Given an invalid message
When the protocol.validate method is called
Then the message fails to validate
\ No newline at end of file
......@@ -50,7 +50,11 @@ export class GenericProtocol {
* @returns {string}
*/
getType(message) {
return message.message_type;
try {
return message.payload.message_type;
} catch(error) {
return null;
}
}
/**
......
const assert = require('assert');
const { When, Then } = require('@cucumber/cucumber');
Then('a successful response is returned with status {int}', function(expectedStatus) {
this.call
.then(response => {
assert.equal(response.status, expectedStatus);
});
});
Then('an error response is returned with status {int}', function(expectedStatus) {
this.call
.catch((error) => {
assert.equal(error.response.status, expectedStatus);
});
});
\ No newline at end of file
......@@ -45,10 +45,3 @@ Then('the protocol {string} method is called {int} times', function(method, xInv
const decodes = this.protocol.getTrackedCalls(method);
assert.equal(decodes.length, xInvokes);
});
Then('an error response is returned with status {int}', function(expectedStatus) {
this.call
.catch((error) => {
assert.equal(error.response.status, expectedStatus);
});
});
......@@ -24,11 +24,4 @@ When('the publish method is called', function() {
const topic = message.metadata.destination;
const body = JSON.stringify(message);
this.call = this.adapter.publish(topic, body);
});
Then('a successful response is returned with status {int}', function(expectedStatus) {
this.call
.then(response => {
assert.equal(response.status, expectedStatus);
});
});
\ No newline at end of file
......@@ -13,14 +13,4 @@ Given('an invalid message', function() {
When('the validate method is called', function() {
this.validation = this.adapter.validate(this.message);
});
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() {
assert.equal(this.validation.valid, false);
assert.notEqual(this.validation.errorCount, 0);
});
\ No newline at end of file
const assert = require('assert');
const { Then } = require('@cucumber/cucumber');
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() {
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() {
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() {
this.type = this.protocol.getType(this.message);
});
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
const assert = require('assert');
const { When, Then } = require('@cucumber/cucumber');
When('the protocol.validate method is called', function() {
this.validation = this.protocol.validate(this.message);
});
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() {
assert.equal(this.validation.valid, false);
assert.notEqual(this.validation.errorCount, 0);
});
\ No newline at end of file
......@@ -6,9 +6,9 @@
"message_id": "test"
},
"payload": {
"message_type": "VehicleStatus",
"xoperator_id": 1,
"xvehicle_id": 12,
"messagetype": "VehicleStatus",
"operatorID": 1,
"vehicleID": 12,
"coordinates": {
"latitude": "monkeys",
"longitude": "janvier",
......
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