From 9305d7298863a25d8377daa60e4e3d50031b0496 Mon Sep 17 00:00:00 2001 From: Abdul Wahab Date: Fri, 23 Feb 2024 00:54:18 +0500 Subject: [PATCH] Addressed changes --- handlers/bounty_test.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/handlers/bounty_test.go b/handlers/bounty_test.go index 61365954b..6001ac45b 100644 --- a/handlers/bounty_test.go +++ b/handlers/bounty_test.go @@ -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) }) } @@ -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) @@ -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) { @@ -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) @@ -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) {