More test cases

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-05-24 09:17:28 -03:00
parent 30796b2147
commit 3dd2993e5a
1 changed files with 19 additions and 3 deletions

View File

@ -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);