mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Added BackstagePassItemUpdateService test
This commit is contained in:
parent
a90385b7e5
commit
4871885ade
74
go/services/backstage_pass_item_update_service_test.go
Normal file
74
go/services/backstage_pass_item_update_service_test.go
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/emilybache/gildedrose-refactoring-kata/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BackstagePass item quality increments +1 >10 days before sellIn
|
||||||
|
func TestBackstagePassItemUpdateService_QualityBeforeSellIn(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
backstagePassItemUpdateService BackstagePassItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Backstage passes to a TAFKAL80ETC concert", 20, 5})
|
||||||
|
backstagePassItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 6, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BackstagePass item quality increments +2 10 days before sellIn
|
||||||
|
func TestBackstagePassItemUpdateService_QualityBeforeSellIn10Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
backstagePassItemUpdateService BackstagePassItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Backstage passes to a TAFKAL80ETC concert", 10, 5})
|
||||||
|
backstagePassItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 7, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// BackstagePass item quality increments +3 5 days before sellIn
|
||||||
|
func TestBackstagePassItemUpdateService_QualityBeforeSellIn5Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
backstagePassItemUpdateService BackstagePassItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Backstage passes to a TAFKAL80ETC concert", 5, 5})
|
||||||
|
backstagePassItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 8, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the BackstagePass item quality is 0
|
||||||
|
func TestBackstagePassItemUpdateService_QualityAfterSellIn0Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
backstagePassItemUpdateService BackstagePassItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Backstage passes to a TAFKAL80ETC concert", 0, 5})
|
||||||
|
backstagePassItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 0, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the BackstagePass item quality is still 0
|
||||||
|
func TestBackstagePassItemUpdateService_QualityAfterSellIn4Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
backstagePassItemUpdateService BackstagePassItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Backstage passes to a TAFKAL80ETC concert", -4, 5})
|
||||||
|
backstagePassItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 0, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// sellIn date must decrease
|
||||||
|
func TestBackstagePassItemUpdateService_SellInIsDecreased(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
backstagePassItemUpdateService BackstagePassItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Random normal item", -4, 0})
|
||||||
|
backstagePassItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, -5, item.Model.SellIn)
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user