From 8ef9457fdee7812b1a8cc3b3bdeff94130819003 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 10:36:54 +0200 Subject: Correctly export misc files --- server/tests/api/users/users-verification.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index e0f2f2112..265cd6050 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -1,7 +1,8 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' import { cleanupTests, flushAndRunServer, @@ -15,11 +16,10 @@ import { userLogin, verifyEmail } from '../../../../shared/extra-utils' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' +import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { User } from '../../../../shared/models/users' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect -- cgit v1.2.3 From 0c1a77e9ccf915184c431145a8b326d4ce271b46 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 6 Jul 2021 12:01:59 +0200 Subject: Introduce abuse command --- server/tests/api/users/users.ts | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 87ba775f6..6bfc7cfe5 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,9 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models' -import { CustomConfig, OAuth2ErrorCode } from '@shared/models/server' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { addVideoCommentThread, blockUser, @@ -13,13 +11,14 @@ import { createUser, deleteMe, flushAndRunServer, + follow, getAccountRatings, - getAdminAbusesList, getBlacklistedVideosList, getCustomConfig, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, + getMyVideos, getUserInformation, getUsersList, getUsersListPaginationAndSort, @@ -28,18 +27,19 @@ import { installPlugin, killallServers, login, + logout, makePutBodyRequest, rateVideo, + refreshToken, registerUserWithChannel, removeUser, removeVideo, - reportAbuse, reRunServer, ServerInfo, + setAccessTokensToServers, setTokenField, testImage, unblockUser, - updateAbuse, updateCustomSubConfig, updateMyAvatar, updateMyUser, @@ -47,11 +47,8 @@ import { uploadVideo, userLogin, waitJobs -} from '../../../../shared/extra-utils' -import { follow } from '../../../../shared/extra-utils/server/follows' -import { logout, refreshToken, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' -import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +} from '@shared/extra-utils' +import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect @@ -1002,10 +999,10 @@ describe('Test users', function () { it('Should report correct abuses counts', async function () { const reason = 'my super bad reason' - await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason }) + await server.abusesCommand.report({ token: user17AccessToken, videoId, reason }) - const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken }) - const abuseId = res1.body.data[0].id + const body1 = await server.abusesCommand.getAdminList() + const abuseId = body1.data[0].id const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user2: User = res2.body @@ -1013,8 +1010,7 @@ describe('Test users', function () { expect(user2.abusesCount).to.equal(1) // number of incriminations expect(user2.abusesCreatedCount).to.equal(1) // number of reports created - const body: AbuseUpdate = { state: AbuseState.ACCEPTED } - await updateAbuse(server.url, server.accessToken, abuseId, body) + await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) const user3: User = res3.body -- cgit v1.2.3 From c3d29f694bf8c910f917be655626d0f80871124f Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 09:16:40 +0200 Subject: Introduce follows command --- server/tests/api/users/user-subscriptions.ts | 33 +++++++++++++--------------- server/tests/api/users/users.ts | 8 +++++-- 2 files changed, 21 insertions(+), 20 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 60676a37b..7e365d797 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -1,30 +1,27 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' import { + addUserSubscription, + areSubscriptionsExist, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - follow, - getVideosList, - unfollow, - updateVideo, - userLogin -} from '../../../../shared/extra-utils' -import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { Video, VideoChannel } from '../../../../shared/models/videos' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { - addUserSubscription, - areSubscriptionsExist, getUserSubscription, + getVideosList, listUserSubscriptions, listUserSubscriptionVideos, - removeUserSubscription -} from '../../../../shared/extra-utils/users/user-subscriptions' + removeUserSubscription, + ServerInfo, + setAccessTokensToServers, + updateVideo, + uploadVideo, + userLogin, + waitJobs +} from '@shared/extra-utils' +import { Video, VideoChannel } from '@shared/models' const expect = chai.expect @@ -250,7 +247,7 @@ describe('Test users subscriptions', function () { it('Should have server 1 follow server 3 and display server 3 videos', async function () { this.timeout(60000) - await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken) + await servers[0].followsCommand.follow({ targets: [ servers[2].url ] }) await waitJobs(servers) @@ -268,7 +265,7 @@ describe('Test users subscriptions', function () { it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { this.timeout(60000) - await unfollow(servers[0].url, servers[0].accessToken, servers[2]) + await servers[0].followsCommand.unfollow({ target: servers[2] }) await waitJobs(servers) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6bfc7cfe5..92927ea97 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -11,7 +11,6 @@ import { createUser, deleteMe, flushAndRunServer, - follow, getAccountRatings, getBlacklistedVideosList, getCustomConfig, @@ -138,7 +137,12 @@ describe('Test users', function () { it('Should not be able to follow', async function () { accessToken = 'my_super_token' - await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) + + await server.followsCommand.follow({ + targets: [ 'http://example.com' ], + token: accessToken, + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should not be able to unfollow') -- cgit v1.2.3 From ae2abfd3aed3e75d39a316b49b914d187faa7475 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 10:33:49 +0200 Subject: Introduce plugins command --- server/tests/api/users/users.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 92927ea97..ba4183e08 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -23,7 +23,6 @@ import { getUsersListPaginationAndSort, getVideoChannel, getVideosList, - installPlugin, killallServers, login, logout, @@ -75,7 +74,7 @@ describe('Test users', function () { await setAccessTokensToServers([ server ]) - await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) + await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) }) describe('OAuth client', function () { -- cgit v1.2.3 From 65e6e2602c0d5521f3a6740f7469bb92830ecb53 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 11:51:09 +0200 Subject: Introduce config command --- server/tests/api/users/users-verification.ts | 37 ++++++++++++++++------------ server/tests/api/users/users.ts | 9 +++---- 2 files changed, 24 insertions(+), 22 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 265cd6050..23f81d804 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -11,7 +11,6 @@ import { login, registerUser, ServerInfo, - updateCustomSubConfig, updateMyUser, userLogin, verifyEmail @@ -58,11 +57,13 @@ describe('Test users account verification', function () { it('Should register user and send verification email if verification required', async function () { this.timeout(30000) - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: true, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: true, + limit: 10 + } } }) @@ -148,11 +149,13 @@ describe('Test users account verification', function () { it('Should register user not requiring email verification if setting not enabled', async function () { this.timeout(5000) - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: false, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: false, + limit: 10 + } } }) @@ -168,11 +171,13 @@ describe('Test users account verification', function () { }) it('Should allow login for user with unverified email when setting later enabled', async function () { - await updateCustomSubConfig(server.url, server.accessToken, { - signup: { - enabled: true, - requiresEmailVerification: true, - limit: 10 + await server.configCommand.updateCustomSubConfig({ + newConfig: { + signup: { + enabled: true, + requiresEmailVerification: true, + limit: 10 + } } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index ba4183e08..33bcc8701 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -13,7 +13,6 @@ import { flushAndRunServer, getAccountRatings, getBlacklistedVideosList, - getCustomConfig, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, @@ -38,7 +37,6 @@ import { setTokenField, testImage, unblockUser, - updateCustomSubConfig, updateMyAvatar, updateMyUser, updateUser, @@ -46,7 +44,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect @@ -418,12 +416,11 @@ describe('Test users', function () { this.timeout(60000) { - const res = await getCustomConfig(server.url, server.accessToken) - const config = res.body as CustomConfig + const config = await server.configCommand.getCustomConfig() config.transcoding.webtorrent.enabled = false config.transcoding.hls.enabled = true config.transcoding.enabled = true - await updateCustomSubConfig(server.url, server.accessToken, config) + await server.configCommand.updateCustomSubConfig({ newConfig: config }) } { -- cgit v1.2.3 From 9fff08cf83f34339df7ed4ac770e1dee536adf9d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 13:38:26 +0200 Subject: Introduce accounts command --- server/tests/api/users/users-multiple-servers.ts | 37 ++++++++++++------------ server/tests/api/users/users.ts | 20 +++++-------- 2 files changed, 27 insertions(+), 30 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index f60c66e4b..03fbfabeb 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' -import { Account } from '../../../../shared/models/actors' +import * as chai from 'chai' import { + checkActorFilesWereRemoved, checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, @@ -11,17 +11,19 @@ import { doubleFollow, flushAndRunMultipleServers, getAccountVideos, + getMyUserInformation, getVideoChannelsList, removeUser, + ServerInfo, + setAccessTokensToServers, + testImage, + updateMyAvatar, updateMyUser, - userLogin -} from '../../../../shared/extra-utils' -import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' -import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { User } from '../../../../shared/models/users' -import { VideoChannel } from '../../../../shared/models/videos' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' + uploadVideo, + userLogin, + waitJobs +} from '@shared/extra-utils' +import { User, VideoChannel } from '@shared/models' const expect = chai.expect @@ -133,13 +135,12 @@ describe('Test users with multiple servers', function () { let createdAt: string | Date for (const server of servers) { - const resAccounts = await getAccountsList(server.url, '-createdAt') + const body = await server.accountsCommand.list({ sort: '-createdAt' }) - const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account + const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) expect(resList).not.to.be.undefined - const resAccount = await getAccount(server.url, resList.name + '@' + resList.host) - const account = resAccount.body as Account + const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host }) if (!createdAt) createdAt = account.createdAt @@ -193,9 +194,9 @@ describe('Test users with multiple servers', function () { this.timeout(10_000) for (const server of servers) { - const resAccounts = await getAccountsList(server.url, '-createdAt') + const body = await server.accountsCommand.list({ sort: '-createdAt' }) - const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account + const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).not.to.be.undefined const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) @@ -210,9 +211,9 @@ describe('Test users with multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const resAccounts = await getAccountsList(server.url, '-createdAt') + const body = await server.accountsCommand.list({ sort: '-createdAt' }) - const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account + const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).to.be.undefined const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 33bcc8701..3beea5d50 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -11,7 +11,6 @@ import { createUser, deleteMe, flushAndRunServer, - getAccountRatings, getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, @@ -194,25 +193,22 @@ describe('Test users', function () { it('Should retrieve ratings list', async function () { await rateVideo(server.url, accessToken, videoId, 'like') - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) - const ratings = res.body + const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) - expect(ratings.total).to.equal(1) - expect(ratings.data[0].video.id).to.equal(videoId) - expect(ratings.data[0].rating).to.equal('like') + expect(body.total).to.equal(1) + expect(body.data[0].video.id).to.equal(videoId) + expect(body.data[0].rating).to.equal('like') }) it('Should retrieve ratings list by rating type', async function () { { - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') - const ratings = res.body - expect(ratings.data.length).to.equal(1) + const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' }) + expect(body.data.length).to.equal(1) } { - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') - const ratings = res.body - expect(ratings.data.length).to.equal(0) + const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' }) + expect(body.data.length).to.equal(0) } }) }) -- cgit v1.2.3 From 2c27e70471120c92e0bc8c8114141fbb31ff98ac Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 7 Jul 2021 16:40:49 +0200 Subject: Introduce subscriptions command --- server/tests/api/users/user-subscriptions.ts | 144 ++++++++++++--------------- 1 file changed, 61 insertions(+), 83 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 7e365d797..c119622ad 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -3,25 +3,19 @@ import 'mocha' import * as chai from 'chai' import { - addUserSubscription, - areSubscriptionsExist, cleanupTests, createUser, doubleFollow, flushAndRunMultipleServers, - getUserSubscription, getVideosList, - listUserSubscriptions, - listUserSubscriptionVideos, - removeUserSubscription, ServerInfo, setAccessTokensToServers, + SubscriptionsCommand, updateVideo, uploadVideo, userLogin, waitJobs } from '@shared/extra-utils' -import { Video, VideoChannel } from '@shared/models' const expect = chai.expect @@ -30,6 +24,8 @@ describe('Test users subscriptions', function () { const users: { accessToken: string }[] = [] let video3UUID: string + let command: SubscriptionsCommand + before(async function () { this.timeout(120000) @@ -58,6 +54,8 @@ describe('Test users subscriptions', function () { } await waitJobs(servers) + + command = servers[0].subscriptionsCommand }) it('Should display videos of server 2 on server 1', async function () { @@ -69,8 +67,8 @@ describe('Test users subscriptions', function () { it('User of server 1 should follow user of server 3 and root of server 1', async function () { this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) - await addUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) + await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) + await command.add({ token: users[0].accessToken, targetUri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) @@ -93,17 +91,17 @@ describe('Test users subscriptions', function () { it('Should list subscriptions', async function () { { - const res = await listUserSubscriptions({ url: servers[0].url, token: servers[0].accessToken }) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.list() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptions({ url: servers[0].url, token: users[0].accessToken, sort: 'createdAt' }) - expect(res.body.total).to.equal(2) + const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(2) - const subscriptions: VideoChannel[] = res.body.data + const subscriptions = body.data expect(subscriptions).to.be.an('array') expect(subscriptions).to.have.lengthOf(2) @@ -114,8 +112,7 @@ describe('Test users subscriptions', function () { it('Should get subscription', async function () { { - const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) - const videoChannel: VideoChannel = res.body + const videoChannel = await command.get({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) expect(videoChannel.name).to.equal('user3_channel') expect(videoChannel.host).to.equal('localhost:' + servers[2].port) @@ -125,8 +122,7 @@ describe('Test users subscriptions', function () { } { - const res = await getUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) - const videoChannel: VideoChannel = res.body + const videoChannel = await command.get({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) expect(videoChannel.name).to.equal('root_channel') expect(videoChannel.host).to.equal('localhost:' + servers[0].port) @@ -144,8 +140,7 @@ describe('Test users subscriptions', function () { 'user3_channel@localhost:' + servers[0].port ] - const res = await areSubscriptionsExist(servers[0].url, users[0].accessToken, uris) - const body = res.body + const body = await command.exist({ token: users[0].accessToken, uris }) expect(body['user3_channel@localhost:' + servers[2].port]).to.be.true expect(body['root2_channel@localhost:' + servers[0].port]).to.be.false @@ -155,45 +150,31 @@ describe('Test users subscriptions', function () { it('Should search among subscriptions', async function () { { - const res = await listUserSubscriptions({ - url: servers[0].url, - token: users[0].accessToken, - sort: '-createdAt', - search: 'user3_channel' - }) - expect(res.body.total).to.equal(1) - - const subscriptions = res.body.data - expect(subscriptions).to.have.lengthOf(1) + const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'user3_channel' }) + expect(body.total).to.equal(1) + expect(body.data).to.have.lengthOf(1) } { - const res = await listUserSubscriptions({ - url: servers[0].url, - token: users[0].accessToken, - sort: '-createdAt', - search: 'toto' - }) - expect(res.body.total).to.equal(0) - - const subscriptions = res.body.data - expect(subscriptions).to.have.lengthOf(0) + const body = await command.list({ token: users[0].accessToken, sort: '-createdAt', search: 'toto' }) + expect(body.total).to.equal(0) + expect(body.data).to.have.lengthOf(0) } }) it('Should list subscription videos', async function () { { - const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.listVideos() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(3) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(3) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(3) @@ -212,17 +193,17 @@ describe('Test users subscriptions', function () { await waitJobs(servers) { - const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.listVideos() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(4) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(4) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(4) @@ -281,17 +262,17 @@ describe('Test users subscriptions', function () { it('Should still list subscription videos', async function () { { - const res = await listUserSubscriptionVideos(servers[0].url, servers[0].accessToken) - expect(res.body.total).to.equal(0) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(0) + const body = await command.listVideos() + expect(body.total).to.equal(0) + expect(body.data).to.be.an('array') + expect(body.data).to.have.lengthOf(0) } { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(4) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(4) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(4) @@ -309,44 +290,41 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - const videos: Video[] = res.body.data - expect(videos[2].name).to.equal('video server 3 added after follow updated') + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.data[2].name).to.equal('video server 3 added after follow updated') }) it('Should remove user of server 3 subscription', async function () { this.timeout(30000) - await removeUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) + await command.remove({ token: users[0].accessToken, uri: 'user3_channel@localhost:' + servers[2].port }) await waitJobs(servers) }) it('Should not display its videos anymore', async function () { - { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(1) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(1) - const videos: Video[] = res.body.data - expect(videos).to.be.an('array') - expect(videos).to.have.lengthOf(1) + const videos = body.data + expect(videos).to.be.an('array') + expect(videos).to.have.lengthOf(1) - expect(videos[0].name).to.equal('video server 1 added after follow') - } + expect(videos[0].name).to.equal('video server 1 added after follow') }) it('Should remove the root subscription and not display the videos anymore', async function () { this.timeout(30000) - await removeUserSubscription(servers[0].url, users[0].accessToken, 'root_channel@localhost:' + servers[0].port) + await command.remove({ token: users[0].accessToken, uri: 'root_channel@localhost:' + servers[0].port }) await waitJobs(servers) { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(0) + const body = await command.list({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(0) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(0) } @@ -366,15 +344,15 @@ describe('Test users subscriptions', function () { it('Should follow user of server 3 again', async function () { this.timeout(60000) - await addUserSubscription(servers[0].url, users[0].accessToken, 'user3_channel@localhost:' + servers[2].port) + await command.add({ token: users[0].accessToken, targetUri: 'user3_channel@localhost:' + servers[2].port }) await waitJobs(servers) { - const res = await listUserSubscriptionVideos(servers[0].url, users[0].accessToken, 'createdAt') - expect(res.body.total).to.equal(3) + const body = await command.listVideos({ token: users[0].accessToken, sort: 'createdAt' }) + expect(body.total).to.equal(3) - const videos: Video[] = res.body.data + const videos = body.data expect(videos).to.be.an('array') expect(videos).to.have.lengthOf(3) -- cgit v1.2.3 From e3d15a6a9aed97a004d9dac1b7a6499d794e080a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 8 Jul 2021 11:17:55 +0200 Subject: Introduce blacklist command --- server/tests/api/users/users.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 3beea5d50..4b9056306 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -11,7 +11,6 @@ import { createUser, deleteMe, flushAndRunServer, - getBlacklistedVideosList, getMyUserInformation, getMyUserVideoQuotaUsed, getMyUserVideoRating, @@ -808,7 +807,7 @@ describe('Test users', function () { describe('Video blacklists', function () { it('Should be able to list video blacklist by a moderator', async function () { - await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) + await server.blacklistCommand.list({ token: accessTokenUser }) }) }) -- cgit v1.2.3 From a54618880c394ad7571f3f3222dc96ec2dd10d9a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 11:21:30 +0200 Subject: Introduce channels command --- server/tests/api/users/users-multiple-servers.ts | 15 +++++---------- server/tests/api/users/users.ts | 5 ++--- 2 files changed, 7 insertions(+), 13 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 03fbfabeb..47056be78 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -12,7 +12,6 @@ import { flushAndRunMultipleServers, getAccountVideos, getMyUserInformation, - getVideoChannelsList, removeUser, ServerInfo, setAccessTokensToServers, @@ -23,7 +22,7 @@ import { userLogin, waitJobs } from '@shared/extra-utils' -import { User, VideoChannel } from '@shared/models' +import { User } from '@shared/models' const expect = chai.expect @@ -199,10 +198,8 @@ describe('Test users with multiple servers', function () { const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).not.to.be.undefined - const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) - const videoChannelDeleted = resVideoChannels.body.data.find(a => { - return a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port - }) as VideoChannel + const { data } = await server.channelsCommand.list() + const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).not.to.be.undefined } @@ -216,10 +213,8 @@ describe('Test users with multiple servers', function () { const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).to.be.undefined - const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) - const videoChannelDeleted = resVideoChannels.body.data.find(a => { - return a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port - }) as VideoChannel + const { data } = await server.channelsCommand.list() + const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).to.be.undefined } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 4b9056306..ed670b3c9 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -18,7 +18,6 @@ import { getUserInformation, getUsersList, getUsersListPaginationAndSort, - getVideoChannel, getVideosList, killallServers, login, @@ -864,9 +863,9 @@ describe('Test users', function () { }) it('Should have created the channel', async function () { - const res = await getVideoChannel(server.url, 'my_user_15_channel') + const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' }) - expect(res.body.displayName).to.equal('my channel rocks') + expect(displayName).to.equal('my channel rocks') }) it('Should remove me', async function () { -- cgit v1.2.3 From 12edc1495a36b2199f1bf1ba37f50c7b694be382 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 14:15:11 +0200 Subject: Introduce comments command --- server/tests/api/users/users.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index ed670b3c9..4d255f340 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - addVideoCommentThread, blockUser, cleanupTests, closeAllSequelize, @@ -983,7 +982,7 @@ describe('Test users', function () { it('Should report correct video comments for user', async function () { const text = 'super comment' - await addVideoCommentThread(server.url, user17AccessToken, videoId, text) + await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) const res = await getUserInformation(server.url, server.accessToken, user17Id, true) const user: User = res.body -- cgit v1.2.3 From 9293139fde7091e9badcafa9b570b83cea9a10ad Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 9 Jul 2021 15:37:43 +0200 Subject: Introduce sql command --- server/tests/api/users/users.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 4d255f340..69a8dba34 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -6,7 +6,6 @@ import { HttpStatusCode } from '@shared/core-utils' import { blockUser, cleanupTests, - closeAllSequelize, createUser, deleteMe, flushAndRunServer, @@ -30,7 +29,6 @@ import { reRunServer, ServerInfo, setAccessTokensToServers, - setTokenField, testImage, unblockUser, updateMyAvatar, @@ -264,10 +262,10 @@ describe('Test users', function () { it('Should have an expired access token', async function () { this.timeout(15000) - await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) - await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) + await server.sqlCommand.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) + await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) await getMyUserInformation(server.url, server.accessToken, 401) @@ -281,9 +279,9 @@ describe('Test users', function () { this.timeout(15000) const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() - await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate) + await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) - killallServers([ server ]) + await killallServers([ server ]) await reRunServer(server) const res = await refreshToken(server, server.refreshToken) @@ -1013,7 +1011,6 @@ describe('Test users', function () { }) after(async function () { - await closeAllSequelize([ server ]) await cleanupTests([ server ]) }) }) -- cgit v1.2.3 From 6c5065a011b099618681a37bd77eaa7bd3db752e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 09:43:59 +0200 Subject: Introduce server commands --- server/tests/api/users/users-multiple-servers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 47056be78..7b650cb8f 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -227,7 +227,7 @@ describe('Test users with multiple servers', function () { it('Should not have video files', async () => { for (const server of servers) { - await checkVideoFilesWereRemoved(videoUUID, server.internalServerNumber) + await checkVideoFilesWereRemoved(videoUUID, server) } }) -- cgit v1.2.3 From 41d1d075011174e73dccb74006181a92a618d7b4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 11:05:15 +0200 Subject: Introduce login command --- server/tests/api/users/user-subscriptions.ts | 3 +- server/tests/api/users/users-multiple-servers.ts | 3 +- server/tests/api/users/users-verification.ts | 28 ++++---- server/tests/api/users/users.ts | 91 ++++++++++++------------ 4 files changed, 59 insertions(+), 66 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index c119622ad..1d0fc35f1 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -13,7 +13,6 @@ import { SubscriptionsCommand, updateVideo, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' @@ -42,7 +41,7 @@ describe('Test users subscriptions', function () { const user = { username: 'user' + server.serverNumber, password: 'password' } await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) - const accessToken = await userLogin(server, user) + const accessToken = await server.loginCommand.getAccessToken(user) users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 7b650cb8f..99fa08fe2 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -19,7 +19,6 @@ import { updateMyAvatar, updateMyUser, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { User } from '@shared/models' @@ -64,7 +63,7 @@ describe('Test users with multiple servers', function () { password: user.password }) userId = res.body.user.id - userAccessToken = await userLogin(servers[0], user) + userAccessToken = await servers[0].loginCommand.getAccessToken(user) } { diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 23f81d804..ade730323 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -2,23 +2,21 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, getMyUserInformation, getUserInformation, - login, + MockSmtpServer, registerUser, ServerInfo, + setAccessTokensToServers, updateMyUser, - userLogin, - verifyEmail -} from '../../../../shared/extra-utils' -import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' -import { waitJobs } from '../../../../shared/extra-utils/server/jobs' -import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' -import { User } from '../../../../shared/models/users' + verifyEmail, + waitJobs +} from '@shared/extra-utils' +import { User } from '@shared/models' const expect = chai.expect @@ -91,15 +89,15 @@ describe('Test users account verification', function () { }) it('Should not allow login for user with unverified email', async function () { - const resLogin = await login(server.url, server.client, user1, HttpStatusCode.BAD_REQUEST_400) - expect(resLogin.body.detail).to.contain('User email is not verified.') + const { detail } = await server.loginCommand.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + expect(detail).to.contain('User email is not verified.') }) it('Should verify the user via email and allow login', async function () { await verifyEmail(server.url, userId, verificationString) - const res = await login(server.url, server.client, user1) - userAccessToken = res.body.access_token + const body = await server.loginCommand.login({ user: user1 }) + userAccessToken = body.access_token const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) expect(resUserVerified.body.emailVerified).to.be.true @@ -164,7 +162,7 @@ describe('Test users account verification', function () { await waitJobs(server) expect(emails).to.have.lengthOf(expectedEmailsLength) - const accessToken = await userLogin(server, user2) + const accessToken = await server.loginCommand.getAccessToken(user2) const resMyUserInfo = await getMyUserInformation(server.url, accessToken) expect(resMyUserInfo.body.emailVerified).to.be.null @@ -181,7 +179,7 @@ describe('Test users account verification', function () { } }) - await userLogin(server, user2) + await server.loginCommand.getAccessToken(user2) }) after(async function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 69a8dba34..608bedb8b 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -18,11 +18,8 @@ import { getUsersListPaginationAndSort, getVideosList, killallServers, - login, - logout, makePutBodyRequest, rateVideo, - refreshToken, registerUserWithChannel, removeUser, removeVideo, @@ -35,7 +32,6 @@ import { updateMyUser, updateUser, uploadVideo, - userLogin, waitJobs } from '@shared/extra-utils' import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' @@ -78,22 +74,22 @@ describe('Test users', function () { it('Should not login with an invalid client id', async function () { const client = { id: 'client', secret: server.client.secret } - const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) - expect(res.body.error).to.contain('client is invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.error).to.contain('client is invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) }) it('Should not login with an invalid client secret', async function () { const client = { id: server.client.id, secret: 'coucou' } - const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) - expect(res.body.error).to.contain('client is invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) + expect(body.error).to.contain('client is invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT) }) }) @@ -101,22 +97,22 @@ describe('Test users', function () { it('Should not login with an invalid username', async function () { const user = { username: 'captain crochet', password: server.user.password } - const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) - expect(res.body.error).to.contain('credentials are invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) + expect(body.error).to.contain('credentials are invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) }) it('Should not login with an invalid password', async function () { const user = { username: server.user.username, password: 'mew_three' } - const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) + const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) - expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) - expect(res.body.error).to.contain('credentials are invalid') - expect(res.body.type.startsWith('https://')).to.be.true - expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) + expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) + expect(body.error).to.contain('credentials are invalid') + expect(body.type.startsWith('https://')).to.be.true + expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT) }) it('Should not be able to upload a video', async function () { @@ -139,20 +135,20 @@ describe('Test users', function () { it('Should not be able to unfollow') it('Should be able to login', async function () { - const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) + const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) - accessToken = res.body.access_token + accessToken = body.access_token }) it('Should be able to login with an insensitive username', async function () { const user = { username: 'RoOt', password: server.user.password } - await login(server.url, server.client, user, HttpStatusCode.OK_200) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 }) const user2 = { username: 'rOoT', password: server.user.password } - await login(server.url, server.client, user2, HttpStatusCode.OK_200) + await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) const user3 = { username: 'ROOt', password: server.user.password } - await login(server.url, server.client, user3, HttpStatusCode.OK_200) + await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -222,7 +218,7 @@ describe('Test users', function () { describe('Logout', function () { it('Should logout (revoke token)', async function () { - await logout(server.url, server.accessToken) + await server.loginCommand.logout({ token: server.accessToken }) }) it('Should not be able to get the user information', async function () { @@ -250,9 +246,9 @@ describe('Test users', function () { }) it('Should be able to login again', async function () { - const res = await login(server.url, server.client, server.user) - server.accessToken = res.body.access_token - server.refreshToken = res.body.refresh_token + const body = await server.loginCommand.login() + server.accessToken = body.access_token + server.refreshToken = body.refresh_token }) it('Should be able to get my user information again', async function () { @@ -268,11 +264,11 @@ describe('Test users', function () { await killallServers([ server ]) await reRunServer(server) - await getMyUserInformation(server.url, server.accessToken, 401) + await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) }) it('Should not be able to refresh an access token with an expired refresh token', async function () { - await refreshToken(server, server.refreshToken, 400) + await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should refresh the token', async function () { @@ -284,7 +280,7 @@ describe('Test users', function () { await killallServers([ server ]) await reRunServer(server) - const res = await refreshToken(server, server.refreshToken) + const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken }) server.accessToken = res.body.access_token server.refreshToken = res.body.refresh_token }) @@ -308,7 +304,7 @@ describe('Test users', function () { }) it('Should be able to login with this user', async function () { - accessTokenUser = await userLogin(server, user) + accessTokenUser = await server.loginCommand.getAccessToken(user) }) it('Should be able to get user information', async function () { @@ -562,6 +558,7 @@ describe('Test users', function () { }) describe('Update my account', function () { + it('Should update my password', async function () { await updateMyUser({ url: server.url, @@ -571,7 +568,7 @@ describe('Test users', function () { }) user.password = 'new password' - await userLogin(server, user, HttpStatusCode.OK_200) + await server.loginCommand.login({ user }) }) it('Should be able to change the NSFW display attribute', async function () { @@ -781,7 +778,7 @@ describe('Test users', function () { it('Should have removed the user token', async function () { await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) - accessTokenUser = await userLogin(server, user) + accessTokenUser = await server.loginCommand.getAccessToken(user) }) it('Should be able to update another user password', async function () { @@ -794,10 +791,10 @@ describe('Test users', function () { await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) - await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) user.password = 'password updated' - accessTokenUser = await userLogin(server, user) + accessTokenUser = await server.loginCommand.getAccessToken(user) }) }) @@ -813,7 +810,7 @@ describe('Test users', function () { }) it('Should not be able to login with this user', async function () { - await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not have videos of this user', async function () { @@ -842,7 +839,7 @@ describe('Test users', function () { password: 'my super password' } - user15AccessToken = await userLogin(server, user15) + user15AccessToken = await server.loginCommand.getAccessToken(user15) }) it('Should have the correct display name', async function () { @@ -897,13 +894,13 @@ describe('Test users', function () { }) user16Id = resUser.body.user.id - user16AccessToken = await userLogin(server, user16) + user16AccessToken = await server.loginCommand.getAccessToken(user16) await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) await blockUser(server.url, user16Id, server.accessToken) await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) - await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) + await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should search user by banned status', async function () { @@ -930,7 +927,7 @@ describe('Test users', function () { it('Should unblock a user', async function () { await unblockUser(server.url, user16Id, server.accessToken) - user16AccessToken = await userLogin(server, user16) + user16AccessToken = await server.loginCommand.getAccessToken(user16) await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) }) }) @@ -952,7 +949,7 @@ describe('Test users', function () { }) user17Id = resUser.body.user.id - user17AccessToken = await userLogin(server, user17) + user17AccessToken = await server.loginCommand.getAccessToken(user17) const res = await getUserInformation(server.url, server.accessToken, user17Id, true) const user: User = res.body -- cgit v1.2.3 From 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 13 Jul 2021 14:23:01 +0200 Subject: Introduce user command --- server/tests/api/users/user-subscriptions.ts | 3 +- server/tests/api/users/users-multiple-servers.ts | 45 +-- server/tests/api/users/users-verification.ts | 48 +-- server/tests/api/users/users.ts | 374 +++++++---------------- 4 files changed, 143 insertions(+), 327 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 1d0fc35f1..c09a85a32 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -4,7 +4,6 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getVideosList, @@ -39,7 +38,7 @@ describe('Test users subscriptions', function () { { for (const server of servers) { const user = { username: 'user' + server.serverNumber, password: 'password' } - await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) + await server.usersCommand.create({ username: user.username, password: user.password }) const accessToken = await server.loginCommand.getAccessToken(user) users.push({ accessToken }) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 99fa08fe2..43e67ee60 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -7,17 +7,12 @@ import { checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, - createUser, doubleFollow, flushAndRunMultipleServers, getAccountVideos, - getMyUserInformation, - removeUser, ServerInfo, setAccessTokensToServers, testImage, - updateMyAvatar, - updateMyUser, uploadVideo, waitJobs } from '@shared/extra-utils' @@ -56,13 +51,8 @@ describe('Test users with multiple servers', function () { username: 'user1', password: 'password' } - const res = await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: user.username, - password: user.password - }) - userId = res.body.user.id + const created = await servers[0].usersCommand.create(user) + userId = created.id userAccessToken = await servers[0].loginCommand.getAccessToken(user) } @@ -77,15 +67,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my display name', async function () { this.timeout(10000) - await updateMyUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - displayName: 'my super display name' - }) - - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - user = res.body + await servers[0].usersCommand.updateMe({ displayName: 'my super display name' }) + user = await servers[0].usersCommand.getMyInfo() expect(user.account.displayName).to.equal('my super display name') await waitJobs(servers) @@ -94,14 +78,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my description', async function () { this.timeout(10_000) - await updateMyUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - description: 'my super description updated' - }) + await servers[0].usersCommand.updateMe({ description: 'my super description updated' }) - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - user = res.body + user = await servers[0].usersCommand.getMyInfo() expect(user.account.displayName).to.equal('my super display name') expect(user.account.description).to.equal('my super description updated') @@ -113,15 +92,9 @@ describe('Test users with multiple servers', function () { const fixture = 'avatar2.png' - await updateMyAvatar({ - url: servers[0].url, - accessToken: servers[0].accessToken, - fixture - }) - - const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) - user = res.body + await servers[0].usersCommand.updateMyAvatar({ fixture }) + user = await servers[0].usersCommand.getMyInfo() userAvatarFilename = user.account.avatar.path await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') @@ -202,7 +175,7 @@ describe('Test users with multiple servers', function () { expect(videoChannelDeleted).not.to.be.undefined } - await removeUser(servers[0].url, userId, servers[0].accessToken) + await servers[0].usersCommand.remove({ userId }) await waitJobs(servers) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index ade730323..271aa3c7a 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -3,20 +3,7 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { - cleanupTests, - flushAndRunServer, - getMyUserInformation, - getUserInformation, - MockSmtpServer, - registerUser, - ServerInfo, - setAccessTokensToServers, - updateMyUser, - verifyEmail, - waitJobs -} from '@shared/extra-utils' -import { User } from '@shared/models' +import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect @@ -65,7 +52,7 @@ describe('Test users account verification', function () { } }) - await registerUser(server.url, user1.username, user1.password) + await server.usersCommand.register(user1) await waitJobs(server) expectedEmailsLength++ @@ -84,8 +71,8 @@ describe('Test users account verification', function () { userId = parseInt(userIdMatches[1], 10) - const resUserInfo = await getUserInformation(server.url, server.accessToken, userId) - expect(resUserInfo.body.emailVerified).to.be.false + const body = await server.usersCommand.get({ userId }) + expect(body.emailVerified).to.be.false }) it('Should not allow login for user with unverified email', async function () { @@ -94,13 +81,13 @@ describe('Test users account verification', function () { }) it('Should verify the user via email and allow login', async function () { - await verifyEmail(server.url, userId, verificationString) + await server.usersCommand.verifyEmail({ userId, verificationString }) const body = await server.loginCommand.login({ user: user1 }) userAccessToken = body.access_token - const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) - expect(resUserVerified.body.emailVerified).to.be.true + const user = await server.usersCommand.get({ userId }) + expect(user.emailVerified).to.be.true }) it('Should be able to change the user email', async function () { @@ -109,9 +96,8 @@ describe('Test users account verification', function () { let updateVerificationString: string { - await updateMyUser({ - url: server.url, - accessToken: userAccessToken, + await server.usersCommand.updateMe({ + token: userAccessToken, email: 'updated@example.com', currentPassword: user1.password }) @@ -127,19 +113,15 @@ describe('Test users account verification', function () { } { - const res = await getMyUserInformation(server.url, userAccessToken) - const me: User = res.body - + const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('user_1@example.com') expect(me.pendingEmail).to.equal('updated@example.com') } { - await verifyEmail(server.url, userId, updateVerificationString, true) - - const res = await getMyUserInformation(server.url, userAccessToken) - const me: User = res.body + await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) + const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('updated@example.com') expect(me.pendingEmail).to.be.null } @@ -157,15 +139,15 @@ describe('Test users account verification', function () { } }) - await registerUser(server.url, user2.username, user2.password) + await server.usersCommand.register(user2) await waitJobs(server) expect(emails).to.have.lengthOf(expectedEmailsLength) const accessToken = await server.loginCommand.getAccessToken(user2) - const resMyUserInfo = await getMyUserInformation(server.url, accessToken) - expect(resMyUserInfo.body.emailVerified).to.be.null + const user = await server.usersCommand.getMyInfo({ token: accessToken }) + expect(user.emailVerified).to.be.null }) it('Should allow login for user with unverified email when setting later enabled', async function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 608bedb8b..30d7e850d 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -4,37 +4,22 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { - blockUser, cleanupTests, - createUser, - deleteMe, flushAndRunServer, - getMyUserInformation, - getMyUserVideoQuotaUsed, - getMyUserVideoRating, getMyVideos, - getUserInformation, - getUsersList, - getUsersListPaginationAndSort, getVideosList, killallServers, makePutBodyRequest, rateVideo, - registerUserWithChannel, - removeUser, removeVideo, reRunServer, ServerInfo, setAccessTokensToServers, testImage, - unblockUser, - updateMyAvatar, - updateMyUser, - updateUser, uploadVideo, waitJobs } from '@shared/extra-utils' -import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect @@ -174,8 +159,7 @@ describe('Test users', function () { it('Should retrieve a video rating', async function () { await rateVideo(server.url, accessToken, videoId, 'like') - const res = await getMyUserVideoRating(server.url, accessToken, videoId) - const rating = res.body + const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) expect(rating.videoId).to.equal(videoId) expect(rating.rating).to.equal('like') @@ -222,7 +206,7 @@ describe('Test users', function () { }) it('Should not be able to get the user information', async function () { - await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to upload a video', async function () { @@ -252,7 +236,7 @@ describe('Test users', function () { }) it('Should be able to get my user information again', async function () { - await getMyUserInformation(server.url, server.accessToken) + await server.usersCommand.getMyInfo() }) it('Should have an expired access token', async function () { @@ -264,7 +248,7 @@ describe('Test users', function () { await killallServers([ server ]) await reRunServer(server) - await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to refresh an access token with an expired refresh token', async function () { @@ -286,21 +270,14 @@ describe('Test users', function () { }) it('Should be able to get my user information again', async function () { - await getMyUserInformation(server.url, server.accessToken) + await server.usersCommand.getMyInfo() }) }) describe('Creating a user', function () { it('Should be able to create a new user', async function () { - await createUser({ - url: server.url, - accessToken: accessToken, - username: user.username, - password: user.password, - videoQuota: 2 * 1024 * 1024, - adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST - }) + await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) }) it('Should be able to login with this user', async function () { @@ -308,11 +285,9 @@ describe('Test users', function () { }) it('Should be able to get user information', async function () { - const res1 = await getMyUserInformation(server.url, accessTokenUser) - const userMe: MyUser = res1.body + const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) - const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) - const userGet: User = res2.body + const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) for (const user of [ userMe, userGet ]) { expect(user.username).to.equal('user_1') @@ -356,15 +331,11 @@ describe('Test users', function () { }) it('Should have video quota updated', async function () { - const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) - const data = res.body - - expect(data.videoQuotaUsed).to.equal(218910) - - const resUsers = await getUsersList(server.url, server.accessToken) + const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + expect(quota.videoQuotaUsed).to.equal(218910) - const users: User[] = resUsers.body.data - const tmpUser = users.find(u => u.username === user.username) + const { data } = await server.usersCommand.list() + const tmpUser = data.find(u => u.username === user.username) expect(tmpUser.videoQuotaUsed).to.equal(218910) }) @@ -421,9 +392,7 @@ describe('Test users', function () { } { - const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) - const data = res.body - + const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) expect(data.videoQuotaUsed).to.be.greaterThan(220000) } }) @@ -432,21 +401,18 @@ describe('Test users', function () { describe('Users listing', function () { it('Should list all the users', async function () { - const res = await getUsersList(server.url, server.accessToken) - const result = res.body - const total = result.total - const users = result.data + const { data, total } = await server.usersCommand.list() expect(total).to.equal(2) - expect(users).to.be.an('array') - expect(users.length).to.equal(2) + expect(data).to.be.an('array') + expect(data.length).to.equal(2) - const user = users[0] + const user = data[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('display') - const rootUser = users[1] + const rootUser = data[1] expect(rootUser.username).to.equal('root') expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.nsfwPolicy).to.equal('display') @@ -458,16 +424,12 @@ describe('Test users', function () { }) it('Should list only the first user by username asc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') - - const result = res.body - const total = result.total - const users = result.data + const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' }) expect(total).to.equal(2) - expect(users.length).to.equal(1) + expect(data.length).to.equal(1) - const user = users[0] + const user = data[0] expect(user.username).to.equal('root') expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') expect(user.roleLabel).to.equal('Administrator') @@ -475,84 +437,66 @@ describe('Test users', function () { }) it('Should list only the first user by username desc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') - const result = res.body - const total = result.total - const users = result.data + const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' }) expect(total).to.equal(2) - expect(users.length).to.equal(1) + expect(data.length).to.equal(1) - const user = users[0] + const user = data[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('display') }) it('Should list only the second user by createdAt desc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') - const result = res.body - const total = result.total - const users = result.data - + const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' }) expect(total).to.equal(2) - expect(users.length).to.equal(1) - const user = users[0] + expect(data.length).to.equal(1) + + const user = data[0] expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('display') }) it('Should list all the users by createdAt asc', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') - const result = res.body - const total = result.total - const users = result.data + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' }) expect(total).to.equal(2) - expect(users.length).to.equal(2) + expect(data.length).to.equal(2) - expect(users[0].username).to.equal('root') - expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') - expect(users[0].nsfwPolicy).to.equal('display') + expect(data[0].username).to.equal('root') + expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') + expect(data[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].nsfwPolicy).to.equal('display') + expect(data[1].username).to.equal('user_1') + expect(data[1].email).to.equal('user_1@example.com') + expect(data[1].nsfwPolicy).to.equal('display') }) it('Should search user by username', async function () { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') - 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('root') + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) + expect(data[0].username).to.equal('root') }) it('Should search user by email', async function () { { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') - 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('user_1') - expect(users[0].email).to.equal('user_1@example.com') + const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) + expect(data[0].username).to.equal('user_1') + expect(data[0].email).to.equal('user_1@example.com') } { - const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') - const users = res.body.data as User[] - - expect(res.body.total).to.equal(2) - expect(users.length).to.equal(2) - - expect(users[0].username).to.equal('root') - expect(users[1].username).to.equal('user_1') + const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) + expect(total).to.equal(2) + expect(data.length).to.equal(2) + expect(data[0].username).to.equal('root') + expect(data[1].username).to.equal('user_1') } }) }) @@ -560,9 +504,8 @@ describe('Test users', function () { describe('Update my account', function () { it('Should update my password', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, currentPassword: 'super password', password: 'new password' }) @@ -572,15 +515,12 @@ describe('Test users', function () { }) it('Should be able to change the NSFW display attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, nsfwPolicy: 'do_not_list' }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -591,42 +531,33 @@ describe('Test users', function () { }) it('Should be able to change the autoPlayVideo attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, autoPlayVideo: false }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.autoPlayVideo).to.be.false }) it('Should be able to change the autoPlayNextVideo attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, autoPlayNextVideo: true }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.autoPlayNextVideo).to.be.true }) it('Should be able to change the email attribute', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, currentPassword: 'new password', email: 'updated@example.com' }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -639,15 +570,9 @@ describe('Test users', function () { it('Should be able to update my avatar with a gif', async function () { const fixture = 'avatar.gif' - await updateMyAvatar({ - url: server.url, - accessToken: accessTokenUser, - fixture - }) - - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body + await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') }) @@ -655,29 +580,17 @@ describe('Test users', function () { for (const extension of [ '.png', '.gif' ]) { const fixture = 'avatar' + extension - await updateMyAvatar({ - url: server.url, - accessToken: accessTokenUser, - fixture - }) - - const res = await getMyUserInformation(server.url, accessTokenUser) - const user = res.body + await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) } }) 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 + await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -688,15 +601,9 @@ describe('Test users', function () { }) 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: User = res.body + await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -710,30 +617,21 @@ describe('Test users', function () { it('Should be able to update my theme', async function () { for (const theme of [ 'background-red', 'default', 'instance-default' ]) { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, - theme - }) + await server.usersCommand.updateMe({ token: accessTokenUser, theme }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const body: User = res.body - - expect(body.theme).to.equal(theme) + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + expect(user.theme).to.equal(theme) } }) it('Should be able to update my modal preferences', async function () { - await updateMyUser({ - url: server.url, - accessToken: accessTokenUser, + await server.usersCommand.updateMe({ + token: accessTokenUser, noInstanceConfigWarningModal: true, noWelcomeModal: true }) - const res = await getMyUserInformation(server.url, accessTokenUser) - const user: User = res.body - + const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true }) @@ -741,10 +639,9 @@ describe('Test users', function () { describe('Updating another user', function () { it('Should be able to update another user', async function () { - await updateUser({ - url: server.url, + await server.usersCommand.update({ userId, - accessToken, + token: accessToken, email: 'updated2@example.com', emailVerified: true, videoQuota: 42, @@ -753,8 +650,7 @@ describe('Test users', function () { pluginAuth: 'toto' }) - const res = await getUserInformation(server.url, accessToken, userId) - const user = res.body as User + const user = await server.usersCommand.get({ token: accessToken, userId }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated2@example.com') @@ -768,28 +664,22 @@ describe('Test users', function () { }) it('Should reset the auth plugin', async function () { - await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) + await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) - const res = await getUserInformation(server.url, accessToken, userId) - const user = res.body as User + const user = await server.usersCommand.get({ token: accessToken, userId }) expect(user.pluginAuth).to.be.null }) it('Should have removed the user token', async function () { - await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) accessTokenUser = await server.loginCommand.getAccessToken(user) }) it('Should be able to update another user password', async function () { - await updateUser({ - url: server.url, - userId, - accessToken, - password: 'password updated' - }) + await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) - await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) @@ -806,7 +696,7 @@ describe('Test users', function () { describe('Remove a user', function () { it('Should be able to remove this user', async function () { - await removeUser(server.url, userId, accessToken) + await server.usersCommand.remove({ userId, token: accessToken }) }) it('Should not be able to login with this user', async function () { @@ -830,7 +720,7 @@ describe('Test users', function () { const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } - await registerUserWithChannel({ url: server.url, user, channel }) + await server.usersCommand.register({ ...user, channel }) }) it('Should be able to login with this registered user', async function () { @@ -843,16 +733,12 @@ describe('Test users', function () { }) it('Should have the correct display name', async function () { - const res = await getMyUserInformation(server.url, user15AccessToken) - const user: User = res.body - + const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) expect(user.account.displayName).to.equal('super user 15') }) it('Should have the correct video quota', async function () { - const res = await getMyUserInformation(server.url, user15AccessToken) - const user = res.body - + const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) expect(user.videoQuota).to.equal(5 * 1024 * 1024) }) @@ -864,15 +750,15 @@ describe('Test users', function () { 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 + const { data } = await server.usersCommand.list() + expect(data.find(u => u.username === 'user_15')).to.not.be.undefined } - await deleteMe(server.url, user15AccessToken) + await server.usersCommand.deleteMe({ token: user15AccessToken }) { - const res = await getUsersList(server.url, server.accessToken) - expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined + const { data } = await server.usersCommand.list() + expect(data.find(u => u.username === 'user_15')).to.be.undefined } }) }) @@ -886,49 +772,40 @@ describe('Test users', function () { } it('Should block a user', async function () { - const resUser = await createUser({ - url: server.url, - accessToken: server.accessToken, - username: user16.username, - password: user16.password - }) - user16Id = resUser.body.user.id + const user = await server.usersCommand.create({ ...user16 }) + user16Id = user.id user16AccessToken = await server.loginCommand.getAccessToken(user16) - await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) - await blockUser(server.url, user16Id, server.accessToken) + await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) + await server.usersCommand.banUser({ userId: user16Id }) - await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) + await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_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[] + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) - expect(res.body.total).to.equal(1) - expect(users.length).to.equal(1) - - expect(users[0].username).to.equal(user16.username) + expect(data[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) + const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) + expect(total).to.equal(1) + expect(data.length).to.equal(1) - expect(users[0].username).to.not.equal(user16.username) + expect(data[0].username).to.not.equal(user16.username) } }) it('Should unblock a user', async function () { - await unblockUser(server.url, user16Id, server.accessToken) + await server.usersCommand.unbanUser({ userId: user16Id }) user16AccessToken = await server.loginCommand.getAccessToken(user16) - await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) + await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -941,19 +818,12 @@ describe('Test users', function () { username: 'user_17', password: 'my super password' } - const resUser = await createUser({ - url: server.url, - accessToken: server.accessToken, - username: user17.username, - password: user17.password - }) + const created = await server.usersCommand.create({ ...user17 }) - user17Id = resUser.body.user.id + user17Id = created.id user17AccessToken = await server.loginCommand.getAccessToken(user17) - const res = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user: User = res.body - + const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(0) expect(user.videoCommentsCount).to.equal(0) expect(user.abusesCount).to.equal(0) @@ -969,9 +839,7 @@ describe('Test users', function () { const res1 = await getVideosList(server.url) videoId = res1.body.data.find(video => video.name === videoAttributes.name).id - const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user: User = res2.body - + const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(1) }) @@ -979,9 +847,7 @@ describe('Test users', function () { const text = 'super comment' await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) - const res = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user: User = res.body - + const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videoCommentsCount).to.equal(1) }) @@ -992,17 +858,13 @@ describe('Test users', function () { const body1 = await server.abusesCommand.getAdminList() const abuseId = body1.data[0].id - const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user2: User = res2.body - + const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user2.abusesCount).to.equal(1) // number of incriminations expect(user2.abusesCreatedCount).to.equal(1) // number of reports created await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) - const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) - const user3: User = res3.body - + const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted }) }) -- cgit v1.2.3 From d23dd9fbfc4d26026352c10f81d2795ceaf2908a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Jul 2021 10:02:54 +0200 Subject: Introduce videos command --- server/tests/api/users/user-subscriptions.ts | 56 ++++---- server/tests/api/users/users-multiple-servers.ts | 34 ++--- server/tests/api/users/users.ts | 166 ++++++++++------------- 3 files changed, 116 insertions(+), 140 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index c09a85a32..622cddb7d 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -6,12 +6,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getVideosList, ServerInfo, setAccessTokensToServers, SubscriptionsCommand, - updateVideo, - uploadVideo, waitJobs } from '@shared/extra-utils' @@ -44,10 +41,10 @@ describe('Test users subscriptions', function () { users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber - await uploadVideo(server.url, accessToken, { name: videoName1 }) + await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } }) const videoName2 = 'video 2-' + server.serverNumber - await uploadVideo(server.url, accessToken, { name: videoName2 }) + await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } }) } } @@ -57,9 +54,9 @@ describe('Test users subscriptions', function () { }) it('Should display videos of server 2 on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total } = await servers[0].videosCommand.list() - expect(res.body.total).to.equal(4) + expect(total).to.equal(4) }) it('User of server 1 should follow user of server 3 and root of server 1', async function () { @@ -70,17 +67,17 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await uploadVideo(servers[2].url, users[2].accessToken, { name: 'video server 3 added after follow' }) - video3UUID = res.body.video.uuid + const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } }) + video3UUID = uuid await waitJobs(servers) }) it('Should not display videos of server 3 on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(4) - expect(res.body.total).to.equal(4) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -186,7 +183,7 @@ describe('Test users subscriptions', function () { this.timeout(60000) const videoName = 'video server 1 added after follow' - await uploadVideo(servers[0].url, servers[0].accessToken, { name: videoName }) + await servers[0].videosCommand.upload({ attributes: { name: videoName } }) await waitJobs(servers) @@ -212,10 +209,10 @@ describe('Test users subscriptions', function () { } { - const res = await getVideosList(servers[0].url) + const { data, total } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -230,13 +227,12 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) - - expect(res.body.total).to.equal(8) + const { data, total } = await servers[0].videosCommand.list() + expect(total).to.equal(8) const names = [ '1-3', '2-3', 'video server 3 added after follow' ] for (const name of names) { - const video = res.body.data.find(v => v.name.indexOf(name) === -1) + const video = data.find(v => v.name.includes(name)) expect(video).to.not.be.undefined } }) @@ -248,10 +244,10 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow') @@ -284,7 +280,7 @@ describe('Test users subscriptions', function () { it('Should update a video of server 3 and see the updated video on server 1', async function () { this.timeout(30000) - await updateVideo(servers[2].url, users[2].accessToken, video3UUID, { name: 'video server 3 added after follow updated' }) + await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) await waitJobs(servers) @@ -329,10 +325,10 @@ describe('Test users subscriptions', function () { }) it('Should correctly display public videos on server 1', async function () { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow updated') @@ -360,10 +356,10 @@ describe('Test users subscriptions', function () { } { - const res = await getVideosList(servers[0].url) + const { total, data } = await servers[0].videosCommand.list() + expect(total).to.equal(5) - expect(res.body.total).to.equal(5) - for (const video of res.body.data) { + for (const video of data) { expect(video.name).to.not.contain('1-3') expect(video.name).to.not.contain('2-3') expect(video.name).to.not.contain('video server 3 added after follow updated') diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 43e67ee60..3ae105008 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -9,11 +9,9 @@ import { cleanupTests, doubleFollow, flushAndRunMultipleServers, - getAccountVideos, ServerInfo, setAccessTokensToServers, testImage, - uploadVideo, waitJobs } from '@shared/extra-utils' import { User } from '@shared/models' @@ -44,7 +42,7 @@ describe('Test users with multiple servers', function () { await doubleFollow(servers[1], servers[2]) // The root user of server 1 is propagated to servers 2 and 3 - await uploadVideo(servers[0].url, servers[0].accessToken, {}) + await servers[0].videosCommand.upload() { const user = { @@ -57,8 +55,8 @@ describe('Test users with multiple servers', function () { } { - const resVideo = await uploadVideo(servers[0].url, userAccessToken, {}) - videoUUID = resVideo.body.video.uuid + const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken }) + videoUUID = uuid } await waitJobs(servers) @@ -133,31 +131,29 @@ describe('Test users with multiple servers', function () { it('Should list account videos', async function () { for (const server of servers) { - const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5) + const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].uuid).to.equal(videoUUID) + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].uuid).to.equal(videoUUID) } }) it('Should search through account videos', async function () { this.timeout(10_000) - const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'Kami no chikara' }) + const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) await waitJobs(servers) for (const server of servers) { - const res = await getAccountVideos(server.url, server.accessToken, 'user1@localhost:' + servers[0].port, 0, 5, undefined, { - search: 'Kami' - }) - - expect(res.body.total).to.equal(1) - expect(res.body.data).to.be.an('array') - expect(res.body.data).to.have.lengthOf(1) - expect(res.body.data[0].uuid).to.equal(resVideo.body.video.uuid) + const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) + + expect(total).to.equal(1) + expect(data).to.be.an('array') + expect(data).to.have.lengthOf(1) + expect(data[0].uuid).to.equal(created.uuid) } }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 30d7e850d..6f3873939 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -6,17 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, flushAndRunServer, - getMyVideos, - getVideosList, killallServers, makePutBodyRequest, - rateVideo, - removeVideo, reRunServer, ServerInfo, setAccessTokensToServers, testImage, - uploadVideo, waitJobs } from '@shared/extra-utils' import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' @@ -25,8 +20,8 @@ const expect = chai.expect describe('Test users', function () { let server: ServerInfo - let accessToken: string - let accessTokenUser: string + let token: string + let userToken: string let videoId: number let userId: number const user = { @@ -101,18 +96,17 @@ describe('Test users', function () { }) it('Should not be able to upload a video', async function () { - accessToken = 'my_super_token' + token = 'my_super_token' - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to follow', async function () { - accessToken = 'my_super_token' + token = 'my_super_token' await server.followsCommand.follow({ targets: [ 'http://example.com' ], - token: accessToken, + token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -122,7 +116,7 @@ describe('Test users', function () { it('Should be able to login', async function () { const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) - accessToken = body.access_token + token = body.access_token }) it('Should be able to login with an insensitive username', async function () { @@ -140,33 +134,31 @@ describe('Test users', function () { describe('Upload', function () { it('Should upload the video with the correct token', async function () { - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes) - const res = await getVideosList(server.url) - const video = res.body.data[0] + await server.videosCommand.upload({ token }) + const { data } = await server.videosCommand.list() + const video = data[0] expect(video.account.name).to.equal('root') videoId = video.id }) it('Should upload the video again with the correct token', async function () { - const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes) + await server.videosCommand.upload({ token }) }) }) describe('Ratings', function () { it('Should retrieve a video rating', async function () { - await rateVideo(server.url, accessToken, videoId, 'like') - const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) + await server.videosCommand.rate({ id: videoId, rating: 'like' }) + const rating = await server.usersCommand.getMyRating({ token, videoId }) expect(rating.videoId).to.equal(videoId) expect(rating.rating).to.equal('like') }) it('Should retrieve ratings list', async function () { - await rateVideo(server.url, accessToken, videoId, 'like') + await server.videosCommand.rate({ id: videoId, rating: 'like' }) const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) @@ -190,13 +182,13 @@ describe('Test users', function () { describe('Remove video', function () { it('Should not be able to remove the video with an incorrect token', async function () { - await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to remove the video with the token of another account') it('Should be able to remove the video with the correct token', async function () { - await removeVideo(server.url, accessToken, videoId) + await server.videosCommand.remove({ token, id: videoId }) }) }) @@ -210,7 +202,7 @@ describe('Test users', function () { }) it('Should not be able to upload a video', async function () { - await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) + await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to rate a video', async function () { @@ -281,11 +273,11 @@ describe('Test users', function () { }) it('Should be able to login with this user', async function () { - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) it('Should be able to get user information', async function () { - const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const userMe = await server.usersCommand.getMyInfo({ token: userToken }) const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) @@ -323,15 +315,15 @@ describe('Test users', function () { it('Should be able to upload a video with this user', async function () { this.timeout(10000) - const videoAttributes = { + const attributes = { name: 'super user video', fixture: 'video_short.webm' } - await uploadVideo(server.url, accessTokenUser, videoAttributes) + await server.videosCommand.upload({ token: userToken, attributes }) }) it('Should have video quota updated', async function () { - const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) expect(quota.videoQuotaUsed).to.equal(218910) const { data } = await server.usersCommand.list() @@ -340,13 +332,11 @@ describe('Test users', function () { }) it('Should be able to list my videos', async function () { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5) - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) - const video: Video = videos[0] + const video: Video = data[0] expect(video.name).to.equal('super user video') expect(video.thumbnailPath).to.not.be.null expect(video.previewPath).to.not.be.null @@ -354,19 +344,15 @@ describe('Test users', function () { it('Should be able to search in my videos', async function () { { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') - expect(res.body.total).to.equal(1) - - const videos = res.body.data - expect(videos).to.have.lengthOf(1) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) } { - const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') - expect(res.body.total).to.equal(0) - - const videos = res.body.data - expect(videos).to.have.lengthOf(0) + const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) + expect(total).to.equal(0) + expect(data).to.have.lengthOf(0) } }) @@ -382,17 +368,17 @@ describe('Test users', function () { } { - const videoAttributes = { + const attributes = { name: 'super user video 2', fixture: 'video_short.webm' } - await uploadVideo(server.url, accessTokenUser, videoAttributes) + await server.videosCommand.upload({ token: userToken, attributes }) await waitJobs([ server ]) } { - const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) + const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) expect(data.videoQuotaUsed).to.be.greaterThan(220000) } }) @@ -505,7 +491,7 @@ describe('Test users', function () { it('Should update my password', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, currentPassword: 'super password', password: 'new password' }) @@ -516,11 +502,11 @@ describe('Test users', function () { it('Should be able to change the NSFW display attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, nsfwPolicy: 'do_not_list' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -532,32 +518,32 @@ describe('Test users', function () { it('Should be able to change the autoPlayVideo attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, autoPlayVideo: false }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.autoPlayVideo).to.be.false }) it('Should be able to change the autoPlayNextVideo attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, autoPlayNextVideo: true }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.autoPlayNextVideo).to.be.true }) it('Should be able to change the email attribute', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, currentPassword: 'new password', email: 'updated@example.com' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -570,9 +556,9 @@ describe('Test users', function () { it('Should be able to update my avatar with a gif', async function () { const fixture = 'avatar.gif' - await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') }) @@ -580,17 +566,17 @@ describe('Test users', function () { for (const extension of [ '.png', '.gif' ]) { const fixture = 'avatar' + extension - await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) + await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) } }) it('Should be able to update my display name', async function () { - await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) + await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -601,9 +587,9 @@ describe('Test users', function () { }) it('Should be able to update my description', async function () { - await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) + await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -617,21 +603,21 @@ describe('Test users', function () { it('Should be able to update my theme', async function () { for (const theme of [ 'background-red', 'default', 'instance-default' ]) { - await server.usersCommand.updateMe({ token: accessTokenUser, theme }) + await server.usersCommand.updateMe({ token: userToken, theme }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.theme).to.equal(theme) } }) it('Should be able to update my modal preferences', async function () { await server.usersCommand.updateMe({ - token: accessTokenUser, + token: userToken, noInstanceConfigWarningModal: true, noWelcomeModal: true }) - const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) + const user = await server.usersCommand.getMyInfo({ token: userToken }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true }) @@ -641,7 +627,7 @@ describe('Test users', function () { it('Should be able to update another user', async function () { await server.usersCommand.update({ userId, - token: accessToken, + token, email: 'updated2@example.com', emailVerified: true, videoQuota: 42, @@ -650,7 +636,7 @@ describe('Test users', function () { pluginAuth: 'toto' }) - const user = await server.usersCommand.get({ token: accessToken, userId }) + const user = await server.usersCommand.get({ token, userId }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated2@example.com') @@ -664,39 +650,39 @@ describe('Test users', function () { }) it('Should reset the auth plugin', async function () { - await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) + await server.usersCommand.update({ userId, token, pluginAuth: null }) - const user = await server.usersCommand.get({ token: accessToken, userId }) + const user = await server.usersCommand.get({ token, userId }) expect(user.pluginAuth).to.be.null }) it('Should have removed the user token', async function () { - await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) it('Should be able to update another user password', async function () { - await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) + await server.usersCommand.update({ userId, token, password: 'password updated' }) - await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) user.password = 'password updated' - accessTokenUser = await server.loginCommand.getAccessToken(user) + userToken = await server.loginCommand.getAccessToken(user) }) }) describe('Video blacklists', function () { it('Should be able to list video blacklist by a moderator', async function () { - await server.blacklistCommand.list({ token: accessTokenUser }) + await server.blacklistCommand.list({ token: userToken }) }) }) describe('Remove a user', function () { it('Should be able to remove this user', async function () { - await server.usersCommand.remove({ userId, token: accessToken }) + await server.usersCommand.remove({ userId, token }) }) it('Should not be able to login with this user', async function () { @@ -704,11 +690,10 @@ describe('Test users', function () { }) it('Should not have videos of this user', async function () { - const res = await getVideosList(server.url) - - expect(res.body.total).to.equal(1) + const { data, total } = await server.videosCommand.list() + expect(total).to.equal(1) - const video = res.body.data[0] + const video = data[0] expect(video.account.name).to.equal('root') }) }) @@ -832,12 +817,11 @@ describe('Test users', function () { }) it('Should report correct videos count', async function () { - const videoAttributes = { - name: 'video to test user stats' - } - await uploadVideo(server.url, user17AccessToken, videoAttributes) - const res1 = await getVideosList(server.url) - videoId = res1.body.data.find(video => video.name === videoAttributes.name).id + const attributes = { name: 'video to test user stats' } + await server.videosCommand.upload({ token: user17AccessToken, attributes }) + + const { data } = await server.videosCommand.list() + videoId = data.find(video => video.name === attributes.name).id const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(1) -- cgit v1.2.3 From 89d241a79c262b9775c233b73cff080043ebb5e6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:04:35 +0200 Subject: Shorter server command names --- server/tests/api/users/user-subscriptions.ts | 34 +-- server/tests/api/users/users-multiple-servers.ts | 40 ++-- server/tests/api/users/users-verification.ts | 34 +-- server/tests/api/users/users.ts | 262 +++++++++++------------ 4 files changed, 185 insertions(+), 185 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 622cddb7d..1b15a98dc 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -35,26 +35,26 @@ describe('Test users subscriptions', function () { { for (const server of servers) { const user = { username: 'user' + server.serverNumber, password: 'password' } - await server.usersCommand.create({ username: user.username, password: user.password }) + await server.users.create({ username: user.username, password: user.password }) - const accessToken = await server.loginCommand.getAccessToken(user) + const accessToken = await server.login.getAccessToken(user) users.push({ accessToken }) const videoName1 = 'video 1-' + server.serverNumber - await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName1 } }) + await server.videos.upload({ token: accessToken, attributes: { name: videoName1 } }) const videoName2 = 'video 2-' + server.serverNumber - await server.videosCommand.upload({ token: accessToken, attributes: { name: videoName2 } }) + await server.videos.upload({ token: accessToken, attributes: { name: videoName2 } }) } } await waitJobs(servers) - command = servers[0].subscriptionsCommand + command = servers[0].subscriptions }) it('Should display videos of server 2 on server 1', async function () { - const { total } = await servers[0].videosCommand.list() + const { total } = await servers[0].videos.list() expect(total).to.equal(4) }) @@ -67,14 +67,14 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const { uuid } = await servers[2].videosCommand.upload({ attributes: { name: 'video server 3 added after follow' } }) + const { uuid } = await servers[2].videos.upload({ attributes: { name: 'video server 3 added after follow' } }) video3UUID = uuid await waitJobs(servers) }) it('Should not display videos of server 3 on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(4) for (const video of data) { @@ -183,7 +183,7 @@ describe('Test users subscriptions', function () { this.timeout(60000) const videoName = 'video server 1 added after follow' - await servers[0].videosCommand.upload({ attributes: { name: videoName } }) + await servers[0].videos.upload({ attributes: { name: videoName } }) await waitJobs(servers) @@ -209,7 +209,7 @@ describe('Test users subscriptions', function () { } { - const { data, total } = await servers[0].videosCommand.list() + const { data, total } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { @@ -223,11 +223,11 @@ describe('Test users subscriptions', function () { it('Should have server 1 follow server 3 and display server 3 videos', async function () { this.timeout(60000) - await servers[0].followsCommand.follow({ targets: [ servers[2].url ] }) + await servers[0].follows.follow({ targets: [ servers[2].url ] }) await waitJobs(servers) - const { data, total } = await servers[0].videosCommand.list() + const { data, total } = await servers[0].videos.list() expect(total).to.equal(8) const names = [ '1-3', '2-3', 'video server 3 added after follow' ] @@ -240,11 +240,11 @@ describe('Test users subscriptions', function () { it('Should remove follow server 1 -> server 3 and hide server 3 videos', async function () { this.timeout(60000) - await servers[0].followsCommand.unfollow({ target: servers[2] }) + await servers[0].follows.unfollow({ target: servers[2] }) await waitJobs(servers) - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { @@ -280,7 +280,7 @@ describe('Test users subscriptions', function () { it('Should update a video of server 3 and see the updated video on server 1', async function () { this.timeout(30000) - await servers[2].videosCommand.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) + await servers[2].videos.update({ id: video3UUID, attributes: { name: 'video server 3 added after follow updated' } }) await waitJobs(servers) @@ -325,7 +325,7 @@ describe('Test users subscriptions', function () { }) it('Should correctly display public videos on server 1', async function () { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { @@ -356,7 +356,7 @@ describe('Test users subscriptions', function () { } { - const { total, data } = await servers[0].videosCommand.list() + const { total, data } = await servers[0].videos.list() expect(total).to.equal(5) for (const video of data) { diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index 3ae105008..f8d7ae88e 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -42,20 +42,20 @@ describe('Test users with multiple servers', function () { await doubleFollow(servers[1], servers[2]) // The root user of server 1 is propagated to servers 2 and 3 - await servers[0].videosCommand.upload() + await servers[0].videos.upload() { const user = { username: 'user1', password: 'password' } - const created = await servers[0].usersCommand.create(user) + const created = await servers[0].users.create(user) userId = created.id - userAccessToken = await servers[0].loginCommand.getAccessToken(user) + userAccessToken = await servers[0].login.getAccessToken(user) } { - const { uuid } = await servers[0].videosCommand.upload({ token: userAccessToken }) + const { uuid } = await servers[0].videos.upload({ token: userAccessToken }) videoUUID = uuid } @@ -65,9 +65,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my display name', async function () { this.timeout(10000) - await servers[0].usersCommand.updateMe({ displayName: 'my super display name' }) + await servers[0].users.updateMe({ displayName: 'my super display name' }) - user = await servers[0].usersCommand.getMyInfo() + user = await servers[0].users.getMyInfo() expect(user.account.displayName).to.equal('my super display name') await waitJobs(servers) @@ -76,9 +76,9 @@ describe('Test users with multiple servers', function () { it('Should be able to update my description', async function () { this.timeout(10_000) - await servers[0].usersCommand.updateMe({ description: 'my super description updated' }) + await servers[0].users.updateMe({ description: 'my super description updated' }) - user = await servers[0].usersCommand.getMyInfo() + user = await servers[0].users.getMyInfo() expect(user.account.displayName).to.equal('my super display name') expect(user.account.description).to.equal('my super description updated') @@ -90,9 +90,9 @@ describe('Test users with multiple servers', function () { const fixture = 'avatar2.png' - await servers[0].usersCommand.updateMyAvatar({ fixture }) + await servers[0].users.updateMyAvatar({ fixture }) - user = await servers[0].usersCommand.getMyInfo() + user = await servers[0].users.getMyInfo() userAvatarFilename = user.account.avatar.path await testImage(servers[0].url, 'avatar2-resized', userAvatarFilename, '.png') @@ -104,12 +104,12 @@ describe('Test users with multiple servers', function () { let createdAt: string | Date for (const server of servers) { - const body = await server.accountsCommand.list({ sort: '-createdAt' }) + const body = await server.accounts.list({ sort: '-createdAt' }) const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) expect(resList).not.to.be.undefined - const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host }) + const account = await server.accounts.get({ accountName: resList.name + '@' + resList.host }) if (!createdAt) createdAt = account.createdAt @@ -131,7 +131,7 @@ describe('Test users with multiple servers', function () { it('Should list account videos', async function () { for (const server of servers) { - const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) + const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -143,12 +143,12 @@ describe('Test users with multiple servers', function () { it('Should search through account videos', async function () { this.timeout(10_000) - const created = await servers[0].videosCommand.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) + const created = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'Kami no chikara' } }) await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videosCommand.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) + const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -161,27 +161,27 @@ describe('Test users with multiple servers', function () { this.timeout(10_000) for (const server of servers) { - const body = await server.accountsCommand.list({ sort: '-createdAt' }) + const body = await server.accounts.list({ sort: '-createdAt' }) const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).not.to.be.undefined - const { data } = await server.channelsCommand.list() + const { data } = await server.channels.list() const videoChannelDeleted = data.find(a => a.displayName === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).not.to.be.undefined } - await servers[0].usersCommand.remove({ userId }) + await servers[0].users.remove({ userId }) await waitJobs(servers) for (const server of servers) { - const body = await server.accountsCommand.list({ sort: '-createdAt' }) + const body = await server.accounts.list({ sort: '-createdAt' }) const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) expect(accountDeleted).to.be.undefined - const { data } = await server.channelsCommand.list() + const { data } = await server.channels.list() const videoChannelDeleted = data.find(a => a.name === 'Main user1 channel' && a.host === 'localhost:' + servers[0].port) expect(videoChannelDeleted).to.be.undefined } diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 271aa3c7a..c8c226fa8 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -42,7 +42,7 @@ describe('Test users account verification', function () { it('Should register user and send verification email if verification required', async function () { this.timeout(30000) - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { signup: { enabled: true, @@ -52,7 +52,7 @@ describe('Test users account verification', function () { } }) - await server.usersCommand.register(user1) + await server.users.register(user1) await waitJobs(server) expectedEmailsLength++ @@ -71,22 +71,22 @@ describe('Test users account verification', function () { userId = parseInt(userIdMatches[1], 10) - const body = await server.usersCommand.get({ userId }) + const body = await server.users.get({ userId }) expect(body.emailVerified).to.be.false }) it('Should not allow login for user with unverified email', async function () { - const { detail } = await server.loginCommand.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const { detail } = await server.login.login({ user: user1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(detail).to.contain('User email is not verified.') }) it('Should verify the user via email and allow login', async function () { - await server.usersCommand.verifyEmail({ userId, verificationString }) + await server.users.verifyEmail({ userId, verificationString }) - const body = await server.loginCommand.login({ user: user1 }) + const body = await server.login.login({ user: user1 }) userAccessToken = body.access_token - const user = await server.usersCommand.get({ userId }) + const user = await server.users.get({ userId }) expect(user.emailVerified).to.be.true }) @@ -96,7 +96,7 @@ describe('Test users account verification', function () { let updateVerificationString: string { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userAccessToken, email: 'updated@example.com', currentPassword: user1.password @@ -113,15 +113,15 @@ describe('Test users account verification', function () { } { - const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) + const me = await server.users.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('user_1@example.com') expect(me.pendingEmail).to.equal('updated@example.com') } { - await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) + await server.users.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true }) - const me = await server.usersCommand.getMyInfo({ token: userAccessToken }) + const me = await server.users.getMyInfo({ token: userAccessToken }) expect(me.email).to.equal('updated@example.com') expect(me.pendingEmail).to.be.null } @@ -129,7 +129,7 @@ describe('Test users account verification', function () { it('Should register user not requiring email verification if setting not enabled', async function () { this.timeout(5000) - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { signup: { enabled: true, @@ -139,19 +139,19 @@ describe('Test users account verification', function () { } }) - await server.usersCommand.register(user2) + await server.users.register(user2) await waitJobs(server) expect(emails).to.have.lengthOf(expectedEmailsLength) - const accessToken = await server.loginCommand.getAccessToken(user2) + const accessToken = await server.login.getAccessToken(user2) - const user = await server.usersCommand.getMyInfo({ token: accessToken }) + const user = await server.users.getMyInfo({ token: accessToken }) expect(user.emailVerified).to.be.null }) it('Should allow login for user with unverified email when setting later enabled', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { signup: { enabled: true, @@ -161,7 +161,7 @@ describe('Test users account verification', function () { } }) - await server.loginCommand.getAccessToken(user2) + await server.login.getAccessToken(user2) }) after(async function () { diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6f3873939..310136a37 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -42,7 +42,7 @@ describe('Test users', function () { await setAccessTokensToServers([ server ]) - await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) + await server.plugins.install({ npmName: 'peertube-theme-background-red' }) }) describe('OAuth client', function () { @@ -53,8 +53,8 @@ describe('Test users', function () { it('Should remove the last client') it('Should not login with an invalid client id', async function () { - const client = { id: 'client', secret: server.client.secret } - const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const client = { id: 'client', secret: server.store.client.secret } + const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) expect(body.error).to.contain('client is invalid') @@ -63,8 +63,8 @@ describe('Test users', function () { }) it('Should not login with an invalid client secret', async function () { - const client = { id: server.client.id, secret: 'coucou' } - const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const client = { id: server.store.client.id, secret: 'coucou' } + const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) expect(body.error).to.contain('client is invalid') @@ -76,8 +76,8 @@ describe('Test users', function () { describe('Login', function () { it('Should not login with an invalid username', async function () { - const user = { username: 'captain crochet', password: server.user.password } - const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const user = { username: 'captain crochet', password: server.store.user.password } + const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) expect(body.error).to.contain('credentials are invalid') @@ -86,8 +86,8 @@ describe('Test users', function () { }) it('Should not login with an invalid password', async function () { - const user = { username: server.user.username, password: 'mew_three' } - const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + const user = { username: server.store.user.username, password: 'mew_three' } + const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) expect(body.error).to.contain('credentials are invalid') @@ -98,13 +98,13 @@ describe('Test users', function () { it('Should not be able to upload a video', async function () { token = 'my_super_token' - await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.videos.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to follow', async function () { token = 'my_super_token' - await server.followsCommand.follow({ + await server.follows.follow({ targets: [ 'http://example.com' ], token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 @@ -114,28 +114,28 @@ describe('Test users', function () { it('Should not be able to unfollow') it('Should be able to login', async function () { - const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) + const body = await server.login.login({ expectedStatus: HttpStatusCode.OK_200 }) token = body.access_token }) it('Should be able to login with an insensitive username', async function () { - const user = { username: 'RoOt', password: server.user.password } - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 }) + const user = { username: 'RoOt', password: server.store.user.password } + await server.login.login({ user, expectedStatus: HttpStatusCode.OK_200 }) - const user2 = { username: 'rOoT', password: server.user.password } - await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) + const user2 = { username: 'rOoT', password: server.store.user.password } + await server.login.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) - const user3 = { username: 'ROOt', password: server.user.password } - await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) + const user3 = { username: 'ROOt', password: server.store.user.password } + await server.login.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) }) }) describe('Upload', function () { it('Should upload the video with the correct token', async function () { - await server.videosCommand.upload({ token }) - const { data } = await server.videosCommand.list() + await server.videos.upload({ token }) + const { data } = await server.videos.list() const video = data[0] expect(video.account.name).to.equal('root') @@ -143,24 +143,24 @@ describe('Test users', function () { }) it('Should upload the video again with the correct token', async function () { - await server.videosCommand.upload({ token }) + await server.videos.upload({ token }) }) }) describe('Ratings', function () { it('Should retrieve a video rating', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'like' }) - const rating = await server.usersCommand.getMyRating({ token, videoId }) + await server.videos.rate({ id: videoId, rating: 'like' }) + const rating = await server.users.getMyRating({ token, videoId }) expect(rating.videoId).to.equal(videoId) expect(rating.rating).to.equal('like') }) it('Should retrieve ratings list', async function () { - await server.videosCommand.rate({ id: videoId, rating: 'like' }) + await server.videos.rate({ id: videoId, rating: 'like' }) - const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) + const body = await server.accounts.listRatings({ accountName: server.store.user.username }) expect(body.total).to.equal(1) expect(body.data[0].video.id).to.equal(videoId) @@ -169,12 +169,12 @@ describe('Test users', function () { it('Should retrieve ratings list by rating type', async function () { { - const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' }) + const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'like' }) expect(body.data.length).to.equal(1) } { - const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' }) + const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'dislike' }) expect(body.data.length).to.equal(0) } }) @@ -182,27 +182,27 @@ describe('Test users', function () { describe('Remove video', function () { it('Should not be able to remove the video with an incorrect token', async function () { - await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to remove the video with the token of another account') it('Should be able to remove the video with the correct token', async function () { - await server.videosCommand.remove({ token, id: videoId }) + await server.videos.remove({ token, id: videoId }) }) }) describe('Logout', function () { it('Should logout (revoke token)', async function () { - await server.loginCommand.logout({ token: server.accessToken }) + await server.login.logout({ token: server.accessToken }) }) it('Should not be able to get the user information', async function () { - await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to upload a video', async function () { - await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.videos.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to rate a video', async function () { @@ -222,64 +222,64 @@ describe('Test users', function () { }) it('Should be able to login again', async function () { - const body = await server.loginCommand.login() + const body = await server.login.login() server.accessToken = body.access_token server.refreshToken = body.refresh_token }) it('Should be able to get my user information again', async function () { - await server.usersCommand.getMyInfo() + await server.users.getMyInfo() }) it('Should have an expired access token', async function () { this.timeout(15000) - await server.sqlCommand.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) - await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) + await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) + await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) await killallServers([ server ]) await reRunServer(server) - await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should not be able to refresh an access token with an expired refresh token', async function () { - await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should refresh the token', async function () { this.timeout(15000) const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() - await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) + await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) await killallServers([ server ]) await reRunServer(server) - const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken }) + const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) server.accessToken = res.body.access_token server.refreshToken = res.body.refresh_token }) it('Should be able to get my user information again', async function () { - await server.usersCommand.getMyInfo() + await server.users.getMyInfo() }) }) describe('Creating a user', function () { it('Should be able to create a new user', async function () { - await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) + await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) }) it('Should be able to login with this user', async function () { - userToken = await server.loginCommand.getAccessToken(user) + userToken = await server.login.getAccessToken(user) }) it('Should be able to get user information', async function () { - const userMe = await server.usersCommand.getMyInfo({ token: userToken }) + const userMe = await server.users.getMyInfo({ token: userToken }) - const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) + const userGet = await server.users.get({ userId: userMe.id, withStats: true }) for (const user of [ userMe, userGet ]) { expect(user.username).to.equal('user_1') @@ -319,20 +319,20 @@ describe('Test users', function () { name: 'super user video', fixture: 'video_short.webm' } - await server.videosCommand.upload({ token: userToken, attributes }) + await server.videos.upload({ token: userToken, attributes }) }) it('Should have video quota updated', async function () { - const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) + const quota = await server.users.getMyQuotaUsed({ token: userToken }) expect(quota.videoQuotaUsed).to.equal(218910) - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() const tmpUser = data.find(u => u.username === user.username) expect(tmpUser.videoQuotaUsed).to.equal(218910) }) it('Should be able to list my videos', async function () { - const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) + const { total, data } = await server.videos.listMyVideos({ token: userToken }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) @@ -344,13 +344,13 @@ describe('Test users', function () { it('Should be able to search in my videos', async function () { { - const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) + const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) expect(total).to.equal(1) expect(data).to.have.lengthOf(1) } { - const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) + const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) expect(total).to.equal(0) expect(data).to.have.lengthOf(0) } @@ -360,11 +360,11 @@ describe('Test users', function () { this.timeout(60000) { - const config = await server.configCommand.getCustomConfig() + const config = await server.config.getCustomConfig() config.transcoding.webtorrent.enabled = false config.transcoding.hls.enabled = true config.transcoding.enabled = true - await server.configCommand.updateCustomSubConfig({ newConfig: config }) + await server.config.updateCustomSubConfig({ newConfig: config }) } { @@ -372,13 +372,13 @@ describe('Test users', function () { name: 'super user video 2', fixture: 'video_short.webm' } - await server.videosCommand.upload({ token: userToken, attributes }) + await server.videos.upload({ token: userToken, attributes }) await waitJobs([ server ]) } { - const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) + const data = await server.users.getMyQuotaUsed({ token: userToken }) expect(data.videoQuotaUsed).to.be.greaterThan(220000) } }) @@ -387,7 +387,7 @@ describe('Test users', function () { describe('Users listing', function () { it('Should list all the users', async function () { - const { data, total } = await server.usersCommand.list() + const { data, total } = await server.users.list() expect(total).to.equal(2) expect(data).to.be.an('array') @@ -410,7 +410,7 @@ describe('Test users', function () { }) it('Should list only the first user by username asc', async function () { - const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' }) + const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' }) expect(total).to.equal(2) expect(data.length).to.equal(1) @@ -423,7 +423,7 @@ describe('Test users', function () { }) it('Should list only the first user by username desc', async function () { - const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' }) + const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' }) expect(total).to.equal(2) expect(data.length).to.equal(1) @@ -435,7 +435,7 @@ describe('Test users', function () { }) it('Should list only the second user by createdAt desc', async function () { - const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' }) + const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' }) expect(total).to.equal(2) expect(data.length).to.equal(1) @@ -447,7 +447,7 @@ describe('Test users', function () { }) it('Should list all the users by createdAt asc', async function () { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' }) expect(total).to.equal(2) expect(data.length).to.equal(2) @@ -462,7 +462,7 @@ describe('Test users', function () { }) it('Should search user by username', async function () { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) expect(total).to.equal(1) expect(data.length).to.equal(1) expect(data[0].username).to.equal('root') @@ -470,7 +470,7 @@ describe('Test users', function () { it('Should search user by email', async function () { { - const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) + const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) expect(total).to.equal(1) expect(data.length).to.equal(1) expect(data[0].username).to.equal('user_1') @@ -478,7 +478,7 @@ describe('Test users', function () { } { - const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) + const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) expect(total).to.equal(2) expect(data.length).to.equal(2) expect(data[0].username).to.equal('root') @@ -490,23 +490,23 @@ describe('Test users', function () { describe('Update my account', function () { it('Should update my password', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, currentPassword: 'super password', password: 'new password' }) user.password = 'new password' - await server.loginCommand.login({ user }) + await server.login.login({ user }) }) it('Should be able to change the NSFW display attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, nsfwPolicy: 'do_not_list' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('user_1@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -517,33 +517,33 @@ describe('Test users', function () { }) it('Should be able to change the autoPlayVideo attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, autoPlayVideo: false }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.autoPlayVideo).to.be.false }) it('Should be able to change the autoPlayNextVideo attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, autoPlayNextVideo: true }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.autoPlayNextVideo).to.be.true }) it('Should be able to change the email attribute', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, currentPassword: 'new password', email: 'updated@example.com' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -556,9 +556,9 @@ describe('Test users', function () { it('Should be able to update my avatar with a gif', async function () { const fixture = 'avatar.gif' - await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) + await server.users.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') }) @@ -566,17 +566,17 @@ describe('Test users', function () { for (const extension of [ '.png', '.gif' ]) { const fixture = 'avatar' + extension - await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) + await server.users.updateMyAvatar({ token: userToken, fixture }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) } }) it('Should be able to update my display name', async function () { - await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) + await server.users.updateMe({ token: userToken, displayName: 'new display name' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -587,9 +587,9 @@ describe('Test users', function () { }) it('Should be able to update my description', async function () { - await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) + await server.users.updateMe({ token: userToken, description: 'my super description updated' }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated@example.com') expect(user.nsfwPolicy).to.equal('do_not_list') @@ -603,21 +603,21 @@ describe('Test users', function () { it('Should be able to update my theme', async function () { for (const theme of [ 'background-red', 'default', 'instance-default' ]) { - await server.usersCommand.updateMe({ token: userToken, theme }) + await server.users.updateMe({ token: userToken, theme }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.theme).to.equal(theme) } }) it('Should be able to update my modal preferences', async function () { - await server.usersCommand.updateMe({ + await server.users.updateMe({ token: userToken, noInstanceConfigWarningModal: true, noWelcomeModal: true }) - const user = await server.usersCommand.getMyInfo({ token: userToken }) + const user = await server.users.getMyInfo({ token: userToken }) expect(user.noWelcomeModal).to.be.true expect(user.noInstanceConfigWarningModal).to.be.true }) @@ -625,7 +625,7 @@ describe('Test users', function () { describe('Updating another user', function () { it('Should be able to update another user', async function () { - await server.usersCommand.update({ + await server.users.update({ userId, token, email: 'updated2@example.com', @@ -636,7 +636,7 @@ describe('Test users', function () { pluginAuth: 'toto' }) - const user = await server.usersCommand.get({ token, userId }) + const user = await server.users.get({ token, userId }) expect(user.username).to.equal('user_1') expect(user.email).to.equal('updated2@example.com') @@ -650,47 +650,47 @@ describe('Test users', function () { }) it('Should reset the auth plugin', async function () { - await server.usersCommand.update({ userId, token, pluginAuth: null }) + await server.users.update({ userId, token, pluginAuth: null }) - const user = await server.usersCommand.get({ token, userId }) + const user = await server.users.get({ token, userId }) expect(user.pluginAuth).to.be.null }) it('Should have removed the user token', async function () { - await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - userToken = await server.loginCommand.getAccessToken(user) + userToken = await server.login.getAccessToken(user) }) it('Should be able to update another user password', async function () { - await server.usersCommand.update({ userId, token, password: 'password updated' }) + await server.users.update({ userId, token, password: 'password updated' }) - await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) user.password = 'password updated' - userToken = await server.loginCommand.getAccessToken(user) + userToken = await server.login.getAccessToken(user) }) }) describe('Video blacklists', function () { it('Should be able to list video blacklist by a moderator', async function () { - await server.blacklistCommand.list({ token: userToken }) + await server.blacklist.list({ token: userToken }) }) }) describe('Remove a user', function () { it('Should be able to remove this user', async function () { - await server.usersCommand.remove({ userId, token }) + await server.users.remove({ userId, token }) }) it('Should not be able to login with this user', async function () { - await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should not have videos of this user', async function () { - const { data, total } = await server.videosCommand.list() + const { data, total } = await server.videos.list() expect(total).to.equal(1) const video = data[0] @@ -705,7 +705,7 @@ describe('Test users', function () { const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } - await server.usersCommand.register({ ...user, channel }) + await server.users.register({ ...user, channel }) }) it('Should be able to login with this registered user', async function () { @@ -714,35 +714,35 @@ describe('Test users', function () { password: 'my super password' } - user15AccessToken = await server.loginCommand.getAccessToken(user15) + user15AccessToken = await server.login.getAccessToken(user15) }) it('Should have the correct display name', async function () { - const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) + const user = await server.users.getMyInfo({ token: user15AccessToken }) expect(user.account.displayName).to.equal('super user 15') }) it('Should have the correct video quota', async function () { - const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) + const user = await server.users.getMyInfo({ token: user15AccessToken }) expect(user.videoQuota).to.equal(5 * 1024 * 1024) }) it('Should have created the channel', async function () { - const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' }) + const { displayName } = await server.channels.get({ channelName: 'my_user_15_channel' }) expect(displayName).to.equal('my channel rocks') }) it('Should remove me', async function () { { - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() expect(data.find(u => u.username === 'user_15')).to.not.be.undefined } - await server.usersCommand.deleteMe({ token: user15AccessToken }) + await server.users.deleteMe({ token: user15AccessToken }) { - const { data } = await server.usersCommand.list() + const { data } = await server.users.list() expect(data.find(u => u.username === 'user_15')).to.be.undefined } }) @@ -757,21 +757,21 @@ describe('Test users', function () { } it('Should block a user', async function () { - const user = await server.usersCommand.create({ ...user16 }) + const user = await server.users.create({ ...user16 }) user16Id = user.id - user16AccessToken = await server.loginCommand.getAccessToken(user16) + user16AccessToken = await server.login.getAccessToken(user16) - await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) - await server.usersCommand.banUser({ userId: user16Id }) + await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) + await server.users.banUser({ userId: user16Id }) - await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) - await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) + await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) + await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should search user by banned status', async function () { { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) expect(total).to.equal(1) expect(data.length).to.equal(1) @@ -779,7 +779,7 @@ describe('Test users', function () { } { - const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) + const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) expect(total).to.equal(1) expect(data.length).to.equal(1) @@ -788,9 +788,9 @@ describe('Test users', function () { }) it('Should unblock a user', async function () { - await server.usersCommand.unbanUser({ userId: user16Id }) - user16AccessToken = await server.loginCommand.getAccessToken(user16) - await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) + await server.users.unbanUser({ userId: user16Id }) + user16AccessToken = await server.login.getAccessToken(user16) + await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -803,12 +803,12 @@ describe('Test users', function () { username: 'user_17', password: 'my super password' } - const created = await server.usersCommand.create({ ...user17 }) + const created = await server.users.create({ ...user17 }) user17Id = created.id - user17AccessToken = await server.loginCommand.getAccessToken(user17) + user17AccessToken = await server.login.getAccessToken(user17) - const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user = await server.users.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(0) expect(user.videoCommentsCount).to.equal(0) expect(user.abusesCount).to.equal(0) @@ -818,37 +818,37 @@ describe('Test users', function () { it('Should report correct videos count', async function () { const attributes = { name: 'video to test user stats' } - await server.videosCommand.upload({ token: user17AccessToken, attributes }) + await server.videos.upload({ token: user17AccessToken, attributes }) - const { data } = await server.videosCommand.list() + const { data } = await server.videos.list() videoId = data.find(video => video.name === attributes.name).id - const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user = await server.users.get({ userId: user17Id, withStats: true }) expect(user.videosCount).to.equal(1) }) it('Should report correct video comments for user', async function () { const text = 'super comment' - await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) + await server.comments.createThread({ token: user17AccessToken, videoId, text }) - const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user = await server.users.get({ userId: user17Id, withStats: true }) expect(user.videoCommentsCount).to.equal(1) }) it('Should report correct abuses counts', async function () { const reason = 'my super bad reason' - await server.abusesCommand.report({ token: user17AccessToken, videoId, reason }) + await server.abuses.report({ token: user17AccessToken, videoId, reason }) - const body1 = await server.abusesCommand.getAdminList() + const body1 = await server.abuses.getAdminList() const abuseId = body1.data[0].id - const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user2 = await server.users.get({ userId: user17Id, withStats: true }) expect(user2.abusesCount).to.equal(1) // number of incriminations expect(user2.abusesCreatedCount).to.equal(1) // number of reports created - await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) + await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) - const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true }) + const user3 = await server.users.get({ userId: user17Id, withStats: true }) expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted }) }) -- cgit v1.2.3 From 254d3579f5338f5fd775c17d15cdfc37078bcfb4 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 09:47:51 +0200 Subject: Use an object to represent a server --- server/tests/api/users/user-subscriptions.ts | 8 ++++---- server/tests/api/users/users-multiple-servers.ts | 8 ++++---- server/tests/api/users/users-verification.ts | 6 +++--- server/tests/api/users/users.ts | 13 ++++++------- 4 files changed, 17 insertions(+), 18 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 1b15a98dc..d2bb9c387 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -5,8 +5,8 @@ import * as chai from 'chai' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, SubscriptionsCommand, waitJobs @@ -15,7 +15,7 @@ import { const expect = chai.expect describe('Test users subscriptions', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] const users: { accessToken: string }[] = [] let video3UUID: string @@ -24,7 +24,7 @@ describe('Test users subscriptions', function () { before(async function () { this.timeout(120000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index f8d7ae88e..e629966bb 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -8,8 +8,8 @@ import { checkVideoFilesWereRemoved, cleanupTests, doubleFollow, - flushAndRunMultipleServers, - ServerInfo, + createMultipleServers, + PeerTubeServer, setAccessTokensToServers, testImage, waitJobs @@ -19,7 +19,7 @@ import { User } from '@shared/models' const expect = chai.expect describe('Test users with multiple servers', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let user: User let userId: number let videoUUID: string @@ -29,7 +29,7 @@ describe('Test users with multiple servers', function () { before(async function () { this.timeout(120_000) - servers = await flushAndRunMultipleServers(3) + servers = await createMultipleServers(3) // Get the access tokens await setAccessTokensToServers(servers) diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index c8c226fa8..5dbe2af59 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -3,12 +3,12 @@ import 'mocha' import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' -import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect describe('Test users account verification', function () { - let server: ServerInfo + let server: PeerTubeServer let userId: number let userAccessToken: string let verificationString: string @@ -34,7 +34,7 @@ describe('Test users account verification', function () { port } } - server = await flushAndRunServer(1, overrideConfig) + server = await createSingleServer(1, overrideConfig) await setAccessTokensToServers([ server ]) }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 310136a37..6ae5410b3 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -5,11 +5,10 @@ import * as chai from 'chai' import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, - flushAndRunServer, + createSingleServer, killallServers, makePutBodyRequest, - reRunServer, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, testImage, waitJobs @@ -19,7 +18,7 @@ import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlayl const expect = chai.expect describe('Test users', function () { - let server: ServerInfo + let server: PeerTubeServer let token: string let userToken: string let videoId: number @@ -32,7 +31,7 @@ describe('Test users', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1, { + server = await createSingleServer(1, { rates_limit: { login: { max: 30 @@ -238,7 +237,7 @@ describe('Test users', function () { await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) await killallServers([ server ]) - await reRunServer(server) + await server.run() await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -254,7 +253,7 @@ describe('Test users', function () { await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) await killallServers([ server ]) - await reRunServer(server) + await server.run() const res = await server.login.refreshToken({ refreshToken: server.refreshToken }) server.accessToken = res.body.access_token -- cgit v1.2.3 From c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 10:42:24 +0200 Subject: Refactor requests --- server/tests/api/users/users-multiple-servers.ts | 4 ++-- server/tests/api/users/users-verification.ts | 2 +- server/tests/api/users/users.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index e629966bb..e304e5d67 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -131,7 +131,7 @@ describe('Test users with multiple servers', function () { it('Should list account videos', async function () { for (const server of servers) { - const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port }) + const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port }) expect(total).to.equal(1) expect(data).to.be.an('array') @@ -148,7 +148,7 @@ describe('Test users with multiple servers', function () { await waitJobs(servers) for (const server of servers) { - const { total, data } = await server.videos.listByAccount({ accountName: 'user1@localhost:' + servers[0].port, search: 'Kami' }) + const { total, data } = await server.videos.listByAccount({ handle: 'user1@localhost:' + servers[0].port, search: 'Kami' }) expect(total).to.equal(1) expect(data).to.be.an('array') diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 5dbe2af59..56fc25048 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' const expect = chai.expect diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6ae5410b3..be80c2616 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,7 +2,7 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -215,7 +215,7 @@ describe('Test users', function () { path: path + videoId, token: 'wrong token', fields: data, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 } await makePutBodyRequest(options) }) -- cgit v1.2.3 From 4c7e60bc17ee5830399bac4aa273356903421b4c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 16 Jul 2021 14:27:30 +0200 Subject: Reorganize imports --- server/tests/api/users/user-subscriptions.ts | 5 +++-- server/tests/api/users/users-multiple-servers.ts | 2 +- server/tests/api/users/users-verification.ts | 2 +- server/tests/api/users/users.ts | 3 +-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index d2bb9c387..565b4bd77 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -4,8 +4,8 @@ import 'mocha' import * as chai from 'chai' import { cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, SubscriptionsCommand, @@ -67,7 +67,8 @@ describe('Test users subscriptions', function () { await waitJobs(servers) - const { uuid } = await servers[2].videos.upload({ attributes: { name: 'video server 3 added after follow' } }) + const attributes = { name: 'video server 3 added after follow' } + const { uuid } = await servers[2].videos.upload({ token: users[2].accessToken, attributes }) video3UUID = uuid await waitJobs(servers) diff --git a/server/tests/api/users/users-multiple-servers.ts b/server/tests/api/users/users-multiple-servers.ts index e304e5d67..225145957 100644 --- a/server/tests/api/users/users-multiple-servers.ts +++ b/server/tests/api/users/users-multiple-servers.ts @@ -7,8 +7,8 @@ import { checkTmpIsEmpty, checkVideoFilesWereRemoved, cleanupTests, - doubleFollow, createMultipleServers, + doubleFollow, PeerTubeServer, setAccessTokensToServers, testImage, diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 56fc25048..f54463359 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -2,8 +2,8 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, MockSmtpServer, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' +import { HttpStatusCode } from '@shared/models' const expect = chai.expect diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index be80c2616..066da88ee 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -2,7 +2,6 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/models' import { cleanupTests, createSingleServer, @@ -13,7 +12,7 @@ import { testImage, waitJobs } from '@shared/extra-utils' -import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' +import { AbuseState, HttpStatusCode, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' const expect = chai.expect -- cgit v1.2.3 From 4d029ef8ec3d5274eeaa3ee6d808eb7035e7faef Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 20 Jul 2021 14:15:15 +0200 Subject: Add ability for instances to follow any actor --- server/tests/api/users/user-subscriptions.ts | 2 +- server/tests/api/users/users.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/user-subscriptions.ts b/server/tests/api/users/user-subscriptions.ts index 565b4bd77..77b99886d 100644 --- a/server/tests/api/users/user-subscriptions.ts +++ b/server/tests/api/users/user-subscriptions.ts @@ -224,7 +224,7 @@ describe('Test users subscriptions', function () { it('Should have server 1 follow server 3 and display server 3 videos', async function () { this.timeout(60000) - await servers[0].follows.follow({ targets: [ servers[2].url ] }) + await servers[0].follows.follow({ hosts: [ servers[2].url ] }) await waitJobs(servers) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 066da88ee..1419ae820 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -103,7 +103,7 @@ describe('Test users', function () { token = 'my_super_token' await server.follows.follow({ - targets: [ 'http://example.com' ], + hosts: [ 'http://example.com' ], token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) -- cgit v1.2.3