From f4232361da9fb67deeaedeb6a25baeff3173e9dc Mon Sep 17 00:00:00 2001 From: elraphty Date: Thu, 16 May 2024 17:11:58 +0100 Subject: [PATCH] fixed feature cypress test --- cypress/e2e/03_features.cy.ts | 37 ++++++++++++++++--------------- cypress/e2e/04_user_stories.cy.ts | 18 +++++++-------- db/features.go | 4 ++-- handlers/features.go | 5 +++-- 4 files changed, 33 insertions(+), 31 deletions(-) diff --git a/cypress/e2e/03_features.cy.ts b/cypress/e2e/03_features.cy.ts index dd2c66424..10e56a834 100644 --- a/cypress/e2e/03_features.cy.ts +++ b/cypress/e2e/03_features.cy.ts @@ -1,11 +1,11 @@ -import { User, HostName, Workspaces, Repositories, Features } from '../support/objects/objects'; +import { User, HostName, Features } from '../support/objects/objects'; describe('Create Features for Workspace', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 2; i++) { + for (let i = 0; i <= 2; i++) { cy.request({ method: 'POST', url: `${HostName}/features`, @@ -25,7 +25,7 @@ describe('Create Features for Workspace', () => { describe('Modify name for Feature', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 2; i++) { + for (let i = 0; i <= 2; i++) { cy.request({ method: 'POST', url: `${HostName}/features`, @@ -48,7 +48,7 @@ describe('Modify name for Feature', () => { describe('Modify brief for Feature', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 2; i++) { + for (let i = 0; i <= 2; i++) { cy.request({ method: 'POST', url: `${HostName}/features`, @@ -71,7 +71,7 @@ describe('Modify brief for Feature', () => { describe('Modify requirements for Feature', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 2; i++) { + for (let i = 0; i <= 2; i++) { cy.request({ method: 'POST', url: `${HostName}/features`, @@ -94,7 +94,7 @@ describe('Modify requirements for Feature', () => { describe('Modify architecture for Feature', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 2; i++) { + for (let i = 0; i <= 2; i++) { cy.request({ method: 'POST', url: `${HostName}/features`, @@ -121,17 +121,18 @@ describe('Get Features for Workspace', () => { cy.request({ method: 'GET', url: `${HostName}/features/forworkspace/` + Features[0].workspace_uuid, - headers: { 'x-jwt': `${ value }` }, - body: {} + headers: { 'x-jwt': `${value}` }, + body: {} }).then((resp) => { - expect(resp.status).to.eq(200) - for(let i = 0; i <= 2; i++) { - expect(resp.body[i]).to.have.property('name', Features[i].name.trim() + " _addtext") - expect(resp.body[i]).to.have.property('brief', Features[i].brief.trim() + " _addtext") - expect(resp.body[i]).to.have.property('requirements', Features[i].requirements.trim() + " _addtext") - expect(resp.body[i]).to.have.property('architecture', Features[i].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") } - }) + }); }) }) }) @@ -139,12 +140,12 @@ describe('Get Features for Workspace', () => { describe('Get Feature by uuid', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 2; i++) { + for (let i = 0; i <= 2; i++) { cy.request({ method: 'GET', url: `${HostName}/features/` + Features[i].uuid, - headers: { 'x-jwt': `${ value }` }, - body: {} + headers: { 'x-jwt': `${value}` }, + body: {} }).then((resp) => { expect(resp.status).to.eq(200) expect(resp.body).to.have.property('name', Features[i].name.trim() + " _addtext") diff --git a/cypress/e2e/04_user_stories.cy.ts b/cypress/e2e/04_user_stories.cy.ts index 1321ce441..3bca14d24 100644 --- a/cypress/e2e/04_user_stories.cy.ts +++ b/cypress/e2e/04_user_stories.cy.ts @@ -3,7 +3,7 @@ import { User, HostName, UserStories } from '../support/objects/objects'; describe('Create user stories for Feature', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 5; i++) { + for (let i = 0; i <= 5; i++) { cy.request({ method: 'POST', url: `${HostName}/features/story`, @@ -23,7 +23,7 @@ describe('Create user stories for Feature', () => { describe('Modify user story description', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 5; i++) { + for (let i = 0; i <= 5; i++) { cy.request({ method: 'POST', url: `${HostName}/features/story`, @@ -49,11 +49,11 @@ describe('Get user stories for feature', () => { cy.request({ method: 'GET', url: `${HostName}/features/${UserStories[0].feature_uuid}/story`, - headers: { 'x-jwt': `${ value }` }, - body: {} + headers: { 'x-jwt': `${value}` }, + body: {} }).then((resp) => { expect(resp.status).to.eq(200) - for(let i = 0; i <= 5; i++) { + for (let i = 0; i <= 5; i++) { expect(resp.body[i]).to.have.property('uuid').and.equal(UserStories[i].uuid.trim()); expect(resp.body[i]).to.have.property('feature_uuid').and.equal(UserStories[i].feature_uuid.trim()); expect(resp.body[i]).to.have.property('description').and.equal(UserStories[i].description.trim() + " _addtext"); @@ -67,7 +67,7 @@ describe('Get user stories for feature', () => { describe('Get story by uuid', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 5; i++) { + for (let i = 0; i <= 5; i++) { cy.request({ method: 'GET', url: `${HostName}/features/${UserStories[0].feature_uuid}/story/${UserStories[i].uuid}`, @@ -91,8 +91,8 @@ describe('Delete story by uuid', () => { cy.request({ method: 'DELETE', url: `${HostName}/features/${UserStories[0].feature_uuid}/story/${UserStories[0].uuid}`, - headers: { 'x-jwt': `${ value }` }, - body: {} + headers: { 'x-jwt': `${value}` }, + body: {} }).then((resp) => { expect(resp.status).to.eq(200) }) @@ -106,7 +106,7 @@ describe('Check delete by uuid', () => { cy.request({ method: 'DELETE', url: `${HostName}/features/${UserStories[0].feature_uuid}/story/${UserStories[0].uuid}`, - headers: { 'x-jwt': `${ value }` }, + headers: { 'x-jwt': `${value}` }, body: {}, failOnStatusCode: false }).then((resp) => { diff --git a/db/features.go b/db/features.go index aa7134d75..1a4a1fae4 100644 --- a/db/features.go +++ b/db/features.go @@ -67,6 +67,8 @@ func (db database) CreateOrEditFeature(m WorkspaceFeatures) (WorkspaceFeatures, db.db.Create(&m) } + db.db.Model(&WorkspaceFeatures{}).Where("uuid = ?", m.Uuid).Find(&m) + return m, nil } @@ -80,11 +82,9 @@ func (db database) CreateOrEditFeatureStory(story FeatureStory) (FeatureStory, e result := db.db.Model(&FeatureStory{}).Where("uuid = ?", story.Uuid).First(&existingStory) if result.RowsAffected == 0 { - story.Created = &now db.db.Create(&story) } else { - db.db.Model(&FeatureStory{}).Where("uuid = ?", story.Uuid).Updates(story) } diff --git a/handlers/features.go b/handlers/features.go index c798d476c..2274312a6 100644 --- a/handlers/features.go +++ b/handlers/features.go @@ -3,12 +3,13 @@ package handlers import ( "encoding/json" "fmt" + "io" + "net/http" + "github.com/go-chi/chi" "github.com/rs/xid" "github.com/stakwork/sphinx-tribes/auth" "github.com/stakwork/sphinx-tribes/db" - "io" - "net/http" ) type featureHandler struct {