Test the extensions

Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
Fabio José 2019-01-18 23:42:43 -02:00
parent 177bac8c38
commit 1a81e6e7e1
3 changed files with 40 additions and 1 deletions

View File

@ -1,4 +1,5 @@
var axios = require("axios");
var empty = require("is-empty");
function HTTPBinary(configuration){
this.config = configuration;
@ -32,6 +33,12 @@ HTTPBinary.prototype.emit = function(cloudevent){
// Set the cloudevent payload
_config["data"] = cloudevent.format().data;
// Have extensions?
var exts = cloudevent.getExtensions();
for(ext in exts){
_headers["ce-" + ext] = exts[ext];
}
// Return the Promise
return axios.request(_config);
};

View File

@ -14,6 +14,9 @@ var HTTPBinary02 = require("./bindings/http/binary_0_2.js");
function Cloudevent(_spec, _formatter){
this.spec = (_spec) ? new _spec(Cloudevent) : new Spec01(Cloudevent);
this.formatter = (_formatter) ? _formatter : new JSONFormatter01();
// The map of extensions
this.extensions = {};
}
/*
@ -100,9 +103,17 @@ Cloudevent.prototype.getData = function() {
Cloudevent.prototype.addExtension = function(key, value){
this.spec.addExtension(key, value);
// Stores localy
this.extensions[key] = value;
return this;
};
Cloudevent.prototype.getExtensions = function() {
return this.extensions;
}
/*
* Export the specs

View File

@ -15,6 +15,11 @@ const data = {
foo: "bar"
};
const ext1Name = "extension1";
const ext1Value = "foobar";
const ext2Name = "extension2";
const ext2Value = "acme";
const Structured02 = Cloudevent.bindings["http-structured0.2"];
const Binary02 = Cloudevent.bindings["http-binary0.2"];
@ -25,7 +30,9 @@ var cloudevent =
.contenttype(ceContentType)
.time(now)
.schemaurl(schemaurl)
.data(data);
.data(data)
.addExtension(ext1Name, ext1Value)
.addExtension(ext2Name, ext2Value);
var httpcfg = {
method : "POST",
@ -123,6 +130,20 @@ describe("HTTP Transport Binding - Version 0.2", () => {
.to.have.property("ce-schemaurl");
});
});
it("HTTP Header contains 'ce-" + ext1Name + "'", () => {
return httpbinary02.emit(cloudevent)
.then((response) => {
expect(response.config.headers)
.to.have.property("ce-" + ext1Name);
});
});
it("HTTP Header contains 'ce-" + ext2Name + "'", () => {
return httpbinary02.emit(cloudevent)
.then((response) => {
expect(response.config.headers)
.to.have.property("ce-" + ext2Name);
});
});
});
});
});