Skip to content

Commit

Permalink
fix: check voucher code expiry (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
sepehr-dh99 authored Jan 14, 2025
1 parent 0254829 commit 9d51348
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
3 changes: 1 addition & 2 deletions internal/engine/command/voucher/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

Expand Down
2 changes: 1 addition & 1 deletion internal/engine/command/voucher/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions internal/engine/command/voucher/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
})
Expand All @@ -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)
})

Expand All @@ -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!")
})
Expand All @@ -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!")
})
Expand Down
8 changes: 4 additions & 4 deletions internal/engine/command/voucher/voucher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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,
}

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9d51348

Please sign in to comment.