diff --git a/lib/specs/spec_0_1.js b/lib/specs/spec_0_1.js index 3d87770..c7f5cc6 100644 --- a/lib/specs/spec_0_1.js +++ b/lib/specs/spec_0_1.js @@ -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){ diff --git a/test/cloudevent_spec_0_1.js b/test/cloudevent_spec_0_1.js index af391bf..aff92ea 100644 --- a/test/cloudevent_spec_0_1.js +++ b/test/cloudevent_spec_0_1.js @@ -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(); + }); + }); + }); + }); });