From bc35208841c51d73cbd000211b8125ca0e14641b Mon Sep 17 00:00:00 2001 From: MahtabBukhari Date: Sat, 18 May 2024 10:09:20 +0500 Subject: [PATCH] update cypress tests --- cypress/e2e/01_workspaces.cy.ts | 2 +- cypress/e2e/03_features.cy.ts | 23 +++++++++++------------ handlers/features.go | 16 ++++++++++++++++ handlers/workspaces.go | 16 ---------------- routes/features.go | 1 + routes/workspaces.go | 2 -- 6 files changed, 29 insertions(+), 31 deletions(-) diff --git a/cypress/e2e/01_workspaces.cy.ts b/cypress/e2e/01_workspaces.cy.ts index 0fefa0140..f3e0c5122 100644 --- a/cypress/e2e/01_workspaces.cy.ts +++ b/cypress/e2e/01_workspaces.cy.ts @@ -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()); diff --git a/cypress/e2e/03_features.cy.ts b/cypress/e2e/03_features.cy.ts index d8e55d9c6..069980a52 100644 --- a/cypress/e2e/03_features.cy.ts +++ b/cypress/e2e/03_features.cy.ts @@ -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 => { diff --git a/handlers/features.go b/handlers/features.go index 0ae539184..77a50e359 100644 --- a/handlers/features.go +++ b/handlers/features.go @@ -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) diff --git a/handlers/workspaces.go b/handlers/workspaces.go index f56a45b14..5ed2f09e6 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -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) -} diff --git a/routes/features.go b/routes/features.go index 13c5f38c5..469e39481 100644 --- a/routes/features.go +++ b/routes/features.go @@ -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) diff --git a/routes/workspaces.go b/routes/workspaces.go index 878d9a848..d02c6e956 100644 --- a/routes/workspaces.go +++ b/routes/workspaces.go @@ -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 }