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 #2291

Closed
tomsmith8 opened this issue Dec 24, 2024 · 3 comments · Fixed by #2301
Closed

[Unit Tests] - GetFilterStatusCount #2291

tomsmith8 opened this issue Dec 24, 2024 · 3 comments · Fixed by #2301
Assignees

Comments

@tomsmith8
Copy link

Unit Test Coverage for "GetFilterStatusCount"


Stakwork Run


Unit Test Code


File: /tmp/stakwork/sphinx-tribes/db/db.go


package db

import (
  "testing"

  "github.com/stretchr/testify/assert"
  "gorm.io/driver/sqlite"
  "gorm.io/gorm"
)

// Mock database setup
func setupTestDB() *gorm.DB {
  db, _ := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
  db.AutoMigrate(&Bounty{})
  return db
}

func TestGetFilterStatusCount(t *testing.T) {
  tests := []struct {
  	name     string
  	bounties []Bounty
  	expected FilterStattuCount
  }{
  	{
  		name: "Standard Case with Mixed Statuses",
  		bounties: []Bounty{
  			{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},
  		},
  		expected: FilterStattuCount{Open: 1, Assigned: 1, Completed: 1, Paid: 1, Pending: 1, Failed: 1},
  	},
  	{
  		name:     "All Records Hidden",
  		bounties: []Bounty{{Show: false}, {Show: false}},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 0, Paid: 0, Pending: 0, Failed: 0},
  	},
  	{
  		name:     "No Assignees",
  		bounties: []Bounty{{Show: true, Assignee: ""}, {Show: true, Assignee: ""}},
  		expected: FilterStattuCount{Open: 2, Assigned: 0, Completed: 0, Paid: 0, Pending: 0, Failed: 0},
  	},
  	{
  		name:     "All Paid",
  		bounties: []Bounty{{Show: true, Paid: true}, {Show: true, Paid: true}},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 0, Paid: 2, Pending: 0, Failed: 0},
  	},
  	{
  		name:     "All Completed but Not Paid",
  		bounties: []Bounty{{Show: true, Completed: true, Paid: false}, {Show: true, Completed: true, Paid: false}},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 2, Paid: 0, Pending: 0, Failed: 0},
  	},
  	{
  		name:     "All Payment Pending",
  		bounties: []Bounty{{Show: true, PaymentPending: true}, {Show: true, PaymentPending: true}},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 0, Paid: 0, Pending: 2, Failed: 0},
  	},
  	{
  		name:     "All Payment Failed",
  		bounties: []Bounty{{Show: true, PaymentFailed: true}, {Show: true, PaymentFailed: true}},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 0, Paid: 0, Pending: 0, Failed: 2},
  	},
  	{
  		name:     "Empty Database",
  		bounties: []Bounty{},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 0, Paid: 0, Pending: 0, Failed: 0},
  	},
  	{
  		name: "Single Record for Each Status",
  		bounties: []Bounty{
  			{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},
  		},
  		expected: FilterStattuCount{Open: 1, Assigned: 1, Completed: 1, Paid: 1, Pending: 1, Failed: 1},
  	},
  	{
  		name: "All Conditions False",
  		bounties: []Bounty{
  			{Show: false, Assignee: "", Paid: false},
  			{Show: false, Assignee: "", Paid: false},
  		},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 0, Paid: 0, Pending: 0, Failed: 0},
  	},
  	{
  		name: "Mixed Conditions with Overlapping Criteria",
  		bounties: []Bounty{
  			{Show: true, Assignee: "user1", Completed: true, PaymentPending: true, Paid: false},
  			{Show: true, Assignee: "user2", Completed: true, PaymentFailed: true, Paid: false},
  		},
  		expected: FilterStattuCount{Open: 0, Assigned: 0, Completed: 2, Paid: 0, Pending: 1, Failed: 1},
  	},
  }

  for _, tt := range tests {
  	t.Run(tt.name, func(t *testing.T) {
  		db := setupTestDB()
  		for _, bounty := range tt.bounties {
  			db.Create(&bounty)
  		}

  		database := database{db: db}
  		result := database.GetFilterStatusCount()

  		assert.Equal(t, tt.expected, result)
  	})
  }
}
@sophieturner0
Copy link
Contributor

@tomsmith8 assign?

@aliraza556
Copy link
Contributor

@tomsmith8 Please assign me?

@AhsanFarooqDev
Copy link
Contributor

@tomsmith8 can i help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants