Skip to content

Instantly share code, notes, and snippets.

@mickaelw
Created August 22, 2020 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickaelw/4ac46de71c88b5b70082b07974afbf2e to your computer and use it in GitHub Desktop.
Save mickaelw/4ac46de71c88b5b70082b07974afbf2e to your computer and use it in GitHub Desktop.
@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