github.com/wendylau87/warungpintar2021/inventorysvc@v0.0.0-20210508064910-5fb678f1d33e/usecases/inventory/inventory__test.go (about) 1 package inventory_test 2 3 import ( 4 "fmt" 5 . "github.com/smartystreets/goconvey/convey" 6 "github.com/wendylau87/warungpintar2021/inventorysvc/domain/inventory" 7 "github.com/wendylau87/warungpintar2021/inventorysvc/entities" 8 "github.com/wendylau87/warungpintar2021/inventorysvc/infrastructure" 9 "github.com/wendylau87/warungpintar2021/inventorysvc/infrastructure/logger" 10 "github.com/wendylau87/warungpintar2021/inventorysvc/infrastructure/sqlhandler" 11 inbounduc "github.com/wendylau87/warungpintar2021/inventorysvc/usecases/inventory" 12 "os" 13 "path" 14 "runtime" 15 "testing" 16 ) 17 18 var( 19 dom inventory.DomainItf 20 uc inbounduc.UsecaseItf 21 ) 22 23 func TestMain(t *testing.M){ 24 _, filename, _, _ := runtime.Caller(0) 25 dir := path.Join(path.Dir(filename), "..", "..") 26 err := os.Chdir(dir) 27 if err != nil { 28 panic(err) 29 } 30 31 log := logger.NewLogger() 32 infrastructure.Load(*log) 33 sql, err := sqlhandler.NewSQLHandler(*log) 34 if err != nil{ 35 log.LogError("Failed initiated database") 36 panic(err) 37 } 38 39 dom = inventory.InitInboundDomain(*log, sql) 40 uc = inbounduc.InitInventoryUsecase(*log, dom) 41 42 exitVal := t.Run() 43 os.Exit(exitVal) 44 45 } 46 47 func TestUsecase_CreateInbound(t *testing.T) { 48 Convey("create Inbound", t, func() { 49 testCases := []struct { 50 testID int 51 testType string 52 testDesc string 53 payload entities.CreateInventory 54 }{ 55 { 56 testID: 1, 57 testDesc: "success create", 58 testType: "P", 59 payload: entities.CreateInventory{ 60 InboundDetailID: 1, 61 ItemID: 1, 62 Quantity: 10, 63 }, 64 }, 65 } 66 for _, tc := range testCases { 67 Convey(fmt.Sprintf("%d - [%s] : %s", tc.testID, tc.testType, tc.testDesc), func() { 68 _, err := uc.CreateInventory(tc.payload) 69 if tc.testType == "P" { 70 So(err, ShouldBeNil) 71 72 } else { 73 So(err, ShouldNotBeNil) 74 } 75 }) 76 } 77 }) 78 }