Skip to content

Instantly share code, notes, and snippets.

const config = {
host: 'http://localhost:3010',
endpoint: 'data',
method: 'GET',
headers: { 'content-type': 'application/json' },
contract: {
type: 'class',
description: 'report',
location: 'address',
distance: 'range'
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 },
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',
function createResult (payload) {
const newPayload = cloneDeep(payload)
const data = get(newPayload, 'data.mappedResponse')
const result = {
data,
metadata: {}
}
return set(newPayload, 'result', result)
}
{
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 },
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 },
function mapKeysWith (data, contract) {
const contractProps = invert(contract)
return mapKeys(data, function (value, key) {
return contractProps[key]
})
}
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()
})
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 }
]
}
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,