diff --git a/internal/engine/command/voucher/claim.go b/internal/engine/command/voucher/claim.go index d16bf77d..1f138444 100644 --- a/internal/engine/command/voucher/claim.go +++ b/internal/engine/command/voucher/claim.go @@ -25,8 +25,7 @@ func (v *VoucherCmd) claimHandler( return cmd.ErrorResult(errors.New("voucher code is not valid, no voucher found")) } - now := time.Now().Month() - if voucher.CreatedAt.Month() >= (now + time.Month(voucher.ValidMonths)) { + if voucher.CreatedAt.AddDate(0, int(voucher.ValidMonths), 0).Before(time.Now()) { return cmd.ErrorResult(errors.New("voucher is expired")) } diff --git a/internal/engine/command/voucher/create.go b/internal/engine/command/voucher/create.go index 096bee5e..ab650a3a 100644 --- a/internal/engine/command/voucher/create.go +++ b/internal/engine/command/voucher/create.go @@ -26,7 +26,7 @@ type BulkRecorder struct { Description string `csv:"Description"` } -func (v *VoucherCmd) createOneHandler( +func (v *VoucherCmd) createHandler( caller *entity.User, cmd *command.Command, args map[string]string, diff --git a/internal/engine/command/voucher/create_test.go b/internal/engine/command/voucher/create_test.go index ad4169b1..7335c184 100644 --- a/internal/engine/command/voucher/create_test.go +++ b/internal/engine/command/voucher/create_test.go @@ -21,7 +21,7 @@ func TestCreateOne(t *testing.T) { "valid-months": "1", } - result := td.voucherCmd.createOneHandler(caller, cmd, args) + result := td.voucherCmd.createHandler(caller, cmd, args) assert.False(t, result.Successful) assert.Contains(t, result.Message, "stake amount is more than 1000") }) @@ -32,7 +32,7 @@ func TestCreateOne(t *testing.T) { "valid-months": "1.1", } - result := td.voucherCmd.createOneHandler(caller, cmd, args) + result := td.voucherCmd.createHandler(caller, cmd, args) assert.False(t, result.Successful) }) @@ -42,7 +42,7 @@ func TestCreateOne(t *testing.T) { "valid-months": "1", } - result := td.voucherCmd.createOneHandler(caller, cmd, args) + result := td.voucherCmd.createHandler(caller, cmd, args) assert.True(t, result.Successful) assert.Contains(t, result.Message, "Voucher created successfully!") }) @@ -55,7 +55,7 @@ func TestCreateOne(t *testing.T) { "description": "Testnet node", } - result := td.voucherCmd.createOneHandler(caller, cmd, args) + result := td.voucherCmd.createHandler(caller, cmd, args) assert.True(t, result.Successful) assert.Contains(t, result.Message, "Voucher created successfully!") }) diff --git a/internal/engine/command/voucher/voucher.go b/internal/engine/command/voucher/voucher.go index 38e59cd3..6e6494bf 100644 --- a/internal/engine/command/voucher/voucher.go +++ b/internal/engine/command/voucher/voucher.go @@ -49,8 +49,8 @@ func (v *VoucherCmd) GetCommand() *command.Command { TargetFlag: command.TargetMaskMainnet, } - subCmdCreateOne := &command.Command{ - Name: "create-one", + subCmdCreate := &command.Command{ + Name: "create", Help: "Generate a single voucher code", Args: []*command.Args{ { @@ -81,7 +81,7 @@ func (v *VoucherCmd) GetCommand() *command.Command { SubCommands: nil, AppIDs: []entity.PlatformID{entity.PlatformIDDiscord}, Middlewares: []command.MiddlewareFunc{middlewareHandler.OnlyModerator}, - Handler: v.createOneHandler, + Handler: v.createHandler, TargetFlag: command.TargetMaskModerator, } @@ -138,7 +138,7 @@ func (v *VoucherCmd) GetCommand() *command.Command { } cmdVoucher.AddSubCommand(subCmdClaim) - cmdVoucher.AddSubCommand(subCmdCreateOne) + cmdVoucher.AddSubCommand(subCmdCreate) cmdVoucher.AddSubCommand(subCmdCreateBulk) cmdVoucher.AddSubCommand(subCmdStatus)