diff --git a/go/services/aged_brie_item_update_service_test.go b/go/services/aged_brie_item_update_service_test.go new file mode 100644 index 00000000..758e241d --- /dev/null +++ b/go/services/aged_brie_item_update_service_test.go @@ -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) + }) +} diff --git a/go/services/services_test.go b/go/services/services_test.go new file mode 100644 index 00000000..64649f93 --- /dev/null +++ b/go/services/services_test.go @@ -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()) +}