From 3dd2993e5a78216777f0fae6b26bc9774403a632 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Fri, 24 May 2019 09:17:28 -0300 Subject: [PATCH] More test cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- test/cloudevent_spec_0_2.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test/cloudevent_spec_0_2.js b/test/cloudevent_spec_0_2.js index 6c7102c..733a00e 100644 --- a/test/cloudevent_spec_0_2.js +++ b/test/cloudevent_spec_0_2.js @@ -9,7 +9,7 @@ const contenttype = "application/json"; const data = {}; const extensions = {}; -var cloudevent = +var cloudevent = new Cloudevent(Cloudevent.specs["0.2"]) .type(type) .source(source); @@ -27,6 +27,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => { expect(cloudevent.format()).to.have.property("specversion"); }); + it("should throw an error when mandatory attribute is absent", () => { + delete cloudevent.spec.payload.source; + expect(cloudevent.format.bind(cloudevent)) + .to + .throw("invalid payload"); + cloudevent.spec.payload.source = source; + }); + it("requires 'source'", () => { expect(cloudevent.format()).to.have.property("source"); }); @@ -47,6 +55,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => { expect(cloudevent.format()).to.have.property("schemaurl"); }); + it("should throw an error when 'schemaurl' is not an URI", () => { + cloudevent.spec.payload.schemaurl = "KKKKKK"; + expect(cloudevent.format.bind(cloudevent)) + .to + .throw("invalid payload"); + cloudevent.spec.payload.schemaurl = schemaurl; + }); + it("contains 'contenttype'", () => { cloudevent.contenttype(contenttype); expect(cloudevent.format()).to.have.property("contenttype"); @@ -68,8 +84,8 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => { }); it("should throw an error when employ reserved name as extension", () => { - - var cevt = + + var cevt = new Cloudevent(Cloudevent.specs["0.2"]) .type(type) .source(source);