From 986449d46eb51585293d38fa31cba1e72146c59b Mon Sep 17 00:00:00 2001 From: Rui Gil Date: Mon, 15 May 2017 12:02:12 +0100 Subject: [PATCH] Fix null contentType in negotiateDecoder --- lib/utils.js | 2 +- tests/utils.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index a969bb6..60b127f 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -14,7 +14,7 @@ const determineTransport = function (transports, url) { } const negotiateDecoder = function (decoders, contentType) { - if (contentType === undefined) { + if (contentType === undefined || contentType === null) { return decoders[0] } diff --git a/tests/utils.js b/tests/utils.js index eb88558..fe31ec3 100644 --- a/tests/utils.js +++ b/tests/utils.js @@ -29,6 +29,12 @@ describe('Test the Utils/negotiateDecoder function', function () { expect(result instanceof coreapi.codecs.CoreJSONCodec).toBeTruthy() }) + it('should return the default decoder if content type is null', function () { + const contentType = null + const result = utils.negotiateDecoder(decoders, contentType) + expect(result instanceof coreapi.codecs.CoreJSONCodec).toBeTruthy() + }) + it('should return the decoder for a content type (application/json)', function () { const contentType = 'application/json' const result = utils.negotiateDecoder(decoders, contentType)