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

[Unit Tests] - GetFilterStatusCount #2301

Merged
Merged
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
138 changes: 138 additions & 0 deletions db/db_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
package db

import (
"reflect"
"testing"
)

func TestGetFilterStatusCount(t *testing.T) {

InitTestDB()

tests := []struct {
name string
setup []NewBounty
expected FilterStattuCount
}{
{
name: "Empty Database",
setup: []NewBounty{},
expected: FilterStattuCount{
Open: 0, Assigned: 0, Completed: 0,
Paid: 0, Pending: 0, Failed: 0,
},
},
{
name: "Hidden Bounties Should Not Count",
setup: []NewBounty{
{Show: false, Assignee: "", Paid: false},
{Show: false, Assignee: "user1", Completed: true},
},
expected: FilterStattuCount{
Open: 0, Assigned: 0, Completed: 0,
Paid: 0, Pending: 0, Failed: 0,
},
},
{
name: "Open Bounties Count",
setup: []NewBounty{
{Show: true, Assignee: "", Paid: false},
{Show: true, Assignee: "", Paid: false},
},
expected: FilterStattuCount{
Open: 2, Assigned: 0, Completed: 0,
Paid: 0, Pending: 0, Failed: 0,
},
},
{
name: "Assigned Bounties Count",
setup: []NewBounty{
{Show: true, Assignee: "user1", Paid: false},
{Show: true, Assignee: "user2", Paid: false},
},
expected: FilterStattuCount{
Open: 0, Assigned: 2, Completed: 0,
Paid: 0, Pending: 0, Failed: 0,
},
},
{
name: "Completed Bounties Count",
setup: []NewBounty{
{Show: true, Assignee: "user1", Completed: true, Paid: false},
{Show: true, Assignee: "user2", Completed: true, Paid: false},
},
expected: FilterStattuCount{
Open: 0, Assigned: 2, Completed: 2,
Paid: 0, Pending: 0, Failed: 0,
},
},
{
name: "Paid Bounties Count",
setup: []NewBounty{
{Show: true, Assignee: "user1", Paid: true},
{Show: true, Assignee: "user2", Paid: true},
},
expected: FilterStattuCount{
Open: 0, Assigned: 0, Completed: 0,
Paid: 2, Pending: 0, Failed: 0,
},
},
{
name: "Pending Payment Bounties Count",
setup: []NewBounty{
{Show: true, Assignee: "user1", PaymentPending: true},
{Show: true, Assignee: "user2", PaymentPending: true},
},
expected: FilterStattuCount{
Open: 0, Assigned: 2, Completed: 0,
Paid: 0, Pending: 2, Failed: 0,
},
},
{
name: "Failed Payment Bounties Count",
setup: []NewBounty{
{Show: true, Assignee: "user1", PaymentFailed: true},
{Show: true, Assignee: "user2", PaymentFailed: true},
},
expected: FilterStattuCount{
Open: 0, Assigned: 2, Completed: 0,
Paid: 0, Pending: 0, Failed: 2,
},
},
{
name: "Mixed Status Bounties",
setup: []NewBounty{
{Show: true, Assignee: "", Paid: false},
{Show: true, Assignee: "user1", Paid: false},
{Show: true, Assignee: "user2", Completed: true, Paid: false},
{Show: true, Assignee: "user3", Paid: true},
{Show: true, Assignee: "user4", PaymentPending: true},
{Show: true, Assignee: "user5", PaymentFailed: true},
{Show: false, Assignee: "user6", Paid: true},
},
expected: FilterStattuCount{
Open: 1, Assigned: 4, Completed: 1,
Paid: 1, Pending: 1, Failed: 1,
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

TestDB.DeleteAllBounties()

for _, bounty := range tt.setup {
if err := TestDB.db.Create(&bounty).Error; err != nil {
t.Fatalf("Failed to create test bounty: %v", err)
}
}

result := TestDB.GetFilterStatusCount()

if !reflect.DeepEqual(result, tt.expected) {
t.Errorf("GetFilterStatusCount() = %+v, want %+v", result, tt.expected)
}
})
}
}
Loading