forked from turingschool-examples/javascript-foundations
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvendingMachine-test.js
More file actions
118 lines (86 loc) · 3.67 KB
/
vendingMachine-test.js
File metadata and controls
118 lines (86 loc) · 3.67 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var assert = require('chai').assert
var { createItemStock, collectChange, makePurchase } = require('./vendingMachine')
describe('vending machine functions', function() {
describe('createItemStock', function() {
it.skip('can collect the details of a stocked item', function() {
const name = 'chips'
const quantity = 10
const price = 1.25
const expectedResult = {
name: 'chips',
quantity: 10,
price: 1.25,
}
const itemStock = createItemStock(name, quantity, price)
assert.deepEqual(itemStock, expectedResult)
})
it.skip('should return an item with defaults if nothing is passed', function() {
const expectedResult = {
name: 'unknown',
quantity: 0,
price: 1.00
}
const itemStock = createItemStock()
assert.deepEqual(itemStock, expectedResult)
})
})
describe('makePurchase', function() {
it.skip('does not allow a purchase if given less than price', function() {
const selectedItem = createItemStock('chips', 2, 2.00)
const moneyForPurchase = 0.35
const expectedResult = 'Sorry, you need at least $2 to make that purchase'
const transactionResult = makePurchase(selectedItem, moneyForPurchase)
assert.equal(transactionResult, expectedResult)
})
it.skip('does not allow a purchase if given less than different price', function() {
const selectedItem = createItemStock('soda', 2, 1.00)
const moneyForPurchase = 0.35
const expectedResult = 'Sorry, you need at least $1 to make that purchase'
const transactionResult = makePurchase(selectedItem, moneyForPurchase)
assert.equal(transactionResult, expectedResult)
})
it.skip('does not allow a purchase if no items of that type are available', function() {
const selectedItem = createItemStock('chips', 0, 2.00)
const moneyForPurchase = 2.00
const expectedResult = 'Sorry, there are none left'
const transactionResult = makePurchase(selectedItem, moneyForPurchase)
assert.equal(transactionResult, expectedResult)
})
it.skip('allows the transaction if successful', function() {
const selectedItem = createItemStock('chips', 1, 2.00)
const moneyForPurchase = 2.00
const expectedResult = 'Here are your chips'
const transactionResult = makePurchase(selectedItem, moneyForPurchase)
assert.equal(transactionResult, expectedResult)
assert.deepEqual(transactionResult, expectedResult)
})
it.skip('allows a different transaction if successful', function() {
const selectedItem = createItemStock('skittles', 1, 1.00)
const moneyForPurchase = 1.00
const expectedResult = 'Here are your skittles'
const transactionResult = makePurchase(selectedItem, moneyForPurchase)
assert.equal(transactionResult, expectedResult)
assert.deepEqual(transactionResult, expectedResult)
})
})
describe('collectChange', function() {
it.skip('can calculate the total of a single coin', function() {
const looseChange = [0.25]
const expectedTotal = 0.25
const total = collectChange(looseChange)
assert.deepEqual(total, expectedTotal)
})
it.skip('can calculate the total of two coins', function() {
const looseChange = [0.25, 0.10]
const expectedTotal = 0.35
const total = collectChange(looseChange)
assert.deepEqual(total, expectedTotal)
})
it.skip('can calculate the total of many coins', function() {
const looseChange = [0.25, 0.10, 0.25, 0.05, 1.00]
const expectedTotal = 1.65
const total = collectChange(looseChange)
assert.deepEqual(total, expectedTotal)
})
})
})