X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fusers%2Fusers.ts;h=edb0b4bb3d4a8f15669992f363d7c5390227ef33;hb=daf6e4801052d3ca6be2fafd20bae2323b1ce175;hp=db82e8fc2244217f735e4186b95f12da9d793004;hpb=5600def4c87d3e6b7724489c9c4415778ea014d3;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index db82e8fc2..edb0b4bb3 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -1,16 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { MyUser, User, UserRole, Video, VideoPlaylistType, VideoAbuseState, VideoAbuseUpdate } from '../../../../shared/index' +import * as chai from 'chai' +import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { CustomConfig } from '@shared/models/server' import { + addVideoCommentThread, blockUser, cleanupTests, createUser, deleteMe, flushAndRunServer, getAccountRatings, + getAdminAbusesList, getBlacklistedVideosList, + getCustomConfig, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, @@ -26,24 +30,23 @@ import { registerUserWithChannel, removeUser, removeVideo, + reportAbuse, ServerInfo, testImage, unblockUser, + updateAbuse, + updateCustomSubConfig, updateMyAvatar, updateMyUser, updateUser, uploadVideo, userLogin, - reportVideoAbuse, - addVideoCommentThread, - updateVideoAbuse, - getVideoAbusesList, updateCustomSubConfig, getCustomConfig, waitJobs + waitJobs } from '../../../../shared/extra-utils' import { follow } from '../../../../shared/extra-utils/server/follows' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' +import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' -import { CustomConfig } from '@shared/models/server' const expect = chai.expect @@ -60,7 +63,14 @@ describe('Test users', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + + server = await flushAndRunServer(1, { + rates_limit: { + login: { + max: 30 + } + } + }) await setAccessTokensToServers([ server ]) @@ -205,13 +215,17 @@ describe('Test users', function () { }) describe('Logout', function () { - it('Should logout (revoke token)') - - it('Should not be able to get the user information') + it('Should logout (revoke token)', async function () { + await logout(server.url, server.accessToken) + }) - it('Should not be able to upload a video') + it('Should not be able to get the user information', async function () { + await getMyUserInformation(server.url, server.accessToken, 401) + }) - it('Should not be able to remove a video') + it('Should not be able to upload a video', async function () { + await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) + }) it('Should not be able to rate a video', async function () { const path = '/api/v1/videos/' @@ -229,13 +243,17 @@ describe('Test users', function () { await makePutBodyRequest(options) }) - it('Should be able to login again') + it('Should be able to login again', async function () { + server.accessToken = await serverLogin(server) + }) it('Should have an expired access token') it('Should refresh the token') - it('Should be able to upload a video again') + it('Should be able to get my user information again', async function () { + await getMyUserInformation(server.url, server.accessToken) + }) }) describe('Creating a user', function () { @@ -247,7 +265,7 @@ describe('Test users', function () { username: user.username, password: user.password, videoQuota: 2 * 1024 * 1024, - adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST + adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) }) @@ -274,7 +292,7 @@ describe('Test users', function () { } expect(userMe.adminFlags).to.be.undefined - expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST) + expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST) expect(userMe.specialPlaylists).to.have.lengthOf(1) expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER) @@ -284,10 +302,10 @@ describe('Test users', function () { expect(userGet.videosCount).to.equal(0) expect(userGet.videoCommentsCount).to.be.a('number') expect(userGet.videoCommentsCount).to.equal(0) - expect(userGet.videoAbusesCount).to.be.a('number') - expect(userGet.videoAbusesCount).to.equal(0) - expect(userGet.videoAbusesAcceptedCount).to.be.a('number') - expect(userGet.videoAbusesAcceptedCount).to.equal(0) + expect(userGet.abusesCount).to.be.a('number') + expect(userGet.abusesCount).to.equal(0) + expect(userGet.abusesAcceptedCount).to.be.a('number') + expect(userGet.abusesAcceptedCount).to.equal(0) }) }) @@ -400,6 +418,9 @@ describe('Test users', function () { expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.nsfwPolicy).to.equal('display') + expect(rootUser.lastLoginDate).to.exist + expect(user.lastLoginDate).to.exist + userId = user.id }) @@ -798,12 +819,12 @@ describe('Test users', function () { describe('User blocking', function () { let user16Id let user16AccessToken + const user16 = { + username: 'user_16', + password: 'my super password' + } - it('Should block and unblock a user', async function () { - const user16 = { - username: 'user_16', - password: 'my super password' - } + it('Should block a user', async function () { const resUser = await createUser({ url: server.url, accessToken: server.accessToken, @@ -819,7 +840,31 @@ describe('Test users', function () { await getMyUserInformation(server.url, user16AccessToken, 401) await userLogin(server, user16, 400) + }) + + it('Should search user by banned status', async function () { + { + const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) + const users = res.body.data as User[] + + expect(res.body.total).to.equal(1) + expect(users.length).to.equal(1) + + expect(users[0].username).to.equal(user16.username) + } + + { + const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) + const users = res.body.data as User[] + + expect(res.body.total).to.equal(1) + expect(users.length).to.equal(1) + + expect(users[0].username).to.not.equal(user16.username) + } + }) + it('Should unblock a user', async function () { await unblockUser(server.url, user16Id, server.accessToken) user16AccessToken = await userLogin(server, user16) await getMyUserInformation(server.url, user16AccessToken, 200) @@ -850,9 +895,9 @@ describe('Test users', function () { expect(user.videosCount).to.equal(0) expect(user.videoCommentsCount).to.equal(0) - expect(user.videoAbusesCount).to.equal(0) - expect(user.videoAbusesCreatedCount).to.equal(0) - expect(user.videoAbusesAcceptedCount).to.equal(0) + expect(user.abusesCount).to.equal(0) + expect(user.abusesCreatedCount).to.equal(0) + expect(user.abusesAcceptedCount).to.equal(0) }) it('Should report correct videos count', async function () { @@ -879,26 +924,26 @@ describe('Test users', function () { expect(user.videoCommentsCount).to.equal(1) }) - it('Should report correct video abuses counts', async function () { + it('Should report correct abuses counts', async function () { const reason = 'my super bad reason' - await reportVideoAbuse(server.url, user17AccessToken, videoId, reason) + await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) - const res1 = await getVideoAbusesList(server.url, server.accessToken) + const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken }) const abuseId = res1.body.data[0].id const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user2: User = res2.body - expect(user2.videoAbusesCount).to.equal(1) // number of incriminations - expect(user2.videoAbusesCreatedCount).to.equal(1) // number of reports created + expect(user2.abusesCount).to.equal(1) // number of incriminations + expect(user2.abusesCreatedCount).to.equal(1) // number of reports created - const body: VideoAbuseUpdate = { state: VideoAbuseState.ACCEPTED } - await updateVideoAbuse(server.url, server.accessToken, videoId, abuseId, body) + const body: AbuseUpdate = { state: AbuseState.ACCEPTED } + await updateAbuse(server.url, server.accessToken, abuseId, body) const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user3: User = res3.body - expect(user3.videoAbusesAcceptedCount).to.equal(1) // number of reports created accepted + expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted }) })