Skip to content

Instantly share code, notes, and snippets.

@herzzanu
herzzanu / mobile-app-resources.md
Created November 17, 2023 16:16
Mobile app run and distribution resources
import Component from '@glimmer/component';
import { action } from '@ember/object';
function createForm(schema) {
submit(values) {
debugger
}
}
export default class extends Component {
@herzzanu
herzzanu / config.js
Last active February 10, 2021 10:32
Multi transfers route handler with reading and parsing the file
// 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,
@herzzanu
herzzanu / config.js
Created February 10, 2021 10:29
Parsing file method
// 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;
@herzzanu
herzzanu / config.js
Created February 10, 2021 10:28
Read file method
// 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);
@herzzanu
herzzanu / config.js
Created February 10, 2021 10:26
Mirage basic route handler
// mirage/config.js - Creating a basic route handler
this.post('/multi_transfers');
@herzzanu
herzzanu / multi-transfer-test.js
Created February 10, 2021 10:25
Testing mirage route handlers
// 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 });
@herzzanu
herzzanu / config.js
Last active February 10, 2021 10:21
Mirage config - using factories
// 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',
@herzzanu
herzzanu / config.js
Last active February 10, 2021 10:18
Mirage config - using fixtures
// 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,
@herzzanu
herzzanu / multi-transfer.json
Last active February 10, 2021 10:16
Multi transfer - server JSON response
// Server JSON response
{
"multi_transfer":{
"id":"5f6d9775-2160-4568-8ce2-2083db593753",
"status":"pending",
"total_amount":500,
"transfers":[
{
"amount":300,