Added AgedBrieItemUpdateService tests

This commit is contained in:
Daniel F 2023-07-11 21:23:46 +01:00
parent 1000c5e1e5
commit 38b2c933ce
2 changed files with 71 additions and 0 deletions

View 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)
})
}

View 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())
}