From 55dd2ed72b798c68fce6ee1df4bad2163d6f1270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivar=20Conradi=20=C3=98sthus?= Date: Wed, 24 Feb 2021 13:24:28 +0100 Subject: [PATCH] fix: project id should be validated correctly on create --- src/lib/services/project-service.js | 2 +- .../e2e/services/project-service.e2e.test.js | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib/services/project-service.js b/src/lib/services/project-service.js index 3d6331bfa0..d6d52350e4 100644 --- a/src/lib/services/project-service.js +++ b/src/lib/services/project-service.js @@ -25,7 +25,7 @@ class ProjectService { async createProject(newProject, username) { const data = await schema.validateAsync(newProject); - await this.validateUniqueId(data); + await this.validateUniqueId(data.id); await this.eventStore.store({ type: eventType.PROJECT_CREATED, createdBy: username, diff --git a/src/test/e2e/services/project-service.e2e.test.js b/src/test/e2e/services/project-service.e2e.test.js index 31784d86de..dd1c7418a7 100644 --- a/src/test/e2e/services/project-service.e2e.test.js +++ b/src/test/e2e/services/project-service.e2e.test.js @@ -101,6 +101,20 @@ test.serial('should validate name, legal', async t => { t.true(result); }); +test.serial('should not be able to create exiting project', async t => { + const project = { + id: 'test-delete', + name: 'New project', + description: 'Blah', + }; + try { + await projectService.createProject(project, 'some-user'); + await projectService.createProject(project, 'some-user'); + } catch (err) { + t.is(err.message, 'A project with this id already exists.'); + } +}); + test.serial('should require URL friendly ID', async t => { try { await projectService.validateId('new name øæå'); @@ -139,7 +153,7 @@ test.serial('should update project', async t => { t.is(updatedProject.description, readProject.description); }); -test.serial('should give error when getting unkown project', async t => { +test.serial('should give error when getting unknown project', async t => { try { await projectService.getProject('unknown'); } catch (err) {