Merge branch 'develop'
This commit is contained in:
commit
a39e895ece
|
@ -120,6 +120,11 @@ var config = {
|
||||||
url : "https://myserver.com"
|
url : "https://myserver.com"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To use HTTP Binary:
|
||||||
|
* Cloudevent.bindings["http-binary0.2"](config);
|
||||||
|
*/
|
||||||
|
|
||||||
// The binding instance
|
// The binding instance
|
||||||
var binding = Cloudevent.bindings["http-structured0.1"](config);
|
var binding = Cloudevent.bindings["http-structured0.1"](config);
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,9 @@
|
||||||
"time": {
|
"time": {
|
||||||
"$ref": "#/definitions/time"
|
"$ref": "#/definitions/time"
|
||||||
},
|
},
|
||||||
|
"schemaurl": {
|
||||||
|
"$ref": "#/definitions/schemaurl"
|
||||||
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"$ref": "#/definitions/type"
|
"$ref": "#/definitions/type"
|
||||||
},
|
},
|
||||||
|
@ -58,6 +61,10 @@
|
||||||
"format": "date-time",
|
"format": "date-time",
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"schemaurl": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "uri"
|
||||||
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"minLength": 1
|
"minLength": 1
|
||||||
|
|
|
@ -16,8 +16,9 @@ const reserved = {
|
||||||
|
|
||||||
const schema = require("../../ext/spec_0_2.json");
|
const schema = require("../../ext/spec_0_2.json");
|
||||||
|
|
||||||
// Default options
|
const ajv = new Ajv({
|
||||||
const ajv = new Ajv();
|
extendRefs: true // validate all keywords in the schemas with $ref (the default behaviour in versions before 5.0.0)
|
||||||
|
});
|
||||||
|
|
||||||
const validate = ajv.compile(schema);
|
const validate = ajv.compile(schema);
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ Spec02.prototype.check = function(){
|
||||||
var valid = validate(this.payload);
|
var valid = validate(this.payload);
|
||||||
|
|
||||||
if(!valid) {
|
if(!valid) {
|
||||||
throw {message: "invalid payload"};
|
throw {message: "invalid payload", errors: validate.errors};
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,6 +40,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
|
||||||
expect(cloudevent.format()).to.have.property("specversion");
|
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'", () => {
|
it("requires 'source'", () => {
|
||||||
expect(cloudevent.format()).to.have.property("source");
|
expect(cloudevent.format()).to.have.property("source");
|
||||||
});
|
});
|
||||||
|
@ -60,6 +68,14 @@ describe("CloudEvents Spec 0.2 - JavaScript SDK", () => {
|
||||||
expect(cloudevent.format()).to.have.property("schemaurl");
|
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'", () => {
|
it("contains 'contenttype'", () => {
|
||||||
cloudevent.contenttype(contenttype);
|
cloudevent.contenttype(contenttype);
|
||||||
expect(cloudevent.format()).to.have.property("contenttype");
|
expect(cloudevent.format()).to.have.property("contenttype");
|
||||||
|
|
Loading…
Reference in New Issue