Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment