HTTP Binding Structured 0.2 impl
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
e3b2ce6b52
commit
b976273260
|
@ -0,0 +1,23 @@
|
|||
var axios = require("axios");
|
||||
|
||||
function HTTPStructured(configuration){
|
||||
this.config = configuration;
|
||||
|
||||
this.config["headers"] = {
|
||||
"Content-Type":"application/cloudevents+json; charset=utf-8"
|
||||
};
|
||||
}
|
||||
|
||||
HTTPStructured.prototype.emit = function(cloudevent){
|
||||
|
||||
// Create new request object
|
||||
var _config = JSON.parse(JSON.stringify(this.config));
|
||||
|
||||
// Set the cloudevent payload
|
||||
_config["data"] = cloudevent.format();
|
||||
|
||||
// Return the Promise
|
||||
return axios.request(_config);
|
||||
};
|
||||
|
||||
module.exports = HTTPStructured;
|
|
@ -2,6 +2,7 @@ var Spec01 = require("./specs/spec_0_1.js");
|
|||
var Spec02 = require("./specs/spec_0_2.js");
|
||||
var JSONFormatter01 = require("./formats/json_0_1.js");
|
||||
var HTTPStructured01 = require("./bindings/http/structured_0_1.js");
|
||||
var HTTPStructured02 = require("./bindings/http/structured_0_2.js");
|
||||
var HTTPBinary01 = require("./bindings/http/binary_0_1.js");
|
||||
var HTTPBinary02 = require("./bindings/http/binary_0_2.js");
|
||||
|
||||
|
@ -122,6 +123,7 @@ Cloudevent.formats = {
|
|||
Cloudevent.bindings = {
|
||||
"http-structured" : HTTPStructured01,
|
||||
"http-structured0.1" : HTTPStructured01,
|
||||
"http-structured0.2" : HTTPStructured02,
|
||||
"http-binary0.1" : HTTPBinary01,
|
||||
"http-binary0.2" : HTTPBinary02
|
||||
};
|
||||
|
|
|
@ -15,7 +15,7 @@ const data = {
|
|||
foo: "bar"
|
||||
};
|
||||
|
||||
const Structured01 = Cloudevent.bindings["http-structured0.1"];
|
||||
const Structured02 = Cloudevent.bindings["http-structured0.2"];
|
||||
const Binary02 = Cloudevent.bindings["http-binary0.2"];
|
||||
|
||||
var cloudevent =
|
||||
|
@ -27,14 +27,12 @@ var cloudevent =
|
|||
.schemaurl(schemaurl)
|
||||
.data(data);
|
||||
|
||||
cloudevent.eventTypeVersion("1.0.0");
|
||||
|
||||
var httpcfg = {
|
||||
method : "POST",
|
||||
url : webhook + "/json"
|
||||
};
|
||||
|
||||
var httpstructured01 = new Structured01(httpcfg);
|
||||
var httpstructured02 = new Structured02(httpcfg);
|
||||
var httpbinary02 = new Binary02(httpcfg);
|
||||
|
||||
describe("HTTP Transport Binding - Version 0.2", () => {
|
||||
|
@ -48,7 +46,7 @@ describe("HTTP Transport Binding - Version 0.2", () => {
|
|||
describe("Structured", () => {
|
||||
describe("JSON Format", () => {
|
||||
it("requires '" + contentType + "' Content-Type in the header", () => {
|
||||
return httpstructured01.emit(cloudevent)
|
||||
return httpstructured02.emit(cloudevent)
|
||||
.then((response) => {
|
||||
expect(response.config.headers["Content-Type"])
|
||||
.to.equal(contentType);
|
||||
|
@ -56,7 +54,7 @@ describe("HTTP Transport Binding - Version 0.2", () => {
|
|||
});
|
||||
|
||||
it("the request payload should be correct", () => {
|
||||
return httpstructured01.emit(cloudevent)
|
||||
return httpstructured02.emit(cloudevent)
|
||||
.then((response) => {
|
||||
expect(JSON.parse(response.config.data))
|
||||
.to.deep.equal(cloudevent.format());
|
||||
|
|
Loading…
Reference in New Issue