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
const config = { | |
host: 'http://localhost:3010', | |
endpoint: 'data', | |
method: 'GET', | |
headers: { 'content-type': 'application/json' }, | |
contract: { | |
type: 'class', | |
description: 'report', | |
location: 'address', | |
distance: 'range' |
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
test('mapResponse() should map a given body response to the structure desired', async function ({ deepEqual, end }) { | |
const payload = { | |
data: { | |
config: { | |
contract: { x: 'a', y: 'b' } | |
}, | |
response: { | |
body: [ | |
{ a: 1, b: 2 }, | |
{ a: 3, b: 4 }, |
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
app.get('/stores', async (req, res) => { | |
const config = { | |
host: 'http://localhost:3010', | |
endpoint: 'data', | |
method: 'GET', | |
headers: { 'content-type': 'application/json' }, | |
contract: { | |
type: 'class', | |
description: 'report', | |
location: 'address', |
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
function createResult (payload) { | |
const newPayload = cloneDeep(payload) | |
const data = get(newPayload, 'data.mappedResponse') | |
const result = { | |
data, | |
metadata: {} | |
} | |
return set(newPayload, 'result', result) | |
} |
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
{ | |
data, | |
metadata | |
} | |
test('createResult() should produce a formatted structure to use as response', async function ({ deepEqual, end }) { | |
const payload = { | |
data: { | |
mappedResponse: [ | |
{ x: 1, y: 2 }, |
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
test('mapResponse() should map a given body response to the structure desired', async function ({ deepEqual, end }) { | |
const payload = { | |
data: { | |
config: { | |
contract: { x: 'a', y: 'b' } | |
}, | |
response: { | |
body: [ | |
{ a: 1, b: 2 }, | |
{ a: 3, b: 4 }, |
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
function mapKeysWith (data, contract) { | |
const contractProps = invert(contract) | |
return mapKeys(data, function (value, key) { | |
return contractProps[key] | |
}) | |
} |
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
test('mapKeysWith() should map the keys of input object according to a template or contract', async function ({ deepEqual, end }) { | |
const data = { a: 1, b: 2 } | |
const contract = { x: 'a', y: 'b' } | |
const actual = mapKeysWith(data, contract) | |
const expected = { x: 1, y: 2 } | |
deepEqual(actual, expected, 'keys exist and they do not have null or undefined values') | |
end() | |
}) |
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
test('mapResponse() should map a given body response to the structure desired', async function ({ deepEqual, end }) { | |
const payload = { | |
data: { | |
response: { | |
body: [ | |
{ a: 1, b: 2 }, | |
{ a: 3, b: 4 }, | |
{ a: 5, b: 6 } | |
] | |
} |
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
app.get('/stores', async (req, res) => { | |
const config = { | |
host: 'http://localhost:3010', | |
endpoint: 'data', | |
method: 'GET', | |
headers: { 'content-type': 'application/json' } | |
} | |
const responseBody = await pipe( | |
composeRequest, | |
makeRequest, |