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
// mirage/config.js - Mocking data using fixtures | |
this.post('/multi_transfers', { | |
multi_transfer: { | |
id: '5f6d9775-2160-4568-8ce2-2083db593753', | |
status: 'pending', | |
total_amount: 500, | |
transfers: [ | |
{ | |
amount: 300, |
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
// mirage/config.js - Mocking data using factories | |
this.post('/multi_transfers', function (schema, request) { | |
return server.create('multi-transfer', { | |
status: 'pending', | |
total_amount: 500, | |
transfers: [ | |
{ | |
amount: 300, | |
iban: 'FR3902854000000000000000024', |
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 }); |
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
// mirage/config.js - Creating a basic route handler | |
this.post('/multi_transfers'); |
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
// mirage/config.js - Adding a method for reading the file | |
function readFile(file) { | |
let reader = new FileReader(); | |
return new Promise((resolve, reject) => { | |
reader.onerror = () => { | |
reject(new Error('There was an error reading the file!')); | |
}; | |
reader.onload = () => resolve(reader.result); |
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
// mirage/config.js - AAdding a method for parsing the file | |
function parseCSV(file) { | |
// create an array with the file rows as elements | |
let dataRows = file.split(/\\r?\\n|\\r/); | |
// remove the first row which represents the table header | |
dataRows.shift(); | |
let totalAmount = 0; |
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
// mirage/config.js - Mocking with factories and the data from the request file | |
this.post('/multi_transfers', async function (schema, request) { | |
let file = request.requestBody.get('multi_transfer[file][file]'); | |
let fileContents = await readFile(file); | |
let transferData = parseCSV(fileContents); | |
let multiTransfer = server.create('multi-transfer', { | |
status: 'pending', | |
...transferData, |
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
import Component from '@glimmer/component'; | |
import { action } from '@ember/object'; | |
function createForm(schema) { | |
submit(values) { | |
debugger | |
} | |
} | |
export default class extends Component { |
OlderNewer