http strutured: handle for data_base64
Signed-off-by: Fabio José <fabiojose@gmail.com>
This commit is contained in:
parent
49f4d5ec23
commit
4648305a77
|
@ -55,6 +55,10 @@ setterByAttribute[Constants.STRUCTURED_ATTRS_1.DATA] = {
|
|||
name: "data",
|
||||
parser: (v) => v
|
||||
};
|
||||
setterByAttribute[Constants.STRUCTURED_ATTRS_1.DATA_BASE64] = {
|
||||
name: "data",
|
||||
parser: (v) => v
|
||||
};
|
||||
|
||||
function Receiver(configuration) {
|
||||
this.receiver = new StructuredHTTPReceiver(
|
||||
|
|
|
@ -3,6 +3,8 @@ var v1 = require("../../../v1/index.js");
|
|||
var Cloudevent = require("../../../index.js");
|
||||
var Spec = require("../../../lib/specs/spec_1.js");
|
||||
|
||||
const {asBase64} = require("../../../lib/utils/fun.js");
|
||||
|
||||
var HTTPStructuredReceiver =
|
||||
require("../../../lib/bindings/http/receiver_structured_1.js");
|
||||
|
||||
|
@ -181,5 +183,31 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0", () =
|
|||
// assert
|
||||
expect(actual.getData()).to.deep.equal(data);
|
||||
});
|
||||
|
||||
it("Should maps 'data_base64' to 'data' attribute", () => {
|
||||
// setup
|
||||
let bindata = Uint32Array.from(JSON.stringify(data), (c) => c.codePointAt(0));
|
||||
let expected = asBase64(bindata);
|
||||
let payload = v1.event()
|
||||
.type(type)
|
||||
.source(source)
|
||||
.dataContentType(ceContentType)
|
||||
.data(bindata)
|
||||
.format();
|
||||
|
||||
console.log(payload);
|
||||
|
||||
var headers = {
|
||||
"content-type":"application/cloudevents+json"
|
||||
};
|
||||
|
||||
// act
|
||||
var actual = receiver.parse(JSON.stringify(payload), headers);
|
||||
|
||||
console.log(actual);
|
||||
|
||||
// assert
|
||||
expect(actual.getData()).to.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -108,7 +108,6 @@ describe("HTTP Transport Binding - Version 1.0", () => {
|
|||
|
||||
return structured.emit(binevent)
|
||||
.then((response) => {
|
||||
console.log(response.config.data);
|
||||
expect(JSON.parse(response.config.data))
|
||||
.to.have.property("data_base64");
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue