Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/tests/steps/CartSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Cart from "../../entity/Cart"
import axios, { Axios } from 'axios'
import assert from "assert"
import CartLine from "../../entity/CartLine"
import Discount from "../../entity/Discount"

@binding()
class CartSteps {
Expand Down Expand Up @@ -43,17 +44,29 @@ class CartSteps {

@when("I remove product {string} of my cart")
public async removeProductOfMyCart(sku: string): Promise<void> {
throw "Step method not implemented"
await this.addProductUnitsToMyCart(0, sku)
}

@then("the cart's total cost should be {double} euro(s)")
public async cartTotalCost(totalCost: number) {
throw "Step method not implemented"
const cart: Cart = await this.currentCart()
const totalProducts: number = cart
.lines
.map((cartLine: CartLine) => cartLine.quantity * cartLine.product.price)
.reduce((carry: number, current: number) => carry + current, 0)
const totalDiscounts = cart
.discounts
.map((discount: Discount) => discount.value)
.reduce((carry: number, current: number) => carry + current, 0)
assert.equal(Math.round((totalProducts - totalDiscounts) * 100) / 100, totalCost)
}

@then("there should be {int} unit(s) of product {string} in my cart")
public async thereShouldBeProductUnitsInMyCart(quantity: number, sku: string) {
throw "Step method not implemented"
const cart: Cart = await this.currentCart()
const cartLine: CartLine|undefined = cart.lines.find((cartLine: CartLine) => cartLine.product.sku == sku)
assert.equal(cartLine ? true : false, true, `Product ${sku} not found`)
assert.equal(cartLine?.quantity, quantity)
}

@then("there shouldn't be product {string} in my cart")
Expand Down
10 changes: 9 additions & 1 deletion src/tests/steps/ProductSteps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ class ProductSteps {

@given("the following products exist:")
public async theFollowingProductsExists(table: DataTable): Promise<void> {
throw "Step method not implemented"
var products: Product[] = []
table.hashes().forEach(async (row: any) => {
const product = new Product()
product.sku = row.sku
product.name = row.name
product.price = row.price
products.push(product)
})
await this.productRepository.save(products)
}
}

Expand Down