Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
backbone-adapter-javascript
Commits
73db2678
Unverified
Commit
73db2678
authored
2 years ago
by
Dan Jones
Browse files
Options
Download
Email Patches
Plain Diff
test: add coverage for protocol methods
parent
73605335
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
128 additions
and
30 deletions
+128
-30
dist/protocol.esm.js
dist/protocol.esm.js
+5
-1
dist/protocol.js
dist/protocol.js
+5
-1
features/protocol_decode.feature
features/protocol_decode.feature
+11
-0
features/protocol_encode.feature
features/protocol_encode.feature
+11
-0
features/protocol_get-type.feature
features/protocol_get-type.feature
+12
-0
features/protocol_validate.feature
features/protocol_validate.feature
+12
-0
src/protocol/index.js
src/protocol/index.js
+5
-1
test/cucumber/adapter/common.steps.js
test/cucumber/adapter/common.steps.js
+16
-0
test/cucumber/adapter/poll.steps.js
test/cucumber/adapter/poll.steps.js
+0
-7
test/cucumber/adapter/publish.steps.js
test/cucumber/adapter/publish.steps.js
+0
-7
test/cucumber/adapter/validate.steps.js
test/cucumber/adapter/validate.steps.js
+0
-10
test/cucumber/protocol/common.steps.js
test/cucumber/protocol/common.steps.js
+6
-0
test/cucumber/protocol/decode.steps.js
test/cucumber/protocol/decode.steps.js
+6
-0
test/cucumber/protocol/encode.steps.js
test/cucumber/protocol/encode.steps.js
+6
-0
test/cucumber/protocol/get-type.steps.js
test/cucumber/protocol/get-type.steps.js
+14
-0
test/cucumber/protocol/validate.steps.js
test/cucumber/protocol/validate.steps.js
+16
-0
test/fixtures/message-vehicle-status-invalid.json
test/fixtures/message-vehicle-status-invalid.json
+3
-3
No files found.
dist/protocol.esm.js
View file @
73db2678
...
...
@@ -50,7 +50,11 @@ class GenericProtocol {
* @returns {string}
*/
getType
(
message
)
{
return
message
.
message_type
;
try
{
return
message
.
payload
.
message_type
;
}
catch
(
error
)
{
return
null
;
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
dist/protocol.js
View file @
73db2678
...
...
@@ -52,7 +52,11 @@ class GenericProtocol {
* @returns {string}
*/
getType
(
message
)
{
return
message
.
message_type
;
try
{
return
message
.
payload
.
message_type
;
}
catch
(
error
)
{
return
null
;
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
features/protocol_decode.feature
0 → 100644
View file @
73db2678
# 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
This diff is collapsed.
Click to expand it.
features/protocol_encode.feature
0 → 100644
View file @
73db2678
# 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
This diff is collapsed.
Click to expand it.
features/protocol_get-type.feature
0 → 100644
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
features/protocol_validate.feature
0 → 100644
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
src/protocol/index.js
View file @
73db2678
...
...
@@ -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
;
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/common.steps.js
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/poll.steps.js
View file @
73db2678
...
...
@@ -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
);
});
});
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/publish.steps.js
View file @
73db2678
...
...
@@ -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
This diff is collapsed.
Click to expand it.
test/cucumber/adapter/validate.steps.js
View file @
73db2678
...
...
@@ -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
This diff is collapsed.
Click to expand it.
test/cucumber/protocol/common.steps.js
0 → 100644
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
test/cucumber/protocol/decode.steps.js
0 → 100644
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
test/cucumber/protocol/encode.steps.js
0 → 100644
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
test/cucumber/protocol/get-type.steps.js
0 → 100644
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
test/cucumber/protocol/validate.steps.js
0 → 100644
View file @
73db2678
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
This diff is collapsed.
Click to expand it.
test/fixtures/message-vehicle-status-invalid.json
View file @
73db2678
...
...
@@ -6,9 +6,9 @@
"message_id"
:
"test"
},
"payload"
:
{
"message
_
type"
:
"VehicleStatus"
,
"
x
operator
_id
"
:
1
,
"
x
vehicle
_id
"
:
12
,
"messagetype"
:
"VehicleStatus"
,
"operator
ID
"
:
1
,
"vehicle
ID
"
:
12
,
"coordinates"
:
{
"latitude"
:
"monkeys"
,
"longitude"
:
"janvier"
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment