mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-18 07:51:29 +00:00
Updated some tests and addes Sulfuras item update service tests
This commit is contained in:
parent
44a4456e00
commit
807125a909
@ -14,7 +14,7 @@ func TestAgedBrieItemUpdateService_QualityBeforeSellIn(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Aged Brie", 5, 5})
|
item := models.NewItem(&models.ItemModel{"Aged Brie", 5, 5})
|
||||||
agedBrieItemUpdateService.UpdateQuality(item)
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 6)
|
assert.Equal(t, 6, item.Model.Quality)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ func TestAgedBrieItemUpdateService_QualityAfterSellIn0Days(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Aged Brie", 0, 5})
|
item := models.NewItem(&models.ItemModel{"Aged Brie", 0, 5})
|
||||||
agedBrieItemUpdateService.UpdateQuality(item)
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 7)
|
assert.Equal(t, 7, item.Model.Quality)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func TestAgedBrieItemUpdateService_QualityAfterSellIn4Days(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Aged Brie", -4, 5})
|
item := models.NewItem(&models.ItemModel{"Aged Brie", -4, 5})
|
||||||
agedBrieItemUpdateService.UpdateQuality(item)
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 7)
|
assert.Equal(t, 7, item.Model.Quality)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +47,17 @@ func TestAgedBrieItemUpdateService_QualityNotHigherThan50(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Aged Brie", -4, 50})
|
item := models.NewItem(&models.ItemModel{"Aged Brie", -4, 50})
|
||||||
agedBrieItemUpdateService.UpdateQuality(item)
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 50)
|
assert.Equal(t, 50, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// sellIn date must decrease
|
||||||
|
func TestAgedBrieItemUpdateService_SellInIsDecreased(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
sulfurasItemUpdateService SulfurasItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Aged Brie", 5, 5})
|
||||||
|
sulfurasItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 4, item.Model.SellIn)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ func TestNormalItemUpdateService_QualityBeforeSellIn(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Random normal item", 5, 5})
|
item := models.NewItem(&models.ItemModel{"Random normal item", 5, 5})
|
||||||
normalItemUpdateService.UpdateQuality(item)
|
normalItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 4)
|
assert.Equal(t, 4, item.Model.Quality)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ func TestNormalItemUpdateService_QualityAfterSellIn0Days(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Random normal item", 0, 5})
|
item := models.NewItem(&models.ItemModel{"Random normal item", 0, 5})
|
||||||
normalItemUpdateService.UpdateQuality(item)
|
normalItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 3)
|
assert.Equal(t, 3, item.Model.Quality)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func TestNormalItemUpdateService_QualityAfterSellIn4Days(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Random normal item", -4, 5})
|
item := models.NewItem(&models.ItemModel{"Random normal item", -4, 5})
|
||||||
normalItemUpdateService.UpdateQuality(item)
|
normalItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 3)
|
assert.Equal(t, 3, item.Model.Quality)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +47,6 @@ func TestNormalItemUpdateService_QualityNotLowerThan0(t *testing.T) {
|
|||||||
) {
|
) {
|
||||||
item := models.NewItem(&models.ItemModel{"Random normal item", -4, 0})
|
item := models.NewItem(&models.ItemModel{"Random normal item", -4, 0})
|
||||||
normalItemUpdateService.UpdateQuality(item)
|
normalItemUpdateService.UpdateQuality(item)
|
||||||
assert.Equal(t, item.Model.Quality, 0)
|
assert.Equal(t, 0, item.Model.Quality)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
63
go/services/sulfuras_item_update_service_test.go
Normal file
63
go/services/sulfuras_item_update_service_test.go
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/emilybache/gildedrose-refactoring-kata/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Sulfuras item quality is 80 before sellIn
|
||||||
|
func TestSulfurasItemUpdateService_QualityBeforeSellIn(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
sulfurasItemUpdateService SulfurasItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Sulfuras, Hand of Ragnaros", 5, 5})
|
||||||
|
sulfurasItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 80, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sulfuras item sellIn is immutable
|
||||||
|
func TestSulfurasItemUpdateService_SellInIsImmutable(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
sulfurasItemUpdateService SulfurasItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Sulfuras, Hand of Ragnaros", 5, 5})
|
||||||
|
sulfurasItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 5, item.Model.SellIn)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the Sulfuras item quality is still 80
|
||||||
|
func TestSulfurasItemUpdateService_QualityAfterSellIn0Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
sulfurasItemUpdateService SulfurasItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Sulfuras, Hand of Ragnaros", 0, 5})
|
||||||
|
sulfurasItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 80, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the Sulfuras item quality is still 80
|
||||||
|
func TestSulfurasItemUpdateService_QualityAfterSellIn4Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
sulfurasItemUpdateService SulfurasItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Sulfuras, Hand of Ragnaros", -4, 5})
|
||||||
|
sulfurasItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, 80, item.Model.Quality)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sulfuras item negative sellIn is immutable
|
||||||
|
func TestSulfurasItemUpdateService_NegativeSellInIsImmutable(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
sulfurasItemUpdateService SulfurasItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Sulfuras, Hand of Ragnaros", -4, 5})
|
||||||
|
sulfurasItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, -4, item.Model.SellIn)
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user