-
Notifications
You must be signed in to change notification settings - Fork 62
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
[SuperAdmin] Add optional word clause to query for providers #1552
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,12 @@ import ( | |
"testing" | ||
|
||
"fmt" | ||
"time" | ||
|
||
"github.com/stakwork/sphinx-tribes/auth" | ||
"github.com/stakwork/sphinx-tribes/db" | ||
mocks "github.com/stakwork/sphinx-tribes/mocks" | ||
"github.com/stretchr/testify/assert" | ||
"time" | ||
) | ||
|
||
func TestBountyMetrics(t *testing.T) { | ||
|
@@ -173,6 +174,64 @@ func TestMetricsBounties(t *testing.T) { | |
assert.Equal(t, res[0].BountyDescription, "test bounty") | ||
assert.Equal(t, res[0].BountyCreated, int64(1112)) | ||
}) | ||
|
||
t.Run("should fetch bounties from db for selected providers", func(t *testing.T) { | ||
db.RedisError = errors.New("redis not initialized") | ||
rr := httptest.NewRecorder() | ||
handler := http.HandlerFunc(mh.MetricsBounties) | ||
dateRange := db.PaymentDateRange{ | ||
StartDate: "1111", | ||
EndDate: "2222", | ||
} | ||
body, _ := json.Marshal(dateRange) | ||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "/boutnies", bytes.NewReader(body)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Provide multiple provider IDs in the request query parameters | ||
req.URL.RawQuery = "provider=provider1&provider=provider2&provider=provider3" | ||
|
||
// Mock bounties data for multiple providers | ||
bounties := []db.Bounty{ | ||
{ | ||
ID: 1, | ||
OwnerID: "provider1", | ||
Price: 100, | ||
Title: "bounty 1", | ||
Description: "test bounty", | ||
Created: 1112, | ||
}, | ||
{ | ||
ID: 2, | ||
OwnerID: "provider2", | ||
Price: 100, | ||
Title: "bounty 2", | ||
Description: "test bounty", | ||
Created: 1112, | ||
}, | ||
} | ||
// Mock the database call to return bounties for the selected providers | ||
mockDb.On("GetBountiesByDateRange", dateRange, req).Return(bounties).Once() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to mock this amount of Providers, the you don't have this amount of DB calls in the request handler There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed |
||
mockDb.On("GetPersonByPubkey", "provider1").Return(db.Person{ID: 1}).Once() | ||
mockDb.On("GetPersonByPubkey", "").Return(db.Person{}).Once() | ||
mockDb.On("GetOrganizationByUuid", "").Return(db.Organization{}).Once() | ||
mockDb.On("GetPersonByPubkey", "provider2").Return(db.Person{ID: 2}).Once() | ||
mockDb.On("GetPersonByPubkey", "").Return(db.Person{}).Once() | ||
mockDb.On("GetOrganizationByUuid", "").Return(db.Organization{}).Once() | ||
|
||
handler.ServeHTTP(rr, req) | ||
|
||
var res []db.BountyData | ||
_ = json.Unmarshal(rr.Body.Bytes(), &res) | ||
|
||
assert.Equal(t, http.StatusOK, rr.Code) | ||
|
||
// Assert that the response contains bounties only from the selected providers | ||
for _, bounty := range res { | ||
assert.Contains(t, []string{"provider1", "provider2"}, bounty.OwnerID) | ||
} | ||
}) | ||
} | ||
|
||
func TestMetricsBountiesCount(t *testing.T) { | ||
|
@@ -233,6 +292,33 @@ func TestMetricsBountiesCount(t *testing.T) { | |
assert.Equal(t, http.StatusOK, rr.Code) | ||
assert.Equal(t, res, int64(100)) | ||
}) | ||
|
||
t.Run("should fetch bounties count within specified date range for selected providers", func(t *testing.T) { | ||
db.RedisError = errors.New("redis not initialized") | ||
rr := httptest.NewRecorder() | ||
handler := http.HandlerFunc(mh.MetricsBountiesCount) | ||
dateRange := db.PaymentDateRange{ | ||
StartDate: "1111", | ||
EndDate: "2222", | ||
} | ||
body, _ := json.Marshal(dateRange) | ||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, "/boutnies/count", bytes.NewReader(body)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Provide provider IDs in the request query parameters | ||
req.URL.RawQuery = "provider=provider1" | ||
|
||
mockDb.On("GetBountiesByDateRangeCount", dateRange, req).Return(int64(50)).Once() | ||
handler.ServeHTTP(rr, req) | ||
|
||
var res int64 | ||
_ = json.Unmarshal(rr.Body.Bytes(), &res) | ||
|
||
assert.Equal(t, http.StatusOK, rr.Code) | ||
assert.Equal(t, res, int64(50)) | ||
}) | ||
} | ||
|
||
func TestConvertMetricsToCSV(t *testing.T) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FaisalIqbal211 you have not updated the test to accept, a comma-separated provider string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elraphty Addressed