Skip to content

Commit 302e4a6

Browse files
committed
All attributes of spec 0.1
Signed-off-by: Fabio José <[email protected]>
1 parent ff3ae0a commit 302e4a6

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

lib/specs/spec_0_1.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,28 @@ Spec_0_1.prototype.time = function(_time){
5757
return this;
5858
}
5959

60-
//TODO another attributes . . .
60+
Spec_0_1.prototype.schemaurl = function(_schemaurl){
61+
this.payload['schemaURL'] = _schemaurl;
62+
return this;
63+
}
64+
65+
Spec_0_1.prototype.contenttype = function(_contenttype){
66+
this.payload['contentType'] = _contenttype;
67+
return this;
68+
}
69+
70+
Spec_0_1.prototype.data = function(_data){
71+
this.payload['data'] = _data;
72+
return this;
73+
}
74+
75+
Spec_0_1.prototype.addExtension = function(key, value){
76+
if(!this.payload['extensions']){
77+
this.payload['extensions'] = {};
78+
}
79+
this.payload['extensions'][key] = value;
80+
return this;
81+
}
6182

6283
module.exports = Spec_0_1;
6384

test/cloudevent_spec_0_1.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ var Cloudevent = require("../index.js");
44
const type = "com.github.pull.create";
55
const source = "urn:event:from:myapi/resourse/123";
66
const time = new Date();
7+
const schemaurl = "http://example.com/registry/myschema.json";
8+
const contenttype = "application/json";
9+
const data = {};
10+
const extensions = {};
711

812
var cloudevent = new Cloudevent()
913
.type(type)
@@ -18,6 +22,11 @@ describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
1822
expect(cloudevent.format()).to.have.property('eventType');
1923
});
2024

25+
it("requires 'eventTypeVersion'", () => {
26+
cloudevent.eventTypeVersion("1.0");
27+
expect(cloudevent.format()).to.have.property('eventTypeVersion');
28+
});
29+
2130
it("requires 'cloudEventsVersion'", () => {
2231
expect(cloudevent.format()).to.have.property('cloudEventsVersion');
2332
});
@@ -31,11 +40,38 @@ describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
3140
});
3241
});
3342

34-
describe("Backward compatibility", () => {
35-
it("should have 'eventTypeVersion'", () => {
36-
cloudevent.eventTypeVersion("1.0");
37-
expect(cloudevent.format()).to.have.property('eventTypeVersion');
43+
describe("Optional context attributes", () => {
44+
it("contains 'eventTime'", () => {
45+
cloudevent.time(time);
46+
expect(cloudevent.format()).to.have.property('eventTime');
47+
});
48+
49+
it("contains 'schemaURL'", () => {
50+
cloudevent.schemaurl(schemaurl);
51+
expect(cloudevent.format()).to.have.property('schemaURL');
52+
});
53+
54+
it("contains 'contentType'", () => {
55+
cloudevent.contenttype(contenttype);
56+
expect(cloudevent.format()).to.have.property('contentType');
57+
});
58+
59+
it("contains 'data'", () => {
60+
cloudevent.data(data);
61+
expect(cloudevent.format()).to.have.property('data');
62+
});
63+
64+
it("contains 'extensions'", () => {
65+
cloudevent.addExtension('foo', 'value');
66+
expect(cloudevent.format()).to.have.property('extensions');
67+
});
68+
69+
it("'extensions' should have 'bar' extension", () => {
70+
cloudevent.addExtension('bar', 'value');
71+
expect(cloudevent.format().extensions)
72+
.to.have.property('foo');
3873
});
74+
3975
});
4076

4177
describe("The Constraint check", () => {

0 commit comments

Comments
 (0)