mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Added NormalItemUpdateService tests
This commit is contained in:
parent
0d58e127b1
commit
42944e54f0
52
go/services/normal_item_update_service_test.go
Normal file
52
go/services/normal_item_update_service_test.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/emilybache/gildedrose-refactoring-kata/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Normal item quality decrements in 1 after each day
|
||||||
|
func TestNormalItemUpdateService_QualityBeforeSellIn(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
normalItemUpdateService NormalItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Random normal item", 5, 5})
|
||||||
|
normalItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, item.Model.Quality, 4)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the Normal item quality decrements in 2
|
||||||
|
func TestNormalItemUpdateService_QualityAfterSellIn0Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
normalItemUpdateService NormalItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Random normal item", 0, 5})
|
||||||
|
normalItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, item.Model.Quality, 3)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the Normal item quality decrements in 2
|
||||||
|
func TestNormalItemUpdateService_QualityAfterSellIn4Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
normalItemUpdateService NormalItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Random normal item", -4, 5})
|
||||||
|
normalItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, item.Model.Quality, 3)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Quality must not be lower than 0
|
||||||
|
func TestNormalItemUpdateService_QualityNotLowerThan0(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
agedBrieItemUpdateService AgedBrieItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Random normal item", -4, 0})
|
||||||
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, item.Model.Quality, 0)
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user