Skip to content

Commit 4648305

Browse files
committed
http strutured: handle for data_base64
Signed-off-by: Fabio José <[email protected]>
1 parent 49f4d5e commit 4648305

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/bindings/http/receiver_structured_1.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ setterByAttribute[Constants.STRUCTURED_ATTRS_1.DATA] = {
5555
name: "data",
5656
parser: (v) => v
5757
};
58+
setterByAttribute[Constants.STRUCTURED_ATTRS_1.DATA_BASE64] = {
59+
name: "data",
60+
parser: (v) => v
61+
};
5862

5963
function Receiver(configuration) {
6064
this.receiver = new StructuredHTTPReceiver(

test/bindings/http/receiver_structured_1_test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ var v1 = require("../../../v1/index.js");
33
var Cloudevent = require("../../../index.js");
44
var Spec = require("../../../lib/specs/spec_1.js");
55

6+
const {asBase64} = require("../../../lib/utils/fun.js");
7+
68
var HTTPStructuredReceiver =
79
require("../../../lib/bindings/http/receiver_structured_1.js");
810

@@ -181,5 +183,31 @@ describe("HTTP Transport Binding Structured Receiver for CloudEvents v1.0", () =
181183
// assert
182184
expect(actual.getData()).to.deep.equal(data);
183185
});
186+
187+
it("Should maps 'data_base64' to 'data' attribute", () => {
188+
// setup
189+
let bindata = Uint32Array.from(JSON.stringify(data), (c) => c.codePointAt(0));
190+
let expected = asBase64(bindata);
191+
let payload = v1.event()
192+
.type(type)
193+
.source(source)
194+
.dataContentType(ceContentType)
195+
.data(bindata)
196+
.format();
197+
198+
console.log(payload);
199+
200+
var headers = {
201+
"content-type":"application/cloudevents+json"
202+
};
203+
204+
// act
205+
var actual = receiver.parse(JSON.stringify(payload), headers);
206+
207+
console.log(actual);
208+
209+
// assert
210+
expect(actual.getData()).to.equal(expected);
211+
});
184212
});
185213
});

test/http_binding_1.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ describe("HTTP Transport Binding - Version 1.0", () => {
108108

109109
return structured.emit(binevent)
110110
.then((response) => {
111-
console.log(response.config.data);
112111
expect(JSON.parse(response.config.data))
113112
.to.have.property("data_base64");
114113
});

0 commit comments

Comments
 (0)