From 4648305a779a3cb660363d60cba8678510f94365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Mon, 4 Nov 2019 14:08:49 -0300 Subject: [PATCH] http strutured: handle for data_base64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- lib/bindings/http/receiver_structured_1.js | 4 +++ .../http/receiver_structured_1_test.js | 28 +++++++++++++++++++ test/http_binding_1.js | 1 - 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/bindings/http/receiver_structured_1.js b/lib/bindings/http/receiver_structured_1.js index 89681bd..d8ef328 100644 --- a/lib/bindings/http/receiver_structured_1.js +++ b/lib/bindings/http/receiver_structured_1.js @@ -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( diff --git a/test/bindings/http/receiver_structured_1_test.js b/test/bindings/http/receiver_structured_1_test.js index c0493fe..531a68a 100644 --- a/test/bindings/http/receiver_structured_1_test.js +++ b/test/bindings/http/receiver_structured_1_test.js @@ -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); + }); }); }); diff --git a/test/http_binding_1.js b/test/http_binding_1.js index 47ada93..20dfcb6 100644 --- a/test/http_binding_1.js +++ b/test/http_binding_1.js @@ -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"); });