Skip to content

Instantly share code, notes, and snippets.

@sergueyarellano
Created May 28, 2021 17:09
Show Gist options
  • Save sergueyarellano/4ada9836f541edb669d922f4fdace8ff to your computer and use it in GitHub Desktop.
Save sergueyarellano/4ada9836f541edb669d922f4fdace8ff to your computer and use it in GitHub Desktop.
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 },
{ a: 5, b: 6 },
{ a: 7, b: 8, c: 9 } // add something that we don't want to use
]
}
}
}
const actual = mapResponse(deepFreeze(payload))
const expected = {
data: {
config: {
contract: { x: 'a', y: 'b' }
},
mappedResponse: [
{ x: 1, y: 2 },
{ x: 3, y: 4 },
{ x: 5, y: 6 },
{ x: 7, y: 8 } // should fail for now
],
response: {
body: [
{ a: 1, b: 2 },
{ a: 3, b: 4 },
{ a: 5, b: 6 },
{ a: 7, b: 8, c: 9 } // response is not mutated
]
}
}
}
deepEqual(actual, expected, 'map only the elements according to give interface')
end()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment