From 3f7ae76aadf54f5359180ceb035bcb7f2b651057 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Thu, 29 Oct 2020 14:44:41 +0000 Subject: [PATCH 1/3] SDK-1800: Support media responses with no content --- src/doc_scan_service/doc.scan.service.js | 2 +- tests/doc_scan_service/doc.scan.service.spec.js | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/doc_scan_service/doc.scan.service.js b/src/doc_scan_service/doc.scan.service.js index 0625dfec..3edebb0a 100644 --- a/src/doc_scan_service/doc.scan.service.js +++ b/src/doc_scan_service/doc.scan.service.js @@ -158,7 +158,7 @@ class DocScanService { .then((response) => { try { const contentType = response.getHeaders()['content-type']; - const mimeType = contentType ? contentType.split(';')[0] : null; + const mimeType = contentType ? contentType.split(';')[0] : ''; let content = response.getBody(); if (!Buffer.isBuffer(content)) { diff --git a/tests/doc_scan_service/doc.scan.service.spec.js b/tests/doc_scan_service/doc.scan.service.spec.js index c9f53d7f..9d6774fe 100644 --- a/tests/doc_scan_service/doc.scan.service.spec.js +++ b/tests/doc_scan_service/doc.scan.service.spec.js @@ -299,16 +299,18 @@ describe('DocScanService', () => { }); }); - describe('when content type is not available', () => { - it('should reject', (done) => { + describe('when response has no content', () => { + it('should return empty media', (done) => { nock(config.yoti.docScanApi) .get(MEDIA_URI) - .reply(200, ''); + .reply(204, ''); docScanService .getMediaContent(SESSION_ID, MEDIA_ID) - .catch((err) => { - expect(err.message).toBe('mimeType must be a string'); + .then((result) => { + expect(result).toBeInstanceOf(Media); + expect(result.getContent().toBuffer()).toHaveLength(0); + expect(result.getMimeType()).toBe(''); done(); }) .catch(done); From 48b16df8613b649957ad8abcf8bf36291e3d9fda Mon Sep 17 00:00:00 2001 From: David Grayston Date: Thu, 29 Oct 2020 14:45:52 +0000 Subject: [PATCH 2/3] Bump patch version --- package-lock.json | 2 +- package.json | 2 +- sonar-project.properties | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 73b79447..07df3001 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "yoti", - "version": "3.13.0", + "version": "3.13.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 846e4bac..614f712e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yoti", - "version": "3.13.0", + "version": "3.13.1", "description": "Yoti NodeJS SDK for back-end integration", "author": "Yoti LTD (https://www.yoti.com/developers)", "license": "MIT", diff --git a/sonar-project.properties b/sonar-project.properties index a02c0044..f38fc803 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -3,8 +3,8 @@ sonar.organization = getyoti sonar.projectKey = getyoti:node sonar.projectName = Node SDK -sonar.projectVersion = 3.13.0 +sonar.projectVersion = 3.13.1 sonar.exclusions=tests/**,examples/**,node_modules/**,coverage/** sonar.javascript.lcov.reportPaths=coverage/lcov.info sonar.verbose = true -sonar.cpd.exclusions=**/supplementary.document.resource.response.js \ No newline at end of file +sonar.cpd.exclusions=**/supplementary.document.resource.response.js From fd01cefa6ddd2d3fb11d34dc2f6dd07b00be8809 Mon Sep 17 00:00:00 2001 From: David Grayston Date: Thu, 29 Oct 2020 15:10:43 +0000 Subject: [PATCH 3/3] SDK-1800: Update demo to support no content responses --- examples/doc-scan/src/controllers/index.controller.js | 8 +------- examples/doc-scan/src/controllers/media.controller.js | 10 ++++++++-- tests/doc_scan_service/doc.scan.service.spec.js | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/doc-scan/src/controllers/index.controller.js b/examples/doc-scan/src/controllers/index.controller.js index f0ab28c0..7fd26056 100644 --- a/examples/doc-scan/src/controllers/index.controller.js +++ b/examples/doc-scan/src/controllers/index.controller.js @@ -81,13 +81,7 @@ async function createSession() { .build() ) .withRequiredDocument( - (new RequiredIdDocumentBuilder()) - .withFilter( - (new OrthogonalRestrictionsFilterBuilder()) - .withWhitelistedDocumentTypes(['DRIVING_LICENCE']) - .build() - ) - .build() + (new RequiredIdDocumentBuilder()).build() ) .withRequiredDocument( (new RequiredSupplementaryDocumentBuilder()) diff --git a/examples/doc-scan/src/controllers/media.controller.js b/examples/doc-scan/src/controllers/media.controller.js index da51aa1a..635836d8 100644 --- a/examples/doc-scan/src/controllers/media.controller.js +++ b/examples/doc-scan/src/controllers/media.controller.js @@ -16,8 +16,14 @@ module.exports = async (req, res) => { req.query.mediaId ); - res.set('Content-Type', media.getMimeType()); - res.status(200).end(media.getContent().toBuffer()); + const { buffer } = media.getContent(); + + if (buffer.length === 0) { + res.status(204).end(buffer); + } else { + res.set('Content-Type', media.getMimeType()); + res.status(200).end(buffer); + } } catch (error) { res.render('pages/error', { error }); } diff --git a/tests/doc_scan_service/doc.scan.service.spec.js b/tests/doc_scan_service/doc.scan.service.spec.js index 9d6774fe..7c0ff0b4 100644 --- a/tests/doc_scan_service/doc.scan.service.spec.js +++ b/tests/doc_scan_service/doc.scan.service.spec.js @@ -309,7 +309,7 @@ describe('DocScanService', () => { .getMediaContent(SESSION_ID, MEDIA_ID) .then((result) => { expect(result).toBeInstanceOf(Media); - expect(result.getContent().toBuffer()).toHaveLength(0); + expect(result.getContent().buffer).toHaveLength(0); expect(result.getMimeType()).toBe(''); done(); })