Created
July 25, 2019 14:11
-
-
Save jasongorman/c5893bb8985529bb87711b041e4b1d94 to your computer and use it in GitHub Desktop.
This file contains 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
describe("buy a CD", function() { | |
const creditCard = { | |
number: "1234234545675768", | |
expiry: "10/22", | |
cv: "855" | |
}; | |
describe("payment accepted", function() { | |
it("reduces stock count by 1", function () { | |
const cd = new CD(price = 9.99, stock = 2); | |
const payments = new StubPayments(accepted = true); | |
cd.buy(payments, creditCard); | |
assert.equal(cd.stock, 1); | |
}) | |
}) | |
describe("payment rejected", function () { | |
it("doesn't change the stock count", function() { | |
const cd = new CD(price=9.99, stock=2); | |
const payments = new StubPayments(accepted=false); | |
cd.buy(payments, creditCard); | |
assert.equal(cd.stock, 2); | |
}) | |
}) | |
describe("out of stock", function () { | |
it("should throw an out of stock error", function() { | |
const cd = new CD(price=9.99, stock=0); | |
const payments = new StubPayments(accepted=true); | |
assert.throws(() => {cd.buy(payments, creditCard);}, OutOfStockError); | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment