- })
-
- describe('When getting a user', function () {
- before(async function () {
- const res = await getUsersList(server.url, server.accessToken)
-
- userId = res.body.data[1].id
- })
-
- it('Should fail with an non authenticated user', async function () {
- await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 })
- })
-
- it('Should fail with a non admin user', async function () {
- await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 })
- })
-
- it('Should succeed with the correct params', async function () {
- await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 })
- })
- })
-
- describe('When updating a user', function () {
-
- before(async function () {
- const res = await getUsersList(server.url, server.accessToken)
-
- userId = res.body.data[1].id
- rootId = res.body.data[2].id
- })
-
- it('Should fail with an invalid email attribute', async function () {
- const fields = {
- email: 'blabla'
- }
-
- await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
- })
-
- it('Should fail with an invalid emailVerified attribute', async function () {
- const fields = {
- emailVerified: 'yes'
- }
-
- await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
- })
-
- it('Should fail with an invalid videoQuota attribute', async function () {
- const fields = {
- videoQuota: -90
- }
-
- await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
- })
-
- it('Should fail with an invalid user role attribute', async function () {
- const fields = {
- role: 54878
- }
-
- await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
- })
-
- it('Should fail with an non authenticated user', async function () {
- const fields = {
- videoQuota: 42
- }
-
- await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 })
- })
-
- it('Should fail when updating root role', async function () {
- const fields = {
- role: UserRole.MODERATOR
- }
-
- await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
- })
-
- it('Should succeed with the correct params', async function () {
- const fields = {
- email: 'email@example.com',
- emailVerified: true,
- videoQuota: 42,
- role: UserRole.USER
- }
-
- await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 })
- })
- })
-
- describe('When getting my information', function () {
- it('Should fail with a non authenticated user', async function () {
- await getMyUserInformation(server.url, 'fake_token', 401)
- })
-
- it('Should success with the correct parameters', async function () {
- await getMyUserInformation(server.url, userAccessToken)
- })
- })
-
- describe('When getting my video rating', function () {
- it('Should fail with a non authenticated user', async function () {
- await getMyUserVideoRating(server.url, 'fake_token', videoId, 401)
- })
-
- it('Should fail with an incorrect video uuid', async function () {
- await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400)
- })
-
- it('Should fail with an unknown video', async function () {
- await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
- })
-
- it('Should succeed with the correct parameters', async function () {
- await getMyUserVideoRating(server.url, server.accessToken, videoId)
- })
- })
-
- describe('When blocking/unblocking/removing user', function () {
- it('Should fail with an incorrect id', async function () {
- await removeUser(server.url, 'blabla', server.accessToken, 400)
- await blockUser(server.url, 'blabla', server.accessToken, 400)
- await unblockUser(server.url, 'blabla', server.accessToken, 400)
- })
-
- it('Should fail with the root user', async function () {
- await removeUser(server.url, rootId, server.accessToken, 400)
- await blockUser(server.url, rootId, server.accessToken, 400)
- await unblockUser(server.url, rootId, server.accessToken, 400)
- })
-
- it('Should return 404 with a non existing id', async function () {
- await removeUser(server.url, 4545454, server.accessToken, 404)
- await blockUser(server.url, 4545454, server.accessToken, 404)
- await unblockUser(server.url, 4545454, server.accessToken, 404)
- })
-
- it('Should fail with a non admin user', async function () {
- await removeUser(server.url, userId, userAccessToken, 403)
- await blockUser(server.url, userId, userAccessToken, 403)
- await unblockUser(server.url, userId, userAccessToken, 403)
- })
- })
-
- describe('When deleting our account', function () {
- it('Should fail with with the root account', async function () {
- await deleteMe(server.url, server.accessToken, 400)
- })
- })
-
- describe('When register a new user', function () {
- const registrationPath = path + '/register'
- const baseCorrectParams = {
- username: 'user3',
- email: 'test3@example.com',
- password: 'my super password'
- }
-
- it('Should fail with a too small username', async function () {
- const fields = immutableAssign(baseCorrectParams, { username: '' })
-
- await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
- })