From f599f7ab61f3e1aca2130e5bb78d8e1a6d4b0204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabio=20Jos=C3=A9?= Date: Tue, 6 Aug 2019 11:20:59 -0300 Subject: [PATCH] Fixes how to do tests with Promise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabio José --- test/bindings/http/unmarshaller_0_3_tests.js | 65 ++++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/test/bindings/http/unmarshaller_0_3_tests.js b/test/bindings/http/unmarshaller_0_3_tests.js index b95f833..421b194 100644 --- a/test/bindings/http/unmarshaller_0_3_tests.js +++ b/test/bindings/http/unmarshaller_0_3_tests.js @@ -1,7 +1,7 @@ var expect = require("chai").expect; var Unmarshaller = require("../../../lib/bindings/http/unmarshaller_0_3.js"); var Cloudevent = require("../../../index.js"); -var {Spec03} = require("../../../v03/index.js"); +var v03 = require("../../../v03/index.js"); const type = "com.github.pull.create"; const source = "urn:event:from:myapi/resourse/123"; @@ -115,7 +115,7 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => { it("Should accept event that follow the spec 0.3", () => { // setup var payload = - new Cloudevent(Spec03) + new Cloudevent(v03.Spec) .type(type) .source(source) .contenttype(ceContentType) @@ -131,9 +131,13 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => { var un = new Unmarshaller(); // act and assert - un.unmarshall(payload, headers) + return un.unmarshall(payload, headers) .then(actual => - expect(actual).to.be.an("object")); + expect(actual).to.be.an("object")) + .catch((err) => { + console.log(err); + throw err; + }); }); }); @@ -208,7 +212,60 @@ describe("HTTP Transport Binding Unmarshaller for CloudEvents v0.3", () => { // act and assert un.unmarshall(payload, attributes) .then(actual => expect(actual).to.be.an("object")); + }); + it("Throw error when 'ce-datacontentencoding' is not allowed", () => { + // setup + var payload = "eyJtdWNoIjoid293In0="; + + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.3", + "ce-source" : "source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1", + "Content-Type" : "application/json", + "ce-datacontentencoding" : "binary" + }; + + var un = new Unmarshaller(); + + // act and assert + return un.unmarshall(payload, attributes) + .then(actual => {throw {message: "failed"}}) + .catch(err => { + expect(err.message).to.equal("unsupported datacontentencoding"); + }); + }); + + it("No error when 'ce-datacontentencoding' is base64", () => { + // setup + var payload = "eyJtdWNoIjoid293In0="; + let expected = { + much : "wow" + }; + + var attributes = { + "ce-type" : "type", + "ce-specversion" : "0.3", + "ce-source" : "source", + "ce-id" : "id", + "ce-time" : "2019-06-16T11:42:00Z", + "ce-schemaurl" : "http://schema.registry/v1", + "Content-Type" : "application/json", + "ce-datacontentencoding" : "base64" + }; + + var un = new Unmarshaller(); + + // act and assert + return un.unmarshall(payload, attributes) + .then(actual => expect(actual.getData()).to.deep.equal(expected)) + .catch(err => { + console.log(err); + throw err; + }); }); }); });