From 3498ee2290f92a532e7bc700f000ee27b928d5b6 Mon Sep 17 00:00:00 2001 From: djhi Date: Wed, 15 Feb 2017 17:20:51 +0100 Subject: [PATCH] review --- makefile | 2 +- src/api/controller/api/fetchLineBy.js | 19 ++++++++++++------- src/api/controller/api/fetchLineBy.spec.js | 18 ++++++++++++++++-- src/api/controller/api/publish.js | 7 ++++++- src/api/controller/api/publish.spec.js | 9 ++++++++- src/app/e2e/admin/publication.js | 2 +- 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/makefile b/makefile index 18041fabf..5c4ec4766 100644 --- a/makefile +++ b/makefile @@ -76,7 +76,7 @@ test-frontend-unit: ## Run the frontend application unit tests "./src/app/js/**/*.spec.js" test-frontend-functional: ## Run the frontend application functional tests - # NODE_ENV=test ${MAKE} build-frontend + NODE_ENV=test ${MAKE} build-frontend NODE_ENV=test SELENIUM_BROWSER_BINARY_PATH="./node_modules/selenium-standalone/.selenium/chromedriver/2.24-x64-chromedriver" \ ./node_modules/.bin/mocha \ --require babel-polyfill \ diff --git a/src/api/controller/api/fetchLineBy.js b/src/api/controller/api/fetchLineBy.js index 5f99cfdee..9e0c8c449 100644 --- a/src/api/controller/api/fetchLineBy.js +++ b/src/api/controller/api/fetchLineBy.js @@ -1,8 +1,13 @@ -export default ctx => (fieldName, value) => - ctx.dataset +export default ctx => (fieldName, value) => ( + value + ? ctx.dataset .findBy(fieldName, value) - .then(line => ({ - ...line, - uri: `uri to ${fieldName}: ${value}`, - })) - .catch(() => null); + .then(line => ( + line + ? ({ + ...line, + uri: `uri to ${fieldName}: ${value}`, + }) + : null), + ) + : null); diff --git a/src/api/controller/api/fetchLineBy.spec.js b/src/api/controller/api/fetchLineBy.spec.js index d3945d200..0a4317739 100644 --- a/src/api/controller/api/fetchLineBy.spec.js +++ b/src/api/controller/api/fetchLineBy.spec.js @@ -35,13 +35,27 @@ describe('fetchLineBy', () => { }); }); - it('returns the line with a computed uri when ctx.dataset.findBy fails', async () => { + it('returns null when specified value is null', async () => { + const field = 'the field'; + const value = null; + + const ctx = { + dataset: { + findBy: createSpy().andReturn(Promise.resolve()), + }, + }; + + const result = await fetchLineBy(ctx)(field, value); + expect(result).toEqual(null); + }); + + it('returns null when referenced line is not found', async () => { const field = 'the field'; const value = 'the value'; const ctx = { dataset: { - findBy: createSpy().andReturn(Promise.reject()), + findBy: createSpy().andReturn(Promise.resolve()), }, }; diff --git a/src/api/controller/api/publish.js b/src/api/controller/api/publish.js index d8ba40925..4b9010530 100644 --- a/src/api/controller/api/publish.js +++ b/src/api/controller/api/publish.js @@ -39,6 +39,7 @@ export const publishCharacteristics = async (ctx, datasetCoverFields, count) => .getDocumentTransformer({ env: 'node', dataset: ctx.uriDataset, + fetchLineBy, }, datasetCoverFields); const [lastResource] = await ctx.uriDataset.findLimitFromSkip(1, count - 1); @@ -85,7 +86,11 @@ export const doPublish = async (ctx) => { const datasetCoverFields = fields.filter(c => c.cover === 'dataset'); const uriCol = fields.find(col => col.name === 'uri'); - const getUri = ctx.getDocumentTransformer({ env: 'node', dataset: ctx.dataset }, [uriCol]); + const getUri = ctx.getDocumentTransformer({ + env: 'node', + dataset: ctx.dataset, + fetchLineBy, + }, [uriCol]); const addUri = ctx.addTransformResultToDoc(getUri); await ctx.tranformAllDocuments( diff --git a/src/api/controller/api/publish.spec.js b/src/api/controller/api/publish.spec.js index 47e804250..4fe1a8469 100644 --- a/src/api/controller/api/publish.spec.js +++ b/src/api/controller/api/publish.spec.js @@ -11,6 +11,7 @@ import { publishCharacteristics, } from './publish'; import getDocumentTransformer from '../../../common/getDocumentTransformer'; +import fetchLineBy from './fetchLineBy'; describe('publish', () => { describe('doPublish', () => { @@ -64,7 +65,11 @@ describe('publish', () => { }); it('should call getDocumentTransformer to get the uri transformers', () => { - expect(ctx.getDocumentTransformer).toHaveBeenCalledWith({ env: 'node', dataset: ctx.dataset }, [fields[0]]); + expect(ctx.getDocumentTransformer).toHaveBeenCalledWith({ + env: 'node', + dataset: ctx.dataset, + fetchLineBy, + }, [fields[0]]); }); it('should call ctx.addTransformResultToDoc with transformDocument', () => { @@ -79,6 +84,7 @@ describe('publish', () => { expect(ctx.getDocumentTransformer).toHaveBeenCalledWith({ env: 'node', dataset: ctx.uriDataset, + fetchLineBy, }, [fields[1]]); }); @@ -129,6 +135,7 @@ describe('publish', () => { { env: 'node', dataset: ctx.uriDataset, + fetchLineBy, }, datasetFields, ); diff --git a/src/app/e2e/admin/publication.js b/src/app/e2e/admin/publication.js index 8d1099844..e49fde529 100644 --- a/src/app/e2e/admin/publication.js +++ b/src/app/e2e/admin/publication.js @@ -149,7 +149,7 @@ describe('Admin', () => { 'uri to id: 3', 'uri to id: 1', 'uri to id: 2', - 'uri to id: 5', + '', ]; await Promise.all(tds.map((td, index) => driver.wait(until.elementTextIs(td, expectedTexts[index]), DEFAULT_WAIT_TIMEOUT)),