]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/users/users.ts
Add ability to delete our account
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / users.ts
index ac167d4f97c20e404a3ed2898acf0f8e2c9d9c41..c9e8eb6f9310bd77ace07daa6c0bfea1e030475c 100644 (file)
@@ -6,7 +6,8 @@ import { UserRole } from '../../../../shared/index'
 import {
   createUser, flushTests, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating,
   getUserInformation, getUsersList, getUsersListPaginationAndSort, getVideosList, killallServers, login, makePutBodyRequest, rateVideo,
-  registerUser, removeUser, removeVideo, runServer, ServerInfo, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo, userLogin
+  registerUser, removeUser, removeVideo, runServer, ServerInfo, testImage, updateMyAvatar, updateMyUser, updateUser, uploadVideo, userLogin,
+  deleteMe
 } from '../../utils/index'
 import { follow } from '../../utils/server/follows'
 import { setAccessTokensToServers } from '../../utils/users/login'
@@ -94,7 +95,7 @@ describe('Test users', function () {
     const res = await getVideosList(server.url)
     const video = res.body.data[ 0 ]
 
-    expect(video.accountName).to.equal('root')
+    expect(video.account.name).to.equal('root')
     videoId = video.id
   })
 
@@ -168,10 +169,12 @@ 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.false
+    expect(user.nsfwPolicy).to.equal('display')
     expect(user.videoQuota).to.equal(2 * 1024 * 1024)
     expect(user.roleLabel).to.equal('User')
     expect(user.id).to.be.a('number')
+    expect(user.account.displayName).to.equal('user_1')
+    expect(user.account.description).to.be.null
   })
 
   it('Should be able to upload a video with this user', async function () {
@@ -214,12 +217,12 @@ 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.false
+    expect(user.nsfwPolicy).to.equal('display')
 
     const rootUser = users[ 1 ]
     expect(rootUser.username).to.equal('root')
     expect(rootUser.email).to.equal('admin1@example.com')
-    expect(rootUser.displayNSFW).to.be.false
+    expect(user.nsfwPolicy).to.equal('display')
 
     userId = user.id
   })
@@ -238,7 +241,7 @@ describe('Test users', function () {
     expect(user.username).to.equal('root')
     expect(user.email).to.equal('admin1@example.com')
     expect(user.roleLabel).to.equal('Administrator')
-    expect(user.displayNSFW).to.be.false
+    expect(user.nsfwPolicy).to.equal('display')
   })
 
   it('Should list only the first user by username desc', async function () {
@@ -253,7 +256,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.false
+    expect(user.nsfwPolicy).to.equal('display')
   })
 
   it('Should list only the second user by createdAt desc', async function () {
@@ -268,7 +271,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.false
+    expect(user.nsfwPolicy).to.equal('display')
   })
 
   it('Should list all the users by createdAt asc', async function () {
@@ -282,11 +285,11 @@ 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.false
+    expect(users[ 0 ].nsfwPolicy).to.equal('display')
 
     expect(users[ 1 ].username).to.equal('user_1')
     expect(users[ 1 ].email).to.equal('user_1@example.com')
-    expect(users[ 1 ].displayNSFW).to.be.false
+    expect(users[ 1 ].nsfwPolicy).to.equal('display')
   })
 
   it('Should update my password', async function () {
@@ -304,7 +307,7 @@ describe('Test users', function () {
     await updateMyUser({
       url: server.url,
       accessToken: accessTokenUser,
-      displayNSFW: true
+      nsfwPolicy: 'do_not_list'
     })
 
     const res = await getMyUserInformation(server.url, accessTokenUser)
@@ -312,9 +315,11 @@ 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.ok
+    expect(user.nsfwPolicy).to.equal('do_not_list')
     expect(user.videoQuota).to.equal(2 * 1024 * 1024)
     expect(user.id).to.be.a('number')
+    expect(user.account.displayName).to.equal('user_1')
+    expect(user.account.description).to.be.null
   })
 
   it('Should be able to change the autoPlayVideo attribute', async function () {
@@ -342,9 +347,11 @@ describe('Test users', function () {
 
     expect(user.username).to.equal('user_1')
     expect(user.email).to.equal('updated@example.com')
-    expect(user.displayNSFW).to.be.ok
+    expect(user.nsfwPolicy).to.equal('do_not_list')
     expect(user.videoQuota).to.equal(2 * 1024 * 1024)
     expect(user.id).to.be.a('number')
+    expect(user.account.displayName).to.equal('user_1')
+    expect(user.account.description).to.be.null
   })
 
   it('Should be able to update my avatar', async function () {
@@ -362,6 +369,44 @@ describe('Test users', function () {
     await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
   })
 
+  it('Should be able to update my display name', async function () {
+    await updateMyUser({
+      url: server.url,
+      accessToken: accessTokenUser,
+      displayName: 'new display name'
+    })
+
+    const res = await getMyUserInformation(server.url, accessTokenUser)
+    const user = res.body
+
+    expect(user.username).to.equal('user_1')
+    expect(user.email).to.equal('updated@example.com')
+    expect(user.nsfwPolicy).to.equal('do_not_list')
+    expect(user.videoQuota).to.equal(2 * 1024 * 1024)
+    expect(user.id).to.be.a('number')
+    expect(user.account.displayName).to.equal('new display name')
+    expect(user.account.description).to.be.null
+  })
+
+  it('Should be able to update my description', async function () {
+    await updateMyUser({
+      url: server.url,
+      accessToken: accessTokenUser,
+      description: 'my super description updated'
+    })
+
+    const res = await getMyUserInformation(server.url, accessTokenUser)
+    const user = res.body
+
+    expect(user.username).to.equal('user_1')
+    expect(user.email).to.equal('updated@example.com')
+    expect(user.nsfwPolicy).to.equal('do_not_list')
+    expect(user.videoQuota).to.equal(2 * 1024 * 1024)
+    expect(user.id).to.be.a('number')
+    expect(user.account.displayName).to.equal('new display name')
+    expect(user.account.description).to.equal('my super description updated')
+  })
+
   it('Should be able to update another user', async function () {
     await updateUser({
       url: server.url,
@@ -377,7 +422,7 @@ describe('Test users', function () {
 
     expect(user.username).to.equal('user_1')
     expect(user.email).to.equal('updated2@example.com')
-    expect(user.displayNSFW).to.be.ok
+    expect(user.nsfwPolicy).to.equal('do_not_list')
     expect(user.videoQuota).to.equal(42)
     expect(user.roleLabel).to.equal('Moderator')
     expect(user.id).to.be.a('number')
@@ -411,7 +456,7 @@ describe('Test users', function () {
     expect(res.body.total).to.equal(1)
 
     const video = res.body.data[ 0 ]
-    expect(video.accountName).to.equal('root')
+    expect(video.account.name).to.equal('root')
   })
 
   it('Should register a new user', async function () {
@@ -434,6 +479,20 @@ describe('Test users', function () {
     expect(user.videoQuota).to.equal(5 * 1024 * 1024)
   })
 
+  it('Should remove me', async function () {
+    {
+      const res = await getUsersList(server.url, server.accessToken)
+      expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
+    }
+
+    await deleteMe(server.url, accessToken)
+
+    {
+      const res = await getUsersList(server.url, server.accessToken)
+      expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
+    }
+  })
+
   after(async function () {
     killallServers([ server ])