mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Added AgedBrieItemUpdateService tests
This commit is contained in:
parent
1000c5e1e5
commit
38b2c933ce
41
go/services/aged_brie_item_update_service_test.go
Normal file
41
go/services/aged_brie_item_update_service_test.go
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/emilybache/gildedrose-refactoring-kata/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Aged Brie quality increments in 1 after each day
|
||||||
|
func TestAgedBrieItemUpdateService_QualityBeforeSellIn(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
agedBrieItemUpdateService AgedBrieItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Aged Brie", 5, 5})
|
||||||
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, item.Model.Quality, 6)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the Aged Brie quality increments in 2
|
||||||
|
func TestAgedBrieItemUpdateService_QualityAfterSellIn0Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
agedBrieItemUpdateService AgedBrieItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Aged Brie", 0, 5})
|
||||||
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, item.Model.Quality, 7)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the sellIn date has been passed, the Aged Brie quality increments in 2
|
||||||
|
func TestAgedBrieItemUpdateService_QualityAfterSellIn4Days(t *testing.T) {
|
||||||
|
runTestCase(t, func(
|
||||||
|
agedBrieItemUpdateService AgedBrieItemUpdateService,
|
||||||
|
) {
|
||||||
|
item := models.NewItem(&models.ItemModel{"Aged Brie", -4, 5})
|
||||||
|
agedBrieItemUpdateService.UpdateQuality(item)
|
||||||
|
assert.Equal(t, item.Model.Quality, 7)
|
||||||
|
})
|
||||||
|
}
|
||||||
30
go/services/services_test.go
Normal file
30
go/services/services_test.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package services
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"go.uber.org/fx"
|
||||||
|
"go.uber.org/fx/fxtest"
|
||||||
|
|
||||||
|
"github.com/emilybache/gildedrose-refactoring-kata/lib"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TestCommonModules = fx.Options(
|
||||||
|
Module,
|
||||||
|
lib.Module,
|
||||||
|
)
|
||||||
|
|
||||||
|
type TestCaseRunner interface{}
|
||||||
|
|
||||||
|
func setupTestCase(logger lib.Logger) {
|
||||||
|
logger.Info("Setup Service test case")
|
||||||
|
}
|
||||||
|
|
||||||
|
func runTestCase(t *testing.T, runner TestCaseRunner) {
|
||||||
|
app := fxtest.New(t, TestCommonModules, fx.Invoke(setupTestCase), fx.Invoke(runner))
|
||||||
|
|
||||||
|
defer app.RequireStart().RequireStop()
|
||||||
|
require.NoError(t, app.Err())
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user