From 61e55fc2b8b8dc7467d54af074876ef1e382144a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rune=20Moskvil=20Lyng=C3=A5s?= Date: Fri, 10 Jun 2022 09:11:26 +0200 Subject: [PATCH] `name` must be unique --- src/mocks/handlers.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/mocks/handlers.js b/src/mocks/handlers.js index 711e5a7..53763fe 100644 --- a/src/mocks/handlers.js +++ b/src/mocks/handlers.js @@ -77,8 +77,15 @@ export const handlers = [ ) } - const { fullitem } = getReqSearchParams(req) const apiKeys = get({ top: getTop(req), type: 'apikeys' }) + if (apiKeys.data.find(key => key.name === req.body.name)) { + return res( + ctx.status(400), + ctx.json({ message: 'Error: name must be unique' }) + ) + } + + const { fullitem } = getReqSearchParams(req) const copyApiKey = apiKeys.data.length > 0 ? apiKeys.data[0] : _apikeys[0] const newApiKey = JSON.parse(JSON.stringify(copyApiKey))