From 42944e54f08b43869dffc6c59ed8b47ec80227d2 Mon Sep 17 00:00:00 2001 From: Daniel F Date: Tue, 11 Jul 2023 21:29:15 +0100 Subject: [PATCH] Added NormalItemUpdateService tests --- .../normal_item_update_service_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 go/services/normal_item_update_service_test.go diff --git a/go/services/normal_item_update_service_test.go b/go/services/normal_item_update_service_test.go new file mode 100644 index 00000000..eff435e3 --- /dev/null +++ b/go/services/normal_item_update_service_test.go @@ -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) + }) +}