Unit testing for eventType constraints in 0.1

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2018-11-09 16:50:54 -02:00
parent 46c7946707
commit 3b732a0308
2 changed files with 21 additions and 1 deletions

View File

@ -26,6 +26,10 @@ function Spec_0_1(_caller){
*/
Spec_0_1.prototype.check = function() {
if(!this.payload['eventType']){
throw {message: "'eventType' is invalid"};
}
}
Spec_0_1.prototype.type = function(_type){

View File

@ -1,8 +1,10 @@
var expect = require("chai").expect;
var Cloudevent = require("../index.js");
const type = "com.github.pull.create";
var cloudevent = new Cloudevent()
.type("com.github.pull.create")
.type(type)
.source("urn:event:from:myapi/resourse/123");
describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
@ -34,6 +36,20 @@ describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
});
});
describe("The Constraint check", () => {
describe("'eventType'", () => {
it("should throw an error when is an empty string", () => {
cloudevent.type("");
expect(cloudevent.format.bind(cloudevent)).to.throw("'eventType' is invalid");
});
it("should be a non-empty string", () => {
cloudevent.type(type);
cloudevent.format();
});
});
});
});
});