Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
djhi committed Feb 15, 2017
1 parent d908cbd commit 3498ee2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
19 changes: 12 additions & 7 deletions src/api/controller/api/fetchLineBy.js
Original file line number Diff line number Diff line change
@@ -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);
18 changes: 16 additions & 2 deletions src/api/controller/api/fetchLineBy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
};

Expand Down
7 changes: 6 additions & 1 deletion src/api/controller/api/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 8 additions & 1 deletion src/api/controller/api/publish.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
publishCharacteristics,
} from './publish';
import getDocumentTransformer from '../../../common/getDocumentTransformer';
import fetchLineBy from './fetchLineBy';

describe('publish', () => {
describe('doPublish', () => {
Expand Down Expand Up @@ -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', () => {
Expand All @@ -79,6 +84,7 @@ describe('publish', () => {
expect(ctx.getDocumentTransformer).toHaveBeenCalledWith({
env: 'node',
dataset: ctx.uriDataset,
fetchLineBy,
}, [fields[1]]);
});

Expand Down Expand Up @@ -129,6 +135,7 @@ describe('publish', () => {
{
env: 'node',
dataset: ctx.uriDataset,
fetchLineBy,
},
datasetFields,
);
Expand Down
2 changes: 1 addition & 1 deletion src/app/e2e/admin/publication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit 3498ee2

Please sign in to comment.