From 6491db419186a558019f3708878c9f3e6478787d Mon Sep 17 00:00:00 2001 From: "Juan Picado @jotadeveloper" Date: Tue, 3 Apr 2018 07:08:44 +0200 Subject: [PATCH] fix: api login use case when user already exist It adds a new use case based on the plugin update. 409 in case user exists already and 201 when new user has been created. --- test/unit/api.spec.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/unit/api.spec.js b/test/unit/api.spec.js index 56e6e3fd8..98e8859d2 100644 --- a/test/unit/api.spec.js +++ b/test/unit/api.spec.js @@ -146,12 +146,14 @@ describe('endpoint unit test', () => { }); test('should test add a new user with login', (done) => { + const newCredentials = _.clone(credentials); + newCredentials.name = 'jotaNew'; request(app) - .put('/-/user/org.couchdb.user:jota') - .send(credentials) + .put('/-/user/org.couchdb.user:jotaNew') + .send(newCredentials) .expect('Content-Type', /json/) - .expect(200) + .expect(201) .end(function(err, res) { if (err) { return done(err); @@ -161,6 +163,22 @@ describe('endpoint unit test', () => { }); }); + test('should test fails on add a existing user with login', (done) => { + request(app) + .put('/-/user/org.couchdb.user:jotaNew') + .send(credentials) + .expect('Content-Type', /json/) + .expect(409) + .end(function(err, res) { + if (err) { + return done(err); + } + expect(res.body.error).toBeDefined(); + expect(res.body.error).toMatch(/username is already registered/); + done(); + }); + }); + test('should test fails add a new user with wrong password', (done) => { const credentialsShort = _.clone(credentials);