From 424cf0985d27f1def2fce75fc166798834a24e01 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Mon, 19 Mar 2018 15:43:00 +0100 Subject: [PATCH] Added test for registering when user is already registered. --- ...GetErrorWhenRegisteringExistingUsername.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 seasoned_api/test/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js diff --git a/seasoned_api/test/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js b/seasoned_api/test/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js new file mode 100644 index 0000000..0fd4557 --- /dev/null +++ b/seasoned_api/test/system/asAUserIWantToGetErrorWhenRegisteringExistingUsername.js @@ -0,0 +1,20 @@ +const assert = require('assert'); +const request = require('supertest-as-promised'); +const app = require('src/webserver/app'); +const createUser = require('test/helpers/createUser'); +const resetDatabase = require('test/helpers/resetDatabase'); + +describe('As a user I want error when registering existing username', () => { + before(() => { + return resetDatabase() + .then(() => createUser('test_user', 'password')) + }) + + it('should return 401 with error message when same username is given', () => + request(app) + .post('/api/v1/user') + .send({ username: 'test_user', password: 'password' }) + .expect(401) + .then(response => assert.equal(response.text, '{"success":false,"error":"That username is already registered"}')) + ); +});