-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinvariants.js
48 lines (39 loc) · 1.46 KB
/
invariants.js
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
41
42
43
44
45
46
47
48
"use strict"
const { invariants } = require('../build/index')
const theOrder = {
total: 10,
shipping: 4,
items: [{ id: 'a', price: 4, total: 10, qty: 4 }],
invoiced: [{ items: [{ id: 'a', price: 4, total: 8, qty: 2 }],
shipping: 2,
total: 5 }],
refunded: [{ items: [{ id: 'a', price: 4, total: 9, qty: 3 }],
shipping: 3,
total: 6 }],
canceled: [{ items: [{ id: 'a', price: 4, total: 5, qty: 3 }],
shipping: 3,
total: 7 }] }
// Refunded amount more than invoiced
console.log(invariants.total(theOrder).ir)
// -1
// Refunded shipping amount more than invoiced
console.log(invariants.shipping(theOrder).total.ir)
// -1
// 1 more item refunded, than invoiced
console.log(invariants.items.qty(theOrder).ir[0].qty)
// -1
// Refunded amount for the item is more than invoiced amount for this item
console.log(invariants.items.total(theOrder).ir[0].total)
// -1
// Invoiced and canceled amount together more than order amount
console.log(invariants.total(theOrder).ci)
// -2
// Invoiced and canceled shipping amount together more than order amount
console.log(invariants.shipping(theOrder).total.ci)
// -1
// Invoiced and canceled quantity of the item more than quantity of this item in the order
console.log(invariants.items.qty(theOrder).ci[0].qty)
// -1
// Invoiced and canceled amount for the item together more than we paid for this item in the order
console.log(invariants.items.total(theOrder).ci[0].total)
// -3