All attributes of spec 0.1

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2018-12-05 22:52:29 -02:00
parent ff3ae0a343
commit 302e4a653b
2 changed files with 62 additions and 5 deletions

View File

@ -57,7 +57,28 @@ Spec_0_1.prototype.time = function(_time){
return this;
}
//TODO another attributes . . .
Spec_0_1.prototype.schemaurl = function(_schemaurl){
this.payload['schemaURL'] = _schemaurl;
return this;
}
Spec_0_1.prototype.contenttype = function(_contenttype){
this.payload['contentType'] = _contenttype;
return this;
}
Spec_0_1.prototype.data = function(_data){
this.payload['data'] = _data;
return this;
}
Spec_0_1.prototype.addExtension = function(key, value){
if(!this.payload['extensions']){
this.payload['extensions'] = {};
}
this.payload['extensions'][key] = value;
return this;
}
module.exports = Spec_0_1;

View File

@ -4,6 +4,10 @@ var Cloudevent = require("../index.js");
const type = "com.github.pull.create";
const source = "urn:event:from:myapi/resourse/123";
const time = new Date();
const schemaurl = "http://example.com/registry/myschema.json";
const contenttype = "application/json";
const data = {};
const extensions = {};
var cloudevent = new Cloudevent()
.type(type)
@ -18,6 +22,11 @@ describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
expect(cloudevent.format()).to.have.property('eventType');
});
it("requires 'eventTypeVersion'", () => {
cloudevent.eventTypeVersion("1.0");
expect(cloudevent.format()).to.have.property('eventTypeVersion');
});
it("requires 'cloudEventsVersion'", () => {
expect(cloudevent.format()).to.have.property('cloudEventsVersion');
});
@ -31,11 +40,38 @@ describe("CloudEvents Spec 0.1 - JavaScript SDK", () => {
});
});
describe("Backward compatibility", () => {
it("should have 'eventTypeVersion'", () => {
cloudevent.eventTypeVersion("1.0");
expect(cloudevent.format()).to.have.property('eventTypeVersion');
describe("Optional context attributes", () => {
it("contains 'eventTime'", () => {
cloudevent.time(time);
expect(cloudevent.format()).to.have.property('eventTime');
});
it("contains 'schemaURL'", () => {
cloudevent.schemaurl(schemaurl);
expect(cloudevent.format()).to.have.property('schemaURL');
});
it("contains 'contentType'", () => {
cloudevent.contenttype(contenttype);
expect(cloudevent.format()).to.have.property('contentType');
});
it("contains 'data'", () => {
cloudevent.data(data);
expect(cloudevent.format()).to.have.property('data');
});
it("contains 'extensions'", () => {
cloudevent.addExtension('foo', 'value');
expect(cloudevent.format()).to.have.property('extensions');
});
it("'extensions' should have 'bar' extension", () => {
cloudevent.addExtension('bar', 'value');
expect(cloudevent.format().extensions)
.to.have.property('foo');
});
});
describe("The Constraint check", () => {