From 3b732a03086706e3f6f07c15737043cdc5453b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Fri, 9 Nov 2018 16:50:54 -0200 Subject: [PATCH] Unit testing for eventType constraints in 0.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/specs/spec_0_1.js | 4 ++++ test/cloudevent_spec_0_1.js | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) 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(); + }); + }); + }); + }); });