From 92b9d60c00432c58d6184f3683bdb14a0300a3c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 8 Aug 2018 10:55:27 +0200 Subject: Add ability to delete our account --- server/tests/api/check-params/users.ts | 8 +++++++- server/tests/api/users/users.ts | 17 ++++++++++++++++- server/tests/utils/users/users.ts | 11 +++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) (limited to 'server/tests') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 62faabc54..60165ae22 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -8,7 +8,7 @@ import { UserRole, VideoImport, VideoImportState } from '../../../../shared' import { createUser, flushTests, getMyUserInformation, getMyUserVideoRating, getUsersList, immutableAssign, killallServers, makeGetRequest, makePostBodyRequest, makeUploadRequest, makePutBodyRequest, registerUser, removeUser, runServer, ServerInfo, setAccessTokensToServers, - updateUser, uploadVideo, userLogin + updateUser, uploadVideo, userLogin, deleteMe } from '../../utils' import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports' @@ -469,6 +469,12 @@ describe('Test users API validators', function () { }) }) + 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 = { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 1ea599859..c9e8eb6f9 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -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' @@ -478,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 ]) diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index 37b15f64a..e24e721bd 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts @@ -56,6 +56,16 @@ function getMyUserInformation (url: string, accessToken: string, specialStatus = .expect('Content-Type', /json/) } +function deleteMe (url: string, accessToken: string, specialStatus = 204) { + const path = '/api/v1/users/me' + + return request(url) + .delete(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + .expect(specialStatus) +} + function getMyUserVideoQuotaUsed (url: string, accessToken: string, specialStatus = 200) { const path = '/api/v1/users/me/video-quota-used' @@ -216,6 +226,7 @@ export { registerUser, getMyUserInformation, getMyUserVideoRating, + deleteMe, getMyUserVideoQuotaUsed, getUsersList, getUsersListPaginationAndSort, -- cgit v1.2.3