+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 })
+ })
+
+ it('Should fail with a too long description', async function () {
+ const fields = {
+ description: 'super'.repeat(201)
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ })
+
+ it('Should fail with an invalid videoLanguages attribute', async function () {
+ {
+ const fields = {
+ videoLanguages: 'toto'
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ }
+
+ {
+ const languages = []
+ for (let i = 0; i < 1000; i++) {
+ languages.push('fr')
+ }
+
+ const fields = {
+ videoLanguages: languages
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ }
+ })
+
+ it('Should fail with an invalid theme', async function () {
+ const fields = { theme: 'invalid' }
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ })
+
+ it('Should fail with an unknown theme', async function () {
+ const fields = { theme: 'peertube-theme-unknown' }
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields })
+ })
+
+ it('Should succeed to change password with the correct params', async function () {
+ const fields = {
+ currentPassword: 'my super password',
+ password: 'my super password',
+ nsfwPolicy: 'blur',
+ autoPlayVideo: false,
+ email: 'super_email@example.com',
+ theme: 'default'
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
+ })
+
+ it('Should succeed without password change with the correct params', async function () {
+ const fields = {
+ nsfwPolicy: 'blur',
+ autoPlayVideo: false
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 })
+ })
+ })
+
+ describe('When updating my avatar', function () {
+ it('Should fail without an incorrect input file', async function () {
+ const fields = {}
+ const attaches = {
+ 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
+ }
+ await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
+ })
+
+ it('Should fail with a big file', async function () {
+ const fields = {}
+ const attaches = {
+ 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
+ }
+ await makeUploadRequest({ url: server.url, path: path + '/me/avatar/pick', token: server.accessToken, fields, attaches })
+ })
+
+ it('Should fail with an unauthenticated user', async function () {
+ const fields = {}
+ const attaches = {
+ 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
+ }
+ await makeUploadRequest({
+ url: server.url,
+ path: path + '/me/avatar/pick',
+ fields,
+ attaches,
+ statusCodeExpected: 401
+ })
+ })
+
+ it('Should succeed with the correct params', async function () {
+ const fields = {}
+ const attaches = {
+ 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
+ }
+ await makeUploadRequest({
+ url: server.url,
+ path: path + '/me/avatar/pick',
+ token: server.accessToken,
+ fields,
+ attaches,
+ statusCodeExpected: 200
+ })
+ })
+ })
+
+ describe('When getting a user', function () {
+
+ 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 () {
+
+ 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 a too small password', async function () {
+ const fields = {
+ currentPassword: 'my super password',
+ password: 'bla'
+ }
+
+ await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields })
+ })
+
+ it('Should fail with a too long password', async function () {
+ const fields = {
+ currentPassword: 'my super password',
+ password: 'super'.repeat(61)
+ }
+
+ 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
+ }
+