Created
August 22, 2020 12:58
-
-
Save mickaelw/4ac46de71c88b5b70082b07974afbf2e 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
@binding() | |
export class BasketPriceCalculationSteps { | |
private addToBasket: AddToBasket = null | |
private getBasketInformation: GetBasketInformation = null | |
@given(/^A basket that not contains any book$/) | |
public givenABasket(): void { | |
const basketRepository = new InMemoryBasketRepository() | |
this.addToBasket = new AddToBasket(basketRepository) | |
this.getBasketInformation = new GetBasketInformation(basketRepository) | |
} | |
@when(/^I add (.*) times the book (.*) into the basket$/) | |
public async whenIAddXTimesTheSameBookIntoTheBasket(time: string, bookTitle: string): Promise<void> { | |
const book = new Book(bookTitle) | |
for (let i = 1; i <= parseInt(time); i++) | |
await this.addToBasket.execute(book) | |
} | |
@when(/^I add those (.*) into the basket$/) | |
public async whenIAddSomeBooksIntoTheBasket(books: string): Promise<void> { | |
for (const bookTitle of books.split(',')) { | |
const book = new Book(bookTitle) | |
await this.addToBasket.execute(book) | |
} | |
} | |
@then(/^The price of the basket is (.*)$/) | |
public async thenThePriceOfTheBasketIs(basketPrice: string): Promise<void> { | |
const basket = await this.getBasketInformation.handle() | |
expect(basket.price).to.equals(parseFloat(basketPrice)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment