Skip to content

Commit 3b732a0

Browse files
committed
Unit testing for eventType constraints in 0.1
Signed-off-by: Fabio José <[email protected]>
1 parent 46c7946 commit 3b732a0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

lib/specs/spec_0_1.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ function Spec_0_1(_caller){
2626
*/
2727
Spec_0_1.prototype.check = function() {
2828

29+
if(!this.payload['eventType']){
30+
throw {message: "'eventType' is invalid"};
31+
}
32+
2933
}
3034

3135
Spec_0_1.prototype.type = function(_type){

test/cloudevent_spec_0_1.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
var expect = require("chai").expect;
22
var Cloudevent = require("../index.js");
33

4+
const type = "com.github.pull.create";
5+
46
var cloudevent = new Cloudevent()
5-
.type("com.github.pull.create")
7+
.type(type)
68
.source("urn:event:from:myapi/resourse/123");
79

810
describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
@@ -34,6 +36,20 @@ describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
3436
});
3537
});
3638

39+
describe("The Constraint check", () => {
40+
describe("'eventType'", () => {
41+
it("should throw an error when is an empty string", () => {
42+
cloudevent.type("");
43+
expect(cloudevent.format.bind(cloudevent)).to.throw("'eventType' is invalid");
44+
});
45+
46+
it("should be a non-empty string", () => {
47+
cloudevent.type(type);
48+
cloudevent.format();
49+
});
50+
});
51+
});
52+
3753
});
3854

3955
});

0 commit comments

Comments
 (0)