-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from Inist-CNRS/fix_link_function_publish
[RFR] Fix LINK function when reference is null
- Loading branch information
Showing
9 changed files
with
113 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default ctx => (fieldName, value) => ( | ||
value | ||
? ctx.dataset | ||
.findBy(fieldName, value) | ||
.then(line => ( | ||
line | ||
? ({ | ||
...line, | ||
uri: `uri to ${fieldName}: ${value}`, | ||
}) | ||
: null), | ||
) | ||
: null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import expect, { createSpy } from 'expect'; | ||
import fetchLineBy from './fetchLineBy'; | ||
|
||
describe('fetchLineBy', () => { | ||
it('calls ctx.dataset.findBy', () => { | ||
const line = { data: 'the line' }; | ||
const field = 'the field'; | ||
const value = 'the value'; | ||
|
||
const ctx = { | ||
dataset: { | ||
findBy: createSpy().andReturn(Promise.resolve(line)), | ||
}, | ||
}; | ||
|
||
fetchLineBy(ctx)(field, value); | ||
expect(ctx.dataset.findBy).toHaveBeenCalledWith(field, value); | ||
}); | ||
|
||
it('returns the line with a computed uri when ctx.dataset.findBy succeeds', async () => { | ||
const line = { data: 'the line' }; | ||
const field = 'the field'; | ||
const value = 'the value'; | ||
|
||
const ctx = { | ||
dataset: { | ||
findBy: createSpy().andReturn(Promise.resolve(line)), | ||
}, | ||
}; | ||
|
||
const result = await fetchLineBy(ctx)(field, value); | ||
expect(result).toEqual({ | ||
...line, | ||
uri: `uri to ${field}: ${value}`, | ||
}); | ||
}); | ||
|
||
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.resolve()), | ||
}, | ||
}; | ||
|
||
const result = await fetchLineBy(ctx)(field, value); | ||
expect(result).toEqual(null); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
"1";"rock";"3"; | ||
"2";"paper";"1"; | ||
"3";"scissor";"2"; | ||
"4";"invalid_reference";"5"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import fetchLineBy from '../../app/js/lib/fetchLineBy'; | ||
|
||
export default (context, targetColumn) => async (prev) => { | ||
if (context.env === 'node') { | ||
return context.dataset.findBy(targetColumn, prev); | ||
} | ||
|
||
return fetchLineBy(targetColumn, prev, context.token); | ||
return context.fetchLineBy(targetColumn, prev, context.token); | ||
}; |