Skip to content

Commit

Permalink
Merge pull request #1935 from aliraza556/phase-create-bounty
Browse files Browse the repository at this point in the history
Fixed [Bug]: Issue with Creating `Bounty` as `Phase` Part of a Feature Not Registering Correctly
  • Loading branch information
elraphty authored Nov 12, 2024
2 parents d7b8012 + ffc283d commit 35936ca
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 7 deletions.
7 changes: 5 additions & 2 deletions handlers/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import (
"net/http"
"time"

"os"

"github.com/go-chi/chi"
"github.com/rs/xid"
"github.com/stakwork/sphinx-tribes/auth"
"github.com/stakwork/sphinx-tribes/db"
"os"
)

type PostData struct {
Expand Down Expand Up @@ -396,8 +397,10 @@ func (oh *featureHandler) GetBountiesByFeatureAndPhaseUuid(w http.ResponseWriter
return
}

bountyResponses := oh.generateBountyHandler(bounties)

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bounties)
json.NewEncoder(w).Encode(bountyResponses)
}

func (oh *featureHandler) GetBountiesCountByFeatureAndPhaseUuid(w http.ResponseWriter, r *http.Request) {
Expand Down
103 changes: 98 additions & 5 deletions handlers/features_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/go-chi/chi"
"github.com/google/uuid"
"github.com/lib/pq"
"github.com/stakwork/sphinx-tribes/auth"
"github.com/stakwork/sphinx-tribes/db"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -1265,7 +1266,7 @@ func TestGetBountiesByFeatureAndPhaseUuid(t *testing.T) {
assert.Equal(t, http.StatusUnauthorized, rr.Code)
})

t.Run("should return the correct bounty count if user is authorized", func(t *testing.T) {
t.Run("should return the correct bounty if user is authorized", func(t *testing.T) {
rctx := chi.NewRouteContext()
rctx.URLParams.Add("feature_uuid", feature.Uuid)
rctx.URLParams.Add("phase_uuid", featurePhase.Uuid)
Expand All @@ -1277,17 +1278,109 @@ func TestGetBountiesByFeatureAndPhaseUuid(t *testing.T) {
rr := httptest.NewRecorder()
http.HandlerFunc(fHandler.GetBountiesByFeatureAndPhaseUuid).ServeHTTP(rr, req)

var returnedBounty []db.NewBounty
err = json.Unmarshal(rr.Body.Bytes(), &returnedBounty)
var returnedBounties []db.BountyResponse
err = json.Unmarshal(rr.Body.Bytes(), &returnedBounties)
assert.NoError(t, err)

bounty.ID = returnedBounty[0].ID
assert.Equal(t, http.StatusOK, rr.Code)
assert.Equal(t, 1, len(returnedBounties))
assert.Equal(t, bounty.Title, returnedBounties[0].Bounty.Title)
assert.Equal(t, bounty.Description, returnedBounties[0].Bounty.Description)
assert.Equal(t, bounty.Price, returnedBounties[0].Bounty.Price)
assert.Equal(t, bounty.PhaseUuid, returnedBounties[0].Bounty.PhaseUuid)
})

t.Run("should phase return the correct bounty response structure", func(t *testing.T) {
rctx := chi.NewRouteContext()
rctx.URLParams.Add("feature_uuid", feature.Uuid)
rctx.URLParams.Add("phase_uuid", featurePhase.Uuid)
req, err := http.NewRequestWithContext(context.WithValue(ctx, chi.RouteCtxKey, rctx), http.MethodGet, "/features/"+feature.Uuid+"/phase/"+featurePhase.Uuid+"/bounty", nil)
if err != nil {
t.Fatal(err)
}

rr := httptest.NewRecorder()
http.HandlerFunc(fHandler.GetBountiesByFeatureAndPhaseUuid).ServeHTTP(rr, req)

var returnedBounties []db.BountyResponse
err = json.Unmarshal(rr.Body.Bytes(), &returnedBounties)
assert.NoError(t, err)

assert.Equal(t, http.StatusOK, rr.Code)
assert.Equal(t, bounty, returnedBounty[0])
assert.Equal(t, 1, len(returnedBounties))

expectedBounty := db.BountyResponse{
Bounty: db.NewBounty{
ID: returnedBounties[0].Bounty.ID,
OwnerID: person.OwnerPubKey,
Paid: false,
Show: false,
Completed: false,
Type: "coding_task",
Award: "",
AssignedHours: 0,
CommitmentFee: 0,
Price: 1000,
Title: "test-bounty",
Tribe: "",
Assignee: "",
TicketUrl: "",
OrgUuid: workspace.Uuid,
WorkspaceUuid: workspace.Uuid,
Description: "test-description",
WantedType: "",
Deliverables: "",
GithubDescription: false,
OneSentenceSummary: "",
EstimatedSessionLength: "",
EstimatedCompletionDate: "",
Created: 0,
Updated: nil,
PhaseUuid: featurePhase.Uuid,
PhasePriority: 0,
PaymentPending: false,
PaymentFailed: false,
},
Assignee: db.Person{},
Owner: db.Person{
ID: returnedBounties[0].Owner.ID,
Uuid: person.Uuid,
OwnerPubKey: person.OwnerPubKey,
OwnerAlias: person.OwnerAlias,
UniqueName: person.UniqueName,
Description: person.Description,
Tags: pq.StringArray{},
Img: "",
},
Organization: db.WorkspaceShort{
Uuid: workspace.Uuid,
Name: workspace.Name,
Img: "",
},
Workspace: db.WorkspaceShort{
Uuid: workspace.Uuid,
Name: workspace.Name,
Img: "",
},
}

assert.Equal(t, expectedBounty, returnedBounties[0])
})

t.Run("should return 404 if feature or phase UUID is invalid", func(t *testing.T) {
rctx := chi.NewRouteContext()
rctx.URLParams.Add("feature_uuid", "invalid-feature-uuid")
rctx.URLParams.Add("phase_uuid", "invalid-phase-uuid")
req, err := http.NewRequestWithContext(context.WithValue(ctx, chi.RouteCtxKey, rctx), http.MethodGet, "/features/invalid-feature-uuid/phase/invalid-phase-uuid/bounty", nil)
if err != nil {
t.Fatal(err)
}

rr := httptest.NewRecorder()
http.HandlerFunc(fHandler.GetBountiesByFeatureAndPhaseUuid).ServeHTTP(rr, req)

assert.Equal(t, http.StatusNotFound, rr.Code)
})
}

func TestGetBountiesCountByFeatureAndPhaseUuid(t *testing.T) {
Expand Down

0 comments on commit 35936ca

Please sign in to comment.