-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 1.09 KB
/
Copy pathindex.js
File metadata and controls
40 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Test mechanism necessary for repl.it.
// Uncomment to run testing on repl.it.
/*
const mocha = require('mocha')
const chai = require('chai')
const sinon = require('sinon')
const runner = new mocha({})
runner.addFile('./test/test.js')
runner.run(failures => {
if (failures) {
console.error(failures)
} else {
console.log('All passed.')
}
})
*/
const transact = require('./transact.js');
module.exports = {placeOrder};
// javascript generator of each sequential step to process a transaction.
function *placeOrder() {
let orderId = Math.floor( Math.random()*5000 );
yield transact.calculateTotal(orderId);
let couponNumber = Math.floor( Math.random()*5000 );
yield transact.updateCoupon(couponNumber);
yield transact.chargeVendorFee();
let ccNumber = Math.floor( Math.random()*5000 );
yield transact.chargeCreditCard(ccNumber);
yield transact.saveOrder(orderId);
}
// Transaction Management main routine.
transact.logMsg("Transaction Management\n");
transact.logMsg("Transaction Finished: Succeed = " + transact.executeTransaction( placeOrder() ));