diff --git a/cypress/e2e/01_workspaces.cy.ts b/cypress/e2e/01_workspaces.cy.ts index 0fefa0140..f4c030f92 100644 --- a/cypress/e2e/01_workspaces.cy.ts +++ b/cypress/e2e/01_workspaces.cy.ts @@ -1,20 +1,24 @@ import { User, HostName, Workspaces } from '../support/objects/objects'; - describe('Create Workspaces', () => { it('passes', () => { cy.upsertlogin(User).then(value => { - for(let i = 0; i <= 2; i++) { + for(let i = 0; i < Workspaces.length; 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()); + body: Workspaces[i], + failOnStatusCode: false + }).then((response) => { + expect(response.status).to.eq(200); + expect(response.body).to.have.property('name', Workspaces[i].name.trim()); + }); } - }) - }) -}) + }); + }); +}); + describe('Edit Mission', () => { it('passes', () => { diff --git a/handlers/workspaces.go b/handlers/workspaces.go index 3c7c44e7e..492df6771 100644 --- a/handlers/workspaces.go +++ b/handlers/workspaces.go @@ -111,21 +111,22 @@ func (oh *workspaceHandler) CreateOrEditWorkspace(w http.ResponseWriter, r *http name := workspace.Name - // check if the organization name already exists - workspace_same_name := oh.db.GetWorkspaceByName(name) - - if workspace_same_name.Name == name && workspace_same_name.Uuid != workspace.Uuid { - w.WriteHeader(http.StatusUnauthorized) - json.NewEncoder(w).Encode("Workspace name already exists - " + name + " " + workspace.Uuid + " | " + workspace_same_name.Uuid) + // check if the workspace name already exists + workspaceSameName := oh.db.GetWorkspaceByName(name) + if workspaceSameName.Name == name { + w.WriteHeader(http.StatusConflict) + json.NewEncoder(w).Encode("Workspace name already exists - " + name) return - } else { - workspace.Created = &now - workspace.Updated = &now - if len(workspace.Uuid) == 0 { - workspace.Uuid = xid.New().String() - } - workspace.Name = name } + + workspace.Created = &now + workspace.Updated = &now + if len(workspace.Uuid) == 0 { + workspace.Uuid = xid.New().String() + } + } else { + workspace.Updated = &now + workspace.Created = existing.Created } p, err := oh.db.CreateOrEditWorkspace(workspace)