From 1d49e1e27d63db1dfc9a7fd28c9902f488831a89 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 3 Apr 2017 21:24:36 +0200 Subject: Server: Add NSFW in user profile --- server/tests/api/check-params/users.js | 11 ++++++++++- server/tests/api/users.js | 31 ++++++++++++++++++++++++++++++- server/tests/utils/users.js | 8 ++++++-- 3 files changed, 46 insertions(+), 4 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js index b04f9f4a6..4a176e6c2 100644 --- a/server/tests/api/check-params/users.js +++ b/server/tests/api/check-params/users.js @@ -270,6 +270,14 @@ describe('Test users API validators', function () { requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) }) + it('Should fail with an invalid display NSFW attribute', function (done) { + const data = { + displayNSFW: -1 + } + + requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done) + }) + it('Should fail with an non authenticated user', function (done) { const data = { password: 'my super password' @@ -280,7 +288,8 @@ describe('Test users API validators', function () { it('Should succeed with the correct params', function (done) { const data = { - password: 'my super password' + password: 'my super password', + displayNSFW: true } requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204) diff --git a/server/tests/api/users.js b/server/tests/api/users.js index 2b6956baa..a5e8a7edf 100644 --- a/server/tests/api/users.js +++ b/server/tests/api/users.js @@ -209,6 +209,7 @@ describe('Test users', function () { expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') + expect(user.displayNSFW).to.be.falsy expect(user.id).to.exist done() @@ -237,10 +238,13 @@ describe('Test users', function () { const user = users[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') + expect(user.displayNSFW).to.be.falsy const rootUser = users[1] expect(rootUser.username).to.equal('root') expect(rootUser.email).to.equal('admin1@example.com') + expect(rootUser.displayNSFW).to.be.falsy + userId = user.id done() @@ -261,6 +265,7 @@ describe('Test users', function () { const user = users[0] expect(user.username).to.equal('root') expect(user.email).to.equal('admin1@example.com') + expect(user.displayNSFW).to.be.falsy done() }) @@ -280,6 +285,7 @@ describe('Test users', function () { const user = users[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') + expect(user.displayNSFW).to.be.falsy done() }) @@ -299,6 +305,7 @@ describe('Test users', function () { const user = users[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') + expect(user.displayNSFW).to.be.falsy done() }) @@ -317,15 +324,18 @@ describe('Test users', function () { expect(users[0].username).to.equal('root') expect(users[0].email).to.equal('admin1@example.com') + expect(users[0].displayNSFW).to.be.falsy + expect(users[1].username).to.equal('user_1') expect(users[1].email).to.equal('user_1@example.com') + expect(users[1].displayNSFW).to.be.falsy done() }) }) it('Should update the user password', function (done) { - usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', function (err, res) { + usersUtils.updateUser(server.url, userId, accessTokenUser, 'new password', null, function (err, res) { if (err) throw err server.user.password = 'new password' @@ -333,6 +343,25 @@ describe('Test users', function () { }) }) + it('Should be able to change the NSFW display attribute', function (done) { + usersUtils.updateUser(server.url, userId, accessTokenUser, null, true, function (err, res) { + if (err) throw err + + usersUtils.getUserInformation(server.url, accessTokenUser, function (err, res) { + if (err) throw err + + const user = res.body + + expect(user.username).to.equal('user_1') + expect(user.email).to.equal('user_1@example.com') + expect(user.displayNSFW).to.be.truthy + expect(user.id).to.exist + + done() + }) + }) + }) + it('Should be able to remove this user', function (done) { usersUtils.removeUser(server.url, userId, accessToken, done) }) diff --git a/server/tests/utils/users.js b/server/tests/utils/users.js index 7817160b9..8138074d0 100644 --- a/server/tests/utils/users.js +++ b/server/tests/utils/users.js @@ -101,14 +101,18 @@ function removeUser (url, userId, accessToken, expectedStatus, end) { .end(end) } -function updateUser (url, userId, accessToken, newPassword, end) { +function updateUser (url, userId, accessToken, newPassword, displayNSFW, end) { const path = '/api/v1/users/' + userId + const toSend = {} + if (newPassword !== undefined && newPassword !== null) toSend.password = newPassword + if (displayNSFW !== undefined && displayNSFW !== null) toSend.displayNSFW = displayNSFW + request(url) .put(path) .set('Accept', 'application/json') .set('Authorization', 'Bearer ' + accessToken) - .send({ password: newPassword }) + .send(toSend) .expect(204) .end(end) } -- cgit v1.2.3