Created
February 10, 2021 10:25
-
-
Save herzzanu/d5157d94adfeb86e9a5c8c8690457611 to your computer and use it in GitHub Desktop.
Testing mirage route handlers
This file contains hidden or 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
// tests/mirage/multi-transfer-test.js - Testing mirage route handlers | |
const CSV_FILE = `beneficiary_name,iban,bic,amount | |
Jane Doe,FR3902854000000000000000024,BNPDFRP1,300 | |
John Doe,FR1408672000000000000000167,BNPDFRP1,200`; | |
test('creates a multi-transfer', async function (assert) { | |
let blob = new Blob([CSV_FILE], { type: 'text/csv' }); | |
let file = new File([blob], 'csv', { type: blob.type }); | |
let form = new FormData(); | |
form.append('multi_transfer[file][file]', file); | |
let response = await fetch(`/multi_transfers`, { method: 'POST', body: form }); | |
assert.equal(response.status, 201); | |
let responsePayload = await response.json(); | |
assert.matchJson(responsePayload, { | |
multi_transfer: { | |
id: String, | |
status: 'pending', | |
total_amount: 500, | |
transfers: [ | |
{ | |
amount: 300, | |
bic: 'BNPDFRP1', | |
iban: 'FR3902854000000000000000024', | |
name: 'Jane Doe', | |
}, | |
{ | |
amount: 200, | |
bic: 'BNPDFRP1', | |
iban: 'FR1408672000000000000000167', | |
name: 'John Doe', | |
}, | |
], | |
}, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment