Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/test2 #52

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class FlowerStock extends AggregateRoot {

const flowerId = this.flowers.shift()

if (currentStock >= 50 && this.flowers.length < 50) {
if (this.hasStock(currentStock)) {
this.record(new LowStock('low flower stock'))
}

Expand All @@ -47,7 +47,7 @@ export class FlowerStock extends AggregateRoot {

const flowerIds: Array<string> = this.flowers.splice(0, amount)

if (currentStock >= 50 && this.flowers.length < 50) {
if (this.hasStock(currentStock)) {
this.record(new LowStock(`low flower stock produced by high demand: ${amount}`))
}

Expand All @@ -59,8 +59,12 @@ export class FlowerStock extends AggregateRoot {

this.flowers = this.flowers.filter(flowerId => !deadFlowers.includes(flowerId))

if (currentStock >= 50 && this.flowers.length < 50) {
if (this.hasStock(currentStock)) {
this.record(new LowStock(`low flower stock produced by ${deadFlowers.length} dead flowers`))
}
}

private hasStock(currentStock: number): boolean {
return currentStock >= 50 && this.flowers.length < 50;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { LowStock } from "../src/LowStock"
import { NotEnoughStock } from "../src/NotEnoughStock"
import { OutOfStock } from "../src/OutOfStock"

const MIN_STOCK_LEVEL = 50;
describe('flower stock management', () => {

it('should add a flower to the stock', () => {
Expand Down Expand Up @@ -34,7 +35,7 @@ describe('flower stock management', () => {
})

it('should reach low stock when getting a single flower from a stock of 50', () => {
const stockFlowerIds = makeFlowerIds(50)
const stockFlowerIds = makeFlowerIds(MIN_STOCK_LEVEL)
const stock = new FlowerStock(stockFlowerIds)

stock.get()
Expand All @@ -46,7 +47,7 @@ describe('flower stock management', () => {
})

it('should not reach low stock when getting a single flower from a stock greater than 50', () => {
const flowerIds = makeFlowerIds(51)
const flowerIds = makeFlowerIds(MIN_STOCK_LEVEL + 1)
const stock = new FlowerStock(flowerIds)

stock.get()
Expand All @@ -71,10 +72,9 @@ describe('flower stock management', () => {
})

it('should reach low stock when getting multiple flowers and the limit of 50 is exceeded', () => {
const lowStockLevel = 50
const unitsToLowStock = 5
const unitsToGetFromTheStock = 6
const totalStock = lowStockLevel + unitsToLowStock
const totalStock = MIN_STOCK_LEVEL + unitsToLowStock
const stockFlowerIds = makeFlowerIds(totalStock)
const stock = new FlowerStock(stockFlowerIds)

Expand All @@ -87,10 +87,9 @@ describe('flower stock management', () => {
})

it('should not reach low stock when getting multiple flowers and the limit of 50 is not exceeded', () => {
const lowStockLimit = 50
const unitsToLowStock = 5
const unitsToGetFromTheStock = 5
const totalStock = lowStockLimit + unitsToLowStock
const totalStock = MIN_STOCK_LEVEL + unitsToLowStock
const flowerIds = makeFlowerIds(totalStock)
const stock = new FlowerStock(flowerIds)

Expand Down Expand Up @@ -119,10 +118,9 @@ describe('flower stock management', () => {


it('should reach low stock when removing dead flowers and the limit of 50 is exceeded', () => {
const lowStockLevel = 50
const unitsToLowStock = 5
const totalDeadFlowers = 6
const totalStock = lowStockLevel + unitsToLowStock
const totalStock = MIN_STOCK_LEVEL + unitsToLowStock
const stockFlowerIds = makeFlowerIds(totalStock)
const stock = new FlowerStock(stockFlowerIds)

Expand All @@ -136,10 +134,9 @@ describe('flower stock management', () => {
})

it('should not reach low stock when removing flowers and the limit of 50 is not exceeded', () => {
const lowStockLimit = 50
const unitsToLowStock = 5
const totalDeadFlowers = 5
const totalStock = lowStockLimit + unitsToLowStock
const totalStock = MIN_STOCK_LEVEL + unitsToLowStock
const flowerIds = makeFlowerIds(totalStock)
const stock = new FlowerStock(flowerIds)

Expand Down