Skip to content

Commit

Permalink
Addressed changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdulWahab3181 committed Feb 22, 2024
1 parent defc38d commit 9305d72
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions handlers/bounty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,13 @@ func TestGetBountyByCreated(t *testing.T) {

assert.NotEmpty(t, responseData)
assert.Len(t, responseData, 1)

returnedBounty := responseData[0].Bounty
assert.Equal(t, expectedBounty[0].ID, returnedBounty.ID)
assert.Equal(t, expectedBounty[0].Type, returnedBounty.Type)
assert.Equal(t, expectedBounty[0].Title, returnedBounty.Title)
assert.Equal(t, expectedBounty[0].Description, returnedBounty.Description)
assert.Equal(t, expectedBounty[0].Created, returnedBounty.Created)
})
}

Expand Down Expand Up @@ -629,10 +636,12 @@ func TestGetPersonAssignedBounties(t *testing.T) {
}
bHandler.generateBountyResponse = mockGenerateBountyResponse

mockDb.On("GetAssignedBounties", mock.Anything).Return([]db.Bounty{
expectedBounties := []db.Bounty{
{ID: 1, Assignee: "user1"},
{ID: 2, Assignee: "user1"},
}, nil).Once()
}

mockDb.On("GetAssignedBounties", mock.Anything).Return(expectedBounties, nil).Once()

rr := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/wanteds/assigned/uuid", nil)
Expand All @@ -653,6 +662,11 @@ func TestGetPersonAssignedBounties(t *testing.T) {

assert.NotEmpty(t, responseData)
assert.Len(t, responseData, 2)

for i, expectedBounty := range expectedBounties {
assert.Equal(t, expectedBounty.ID, responseData[i].Bounty.ID)
assert.Equal(t, expectedBounty.Assignee, responseData[i].Bounty.Assignee)
}
})

t.Run("should not return bounties assigned to other users", func(t *testing.T) {
Expand Down Expand Up @@ -719,10 +733,12 @@ func TestGetPersonCreatedBounties(t *testing.T) {
}
bHandler.generateBountyResponse = mockGenerateBountyResponse

mockDb.On("GetCreatedBounties", mock.Anything).Return([]db.Bounty{
expectedBounties := []db.Bounty{
{ID: 1, OwnerID: "user1"},
{ID: 2, OwnerID: "user1"},
}, nil).Once()
}

mockDb.On("GetCreatedBounties", mock.Anything).Return(expectedBounties, nil).Once()

rr := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/wanteds/created/uuid", nil)
Expand All @@ -743,6 +759,11 @@ func TestGetPersonCreatedBounties(t *testing.T) {

assert.NotEmpty(t, responseData)
assert.Len(t, responseData, 2)

for i, expectedBounty := range expectedBounties {
assert.Equal(t, expectedBounty.ID, responseData[i].Bounty.ID)
assert.Equal(t, expectedBounty.Assignee, responseData[i].Bounty.Assignee)
}
})

t.Run("should not return bounties created by other users", func(t *testing.T) {
Expand Down

0 comments on commit 9305d72

Please sign in to comment.