Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix enabled query param #343

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/handler/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *crud) FindFlags(params flag.FindFlagsParams) middleware.Responder {
q := entity.Flag{}

if params.Enabled != nil {
q.Enabled = *params.Enabled
tx = tx.Where("enabled = ?", *params.Enabled)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
if params.Description != nil {
q.Description = *params.Description
Expand Down
18 changes: 18 additions & 0 deletions pkg/handler/crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ func TestCrudFlags(t *testing.T) {
assert.NotZero(t, len(res.(*flag.FindFlagsOK).Payload))
})

t.Run("it should respect the ?enabled query param", func(t *testing.T) {
res = c.FindFlags(flag.FindFlagsParams{})
allFlags := len(res.(*flag.FindFlagsOK).Payload)

res = c.FindFlags(flag.FindFlagsParams{
Enabled: util.BoolPtr(true),
})
enabledFlags := len(res.(*flag.FindFlagsOK).Payload)

res = c.FindFlags(flag.FindFlagsParams{
Enabled: util.BoolPtr(false),
})
disabledFlags := len(res.(*flag.FindFlagsOK).Payload)

assert.Equal(t, allFlags, enabledFlags+disabledFlags)
assert.NotEqual(t, allFlags, enabledFlags)
})

t.Run("it should be able to get the flag after creation", func(t *testing.T) {
res = c.GetFlag(flag.GetFlagParams{FlagID: int64(1)})
assert.NotZero(t, res.(*flag.GetFlagOK).Payload.ID)
Expand Down