Skip to content

Commit 3dd2993

Browse files
committed
More test cases
Signed-off-by: Fabio José <[email protected]>
1 parent 30796b2 commit 3dd2993

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/cloudevent_spec_0_2.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const contenttype = "application/json";
99
const data = {};
1010
const extensions = {};
1111

12-
var cloudevent =
12+
var cloudevent =
1313
new Cloudevent(Cloudevent.specs["0.2"])
1414
.type(type)
1515
.source(source);
@@ -27,6 +27,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
2727
expect(cloudevent.format()).to.have.property("specversion");
2828
});
2929

30+
it("should throw an error when mandatory attribute is absent", () => {
31+
delete cloudevent.spec.payload.source;
32+
expect(cloudevent.format.bind(cloudevent))
33+
.to
34+
.throw("invalid payload");
35+
cloudevent.spec.payload.source = source;
36+
});
37+
3038
it("requires 'source'", () => {
3139
expect(cloudevent.format()).to.have.property("source");
3240
});
@@ -47,6 +55,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
4755
expect(cloudevent.format()).to.have.property("schemaurl");
4856
});
4957

58+
it("should throw an error when 'schemaurl' is not an URI", () => {
59+
cloudevent.spec.payload.schemaurl = "KKKKKK";
60+
expect(cloudevent.format.bind(cloudevent))
61+
.to
62+
.throw("invalid payload");
63+
cloudevent.spec.payload.schemaurl = schemaurl;
64+
});
65+
5066
it("contains 'contenttype'", () => {
5167
cloudevent.contenttype(contenttype);
5268
expect(cloudevent.format()).to.have.property("contenttype");
@@ -68,8 +84,8 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
6884
});
6985

7086
it("should throw an error when employ reserved name as extension", () => {
71-
72-
var cevt =
87+
88+
var cevt =
7389
new Cloudevent(Cloudevent.specs["0.2"])
7490
.type(type)
7591
.source(source);

0 commit comments

Comments
 (0)