Skip to content

Commit

Permalink
update cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MahtabBukhari committed May 18, 2024
1 parent ed65040 commit bc35208
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/01_workspaces.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('Create Workspaces', () => {
for(let i = 0; i <= 2; i++) {
cy.request({
method: 'POST',
url: `${HostName}/workspaces/`,
url: `${HostName}/workspaces`,
headers: { 'x-jwt': `${value}` },
body: Workspaces[i]
}).its('body').should('have.property', 'name', Workspaces[i].name.trim());
Expand Down
23 changes: 11 additions & 12 deletions cypress/e2e/03_features.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,23 @@ describe('Get Features for Workspace', () => {
cy.upsertlogin(User).then(value => {
cy.request({
method: 'GET',
url: `${HostName}/workspaces/${Features[0].workspace_uuid}/features`,
headers: { 'x-jwt': `${ value }` },
url: `${HostName}/features/forworkspace/` + Features[0].workspace_uuid,
headers: { 'x-jwt': `${value}` },
body: {}
}).then((resp) => {
expect(resp.status).to.eq(200)
resp.body.forEach((feature) => {
const expectedFeature = Features.find(f => f.uuid === feature.uuid);
expect(feature).to.have.property('name', expectedFeature.name.trim() + " _addtext");
expect(feature).to.have.property('brief', expectedFeature.brief.trim() + " _addtext");
expect(feature).to.have.property('requirements', expectedFeature.requirements.trim() + " _addtext");
expect(feature).to.have.property('architecture', expectedFeature.architecture.trim() + " _addtext");
});
})
expect(resp.status).to.eq(200);
const body = resp.body.reverse();
for (let i = 0; i <= 2; i++) {
expect(body[i]).to.have.property('name', Features[i].name.trim() + " _addtext")
expect(body[i]).to.have.property('brief', Features[i].brief.trim() + " _addtext")
expect(body[i]).to.have.property('requirements', Features[i].requirements.trim() + " _addtext")
expect(body[i]).to.have.property('architecture', Features[i].architecture.trim() + " _addtext")
}
});
})
})
})


describe('Get Feature by uuid', () => {
it('passes', () => {
cy.upsertlogin(User).then(value => {
Expand Down
16 changes: 16 additions & 0 deletions handlers/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ func (oh *featureHandler) GetWorkspaceFeaturesCount(w http.ResponseWriter, r *ht
json.NewEncoder(w).Encode(workspaceFeatures)
}

func (oh *featureHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}

uuid := chi.URLParam(r, "uuid")
workspaceFeatures := oh.db.GetFeaturesByWorkspaceUuid(uuid, r)

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workspaceFeatures)
}

func (oh *featureHandler) GetFeatureByUuid(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
Expand Down
16 changes: 0 additions & 16 deletions handlers/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,19 +845,3 @@ func (oh *workspaceHandler) GetWorkspaceRepositorByWorkspaceUuid(w http.Response
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workspaceFeatures)
}

func (oh *workspaceHandler) GetFeaturesByWorkspaceUuid(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pubKeyFromAuth, _ := ctx.Value(auth.ContextKey).(string)
if pubKeyFromAuth == "" {
fmt.Println("no pubkey from auth")
w.WriteHeader(http.StatusUnauthorized)
return
}

uuid := chi.URLParam(r, "workspace_uuid")
workspaceFeatures := oh.db.GetFeaturesByWorkspaceUuid(uuid, r)

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(workspaceFeatures)
}
1 change: 1 addition & 0 deletions routes/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func FeatureRoutes() chi.Router {

r.Post("/", featureHandlers.CreateOrEditFeatures)
r.Get("/{uuid}", featureHandlers.GetFeatureByUuid)
r.Get("/forworkspace/{uuid}", featureHandlers.GetFeaturesByWorkspaceUuid)
r.Get("/workspace/count/{uuid}", featureHandlers.GetWorkspaceFeaturesCount)
r.Delete("/{uuid}", featureHandlers.DeleteFeature)

Expand Down
2 changes: 0 additions & 2 deletions routes/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func WorkspaceRoutes() chi.Router {

r.Post("/repositories", workspaceHandlers.CreateWorkspaceRepository)
r.Get("/repositories/{uuid}", workspaceHandlers.GetWorkspaceRepositorByWorkspaceUuid)

r.Get("/{workspace_uuid}/features", workspaceHandlers.GetFeaturesByWorkspaceUuid)
})
return r
}

0 comments on commit bc35208

Please sign in to comment.