getPrices test
This commit is contained in:
parent
d9eeec2f8c
commit
064ae1aeff
2 changed files with 98 additions and 2 deletions
98
internal/merch/service_prices_test.go
Normal file
98
internal/merch/service_prices_test.go
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
package merch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"merch-api/pkg/utils"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Test_service_getPrices(t *testing.T) {
|
||||
type fields struct {
|
||||
repo Repository
|
||||
utils utils.Utils
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
userId int64
|
||||
days int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want []PricesResponse
|
||||
wantErr assert.ErrorAssertionFunc
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
{name: "success",
|
||||
fields: fields{
|
||||
repo: nil,
|
||||
utils: utils.New(),
|
||||
},
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
userId: 4,
|
||||
days: 180,
|
||||
},
|
||||
want: []PricesResponse{},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockMerch := []Merch{
|
||||
{Id: 1532, MerchUuid: "019cd7f4-e491-7dd5-a327-ea0b4c3800d6", Name: "Momo (darkness ver.)"},
|
||||
{Id: 1534, MerchUuid: "019cd7f4-e491-7dd7-a81f-1160db34da2d", Name: "Sairenji Haruna 1/4"},
|
||||
}
|
||||
|
||||
mockPrices := []Price{
|
||||
{CreatedAt: timeFromString("2026-02-01 15:43:25.375677+00"), MerchId: 1532, Price: 1231, OriginId: 2},
|
||||
{CreatedAt: timeFromString("2026-02-02 15:43:25.375677+00"), MerchId: 1532, Price: 1232, OriginId: 2},
|
||||
{CreatedAt: timeFromString("2026-02-03 15:43:25.375677+00"), MerchId: 1532, Price: 1233, OriginId: 2},
|
||||
{CreatedAt: timeFromString("2026-02-04 15:43:25.375677+00"), MerchId: 1532, Price: 1234, OriginId: 2},
|
||||
{CreatedAt: timeFromString("2026-02-05 15:43:25.375677+00"), MerchId: 1532, Price: 1235, OriginId: 2},
|
||||
{CreatedAt: timeFromString("2026-02-06 15:43:25.375677+00"), MerchId: 1532, Price: 1231, OriginId: 2},
|
||||
//
|
||||
{CreatedAt: timeFromString("2026-02-01 15:43:25.375677+00"), MerchId: 1534, Price: 5231, OriginId: 1},
|
||||
{CreatedAt: timeFromString("2026-02-02 15:43:25.375677+00"), MerchId: 1534, Price: 5232, OriginId: 1},
|
||||
{CreatedAt: timeFromString("2026-02-03 15:43:25.375677+00"), MerchId: 1534, Price: 5233, OriginId: 1},
|
||||
{CreatedAt: timeFromString("2026-02-04 15:43:25.375677+00"), MerchId: 1534, Price: 5234, OriginId: 1},
|
||||
{CreatedAt: timeFromString("2026-02-05 15:43:25.375677+00"), MerchId: 1534, Price: 5235, OriginId: 1},
|
||||
{CreatedAt: timeFromString("2026-02-06 15:43:25.375677+00"), MerchId: 1534, Price: 5231, OriginId: 1},
|
||||
}
|
||||
|
||||
mockOrigins := []Origin{
|
||||
{Id: 1, Name: "surugaya"},
|
||||
{Id: 2, Name: "mandarake"},
|
||||
}
|
||||
|
||||
mockRepo := new(MockRepository)
|
||||
mockRepo.On("getAllUserMerch", mock.Anything, tt.args.userId).Return(mockMerch, nil)
|
||||
|
||||
mockRepo.On("getPricesWithDays", mock.Anything, tt.args.userId, mock.Anything).Return(mockPrices, nil)
|
||||
mockRepo.On("getOrigins", mock.Anything).Return(mockOrigins, nil)
|
||||
|
||||
s := &service{
|
||||
repo: mockRepo,
|
||||
utils: tt.fields.utils,
|
||||
}
|
||||
got, _ := s.getPrices(tt.args.ctx, tt.args.userId, tt.args.days)
|
||||
//if !tt.wantErr(t, err, fmt.Sprintf("getPrices(%v, %v, %v)", tt.args.ctx, tt.args.userId, tt.args.days)) {
|
||||
// return
|
||||
//}
|
||||
|
||||
for _, item := range got {
|
||||
fmt.Printf("name: %v, merch_uuid: %v, origins: %v\n", item.Name, item.MerchUuid, item.Origins)
|
||||
}
|
||||
//assert.Equalf(t, tt.want, got, "getPrices(%v, %v, %v)", tt.args.ctx, tt.args.userId, tt.args.days)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func timeFromString(s string) time.Time {
|
||||
t, _ := time.Parse("2006-01-02 15:04:05", s)
|
||||
return t
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue