aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/activitypub/refresher.ts20
-rw-r--r--server/tests/api/check-params/accounts.ts15
-rw-r--r--server/tests/api/moderation/abuses.ts13
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts5
-rw-r--r--server/tests/api/server/follows.ts40
-rw-r--r--server/tests/api/users/users-multiple-servers.ts37
-rw-r--r--server/tests/api/users/users.ts20
7 files changed, 73 insertions, 77 deletions
diff --git a/server/tests/api/activitypub/refresher.ts b/server/tests/api/activitypub/refresher.ts
index c717f1a30..0d5452ea4 100644
--- a/server/tests/api/activitypub/refresher.ts
+++ b/server/tests/api/activitypub/refresher.ts
@@ -1,8 +1,10 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '@shared/core-utils'
4import { 5import {
5 cleanupTests, closeAllSequelize, 6 cleanupTests,
7 closeAllSequelize,
6 createVideoPlaylist, 8 createVideoPlaylist,
7 doubleFollow, 9 doubleFollow,
8 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
@@ -21,10 +23,8 @@ import {
21 uploadVideoAndGetId, 23 uploadVideoAndGetId,
22 wait, 24 wait,
23 waitJobs 25 waitJobs
24} from '../../../../shared/extra-utils' 26} from '@shared/extra-utils'
25import { getAccount } from '../../../../shared/extra-utils/users/accounts' 27import { VideoPlaylistPrivacy } from '@shared/models'
26import { VideoPlaylistPrivacy } from '../../../../shared/models/videos'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 28
29describe('Test AP refresher', function () { 29describe('Test AP refresher', function () {
30 let servers: ServerInfo[] = [] 30 let servers: ServerInfo[] = []
@@ -116,19 +116,21 @@ describe('Test AP refresher', function () {
116 it('Should remove a deleted actor', async function () { 116 it('Should remove a deleted actor', async function () {
117 this.timeout(60000) 117 this.timeout(60000)
118 118
119 const command = servers[0].accountsCommand
120
119 await wait(10000) 121 await wait(10000)
120 122
121 // Change actor name so the remote server returns a 404 123 // Change actor name so the remote server returns a 404
122 const to = 'http://localhost:' + servers[1].port + '/accounts/user2' 124 const to = 'http://localhost:' + servers[1].port + '/accounts/user2'
123 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto') 125 await setActorField(servers[1].internalServerNumber, to, 'preferredUsername', 'toto')
124 126
125 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port) 127 await command.get({ accountName: 'user1@localhost:' + servers[1].port })
126 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port) 128 await command.get({ accountName: 'user2@localhost:' + servers[1].port })
127 129
128 await waitJobs(servers) 130 await waitJobs(servers)
129 131
130 await getAccount(servers[0].url, 'user1@localhost:' + servers[1].port, HttpStatusCode.OK_200) 132 await command.get({ accountName: 'user1@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.OK_200 })
131 await getAccount(servers[0].url, 'user2@localhost:' + servers[1].port, HttpStatusCode.NOT_FOUND_404) 133 await command.get({ accountName: 'user2@localhost:' + servers[1].port, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
132 }) 134 })
133 }) 135 })
134 136
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts
index d1712cff6..45d440c47 100644
--- a/server/tests/api/check-params/accounts.ts
+++ b/server/tests/api/check-params/accounts.ts
@@ -1,15 +1,15 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4 4import { HttpStatusCode } from '@shared/core-utils'
5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
6import { 5import {
7 checkBadCountPagination, 6 checkBadCountPagination,
8 checkBadSortPagination, 7 checkBadSortPagination,
9 checkBadStartPagination 8 checkBadStartPagination,
10} from '../../../../shared/extra-utils/requests/check-api-params' 9 cleanupTests,
11import { getAccount } from '../../../../shared/extra-utils/users/accounts' 10 flushAndRunServer,
12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 11 ServerInfo
12} from '@shared/extra-utils'
13 13
14describe('Test accounts API validators', function () { 14describe('Test accounts API validators', function () {
15 const path = '/api/v1/accounts/' 15 const path = '/api/v1/accounts/'
@@ -38,8 +38,9 @@ describe('Test accounts API validators', function () {
38 }) 38 })
39 39
40 describe('When getting an account', function () { 40 describe('When getting an account', function () {
41
41 it('Should return 404 with a non existing name', async function () { 42 it('Should return 404 with a non existing name', async function () {
42 await getAccount(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404) 43 await server.accountsCommand.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
43 }) 44 })
44 }) 45 })
45 46
diff --git a/server/tests/api/moderation/abuses.ts b/server/tests/api/moderation/abuses.ts
index a9f5332ce..124833cf6 100644
--- a/server/tests/api/moderation/abuses.ts
+++ b/server/tests/api/moderation/abuses.ts
@@ -13,7 +13,6 @@ import {
13 doubleFollow, 13 doubleFollow,
14 flushAndRunMultipleServers, 14 flushAndRunMultipleServers,
15 generateUserAccessToken, 15 generateUserAccessToken,
16 getAccount,
17 getVideoCommentThreads, 16 getVideoCommentThreads,
18 getVideoIdFromUUID, 17 getVideoIdFromUUID,
19 getVideosList, 18 getVideosList,
@@ -606,10 +605,8 @@ describe('Test abuses', function () {
606 605
607 describe('Account abuses', function () { 606 describe('Account abuses', function () {
608 607
609 async function getAccountFromServer (url: string, name: string, server: ServerInfo) { 608 function getAccountFromServer (server: ServerInfo, targetName: string, targetServer: ServerInfo) {
610 const res = await getAccount(url, name + '@' + server.host) 609 return server.accountsCommand.get({ accountName: targetName + '@' + targetServer.host })
611
612 return res.body as Account
613 } 610 }
614 611
615 before(async function () { 612 before(async function () {
@@ -626,7 +623,7 @@ describe('Test abuses', function () {
626 it('Should report abuse on an account', async function () { 623 it('Should report abuse on an account', async function () {
627 this.timeout(15000) 624 this.timeout(15000)
628 625
629 const account = await getAccountFromServer(servers[0].url, 'user_1', servers[0]) 626 const account = await getAccountFromServer(servers[0], 'user_1', servers[0])
630 627
631 const reason = 'it is a bad account' 628 const reason = 'it is a bad account'
632 await commands[0].report({ accountId: account.id, reason }) 629 await commands[0].report({ accountId: account.id, reason })
@@ -664,7 +661,7 @@ describe('Test abuses', function () {
664 it('Should report abuse on a remote account', async function () { 661 it('Should report abuse on a remote account', async function () {
665 this.timeout(10000) 662 this.timeout(10000)
666 663
667 const account = await getAccountFromServer(servers[0].url, 'user_2', servers[1]) 664 const account = await getAccountFromServer(servers[0], 'user_2', servers[1])
668 665
669 const reason = 'it is a really bad account' 666 const reason = 'it is a really bad account'
670 await commands[0].report({ accountId: account.id, reason }) 667 await commands[0].report({ accountId: account.id, reason })
@@ -718,7 +715,7 @@ describe('Test abuses', function () {
718 it('Should keep the account abuse when deleting the account', async function () { 715 it('Should keep the account abuse when deleting the account', async function () {
719 this.timeout(10000) 716 this.timeout(10000)
720 717
721 const account = await getAccountFromServer(servers[1].url, 'user_2', servers[1]) 718 const account = await getAccountFromServer(servers[1], 'user_2', servers[1])
722 await removeUser(servers[1].url, account.userId, servers[1].accessToken) 719 await removeUser(servers[1].url, account.userId, servers[1].accessToken)
723 720
724 await waitJobs(servers) 721 await waitJobs(servers)
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 3e66e7517..e90640ad6 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -22,7 +22,6 @@ import {
22 cleanupTests, 22 cleanupTests,
23 createUser, 23 createUser,
24 generateUserAccessToken, 24 generateUserAccessToken,
25 getAccount,
26 getVideoCommentThreads, 25 getVideoCommentThreads,
27 getVideoIdFromUUID, 26 getVideoIdFromUUID,
28 immutableAssign, 27 immutableAssign,
@@ -157,8 +156,8 @@ describe('Test moderation notifications', function () {
157 156
158 await waitJobs(servers) 157 await waitJobs(servers)
159 158
160 const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) 159 const account = await servers[1].accountsCommand.get({ accountName: username + '@' + servers[0].host })
161 await servers[1].abusesCommand.report({ accountId: resAccount.body.id, reason: 'super reason' }) 160 await servers[1].abusesCommand.report({ accountId: account.id, reason: 'super reason' })
162 161
163 await waitJobs(servers) 162 await waitJobs(servers)
164 await checkNewAccountAbuseForModerators(baseParams, username, 'presence') 163 await checkNewAccountAbuseForModerators(baseParams, username, 'presence')
diff --git a/server/tests/api/server/follows.ts b/server/tests/api/server/follows.ts
index c8fcca02c..466932d63 100644
--- a/server/tests/api/server/follows.ts
+++ b/server/tests/api/server/follows.ts
@@ -242,16 +242,16 @@ describe('Test follows', function () {
242 }) 242 })
243 243
244 it('Should have the correct follows counts', async function () { 244 it('Should have the correct follows counts', async function () {
245 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) 245 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })
246 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) 246 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
247 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) 247 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
248 248
249 // Server 2 and 3 does not know server 1 follow another server (there was not a refresh) 249 // Server 2 and 3 does not know server 1 follow another server (there was not a refresh)
250 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) 250 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
251 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) 251 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
252 252
253 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) 253 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
254 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) 254 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
255 }) 255 })
256 256
257 it('Should unfollow server 3 on server 1', async function () { 257 it('Should unfollow server 3 on server 1', async function () {
@@ -283,14 +283,14 @@ describe('Test follows', function () {
283 }) 283 })
284 284
285 it('Should have the correct follows counts 2', async function () { 285 it('Should have the correct follows counts 2', async function () {
286 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 1) 286 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
287 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) 287 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
288 288
289 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) 289 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
290 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) 290 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
291 291
292 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 0) 292 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 0 })
293 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 0, 0) 293 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 0, following: 0 })
294 }) 294 })
295 295
296 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () { 296 it('Should upload a video on server 2 and 3 and propagate only the video of server 2', async function () {
@@ -404,15 +404,15 @@ describe('Test follows', function () {
404 }) 404 })
405 405
406 it('Should have the correct follows counts 3', async function () { 406 it('Should have the correct follows counts 3', async function () {
407 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[0].port, 0, 2) 407 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 2 })
408 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[1].port, 1, 0) 408 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
409 await expectAccountFollows(servers[0].url, 'peertube@localhost:' + servers[2].port, 1, 0) 409 await expectAccountFollows({ server: servers[0], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
410 410
411 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[0].port, 0, 1) 411 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
412 await expectAccountFollows(servers[1].url, 'peertube@localhost:' + servers[1].port, 1, 0) 412 await expectAccountFollows({ server: servers[1], handle: 'peertube@localhost:' + servers[1].port, followers: 1, following: 0 })
413 413
414 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[0].port, 0, 1) 414 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[0].port, followers: 0, following: 1 })
415 await expectAccountFollows(servers[2].url, 'peertube@localhost:' + servers[2].port, 1, 0) 415 await expectAccountFollows({ server: servers[2], handle: 'peertube@localhost:' + servers[2].port, followers: 1, following: 0 })
416 }) 416 })
417 417
418 it('Should have propagated videos', async function () { 418 it('Should have propagated videos', async function () {
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 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { Account } from '../../../../shared/models/actors' 4import * as chai from 'chai'
6import { 5import {
6 checkActorFilesWereRemoved,
7 checkTmpIsEmpty, 7 checkTmpIsEmpty,
8 checkVideoFilesWereRemoved, 8 checkVideoFilesWereRemoved,
9 cleanupTests, 9 cleanupTests,
@@ -11,17 +11,19 @@ import {
11 doubleFollow, 11 doubleFollow,
12 flushAndRunMultipleServers, 12 flushAndRunMultipleServers,
13 getAccountVideos, 13 getAccountVideos,
14 getMyUserInformation,
14 getVideoChannelsList, 15 getVideoChannelsList,
15 removeUser, 16 removeUser,
17 ServerInfo,
18 setAccessTokensToServers,
19 testImage,
20 updateMyAvatar,
16 updateMyUser, 21 updateMyUser,
17 userLogin 22 uploadVideo,
18} from '../../../../shared/extra-utils' 23 userLogin,
19import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' 24 waitJobs
20import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' 25} from '@shared/extra-utils'
21import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' 26import { User, VideoChannel } from '@shared/models'
22import { User } from '../../../../shared/models/users'
23import { VideoChannel } from '../../../../shared/models/videos'
24import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
25 27
26const expect = chai.expect 28const expect = chai.expect
27 29
@@ -133,13 +135,12 @@ describe('Test users with multiple servers', function () {
133 let createdAt: string | Date 135 let createdAt: string | Date
134 136
135 for (const server of servers) { 137 for (const server of servers) {
136 const resAccounts = await getAccountsList(server.url, '-createdAt') 138 const body = await server.accountsCommand.list({ sort: '-createdAt' })
137 139
138 const resList = resAccounts.body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port) as Account 140 const resList = body.data.find(a => a.name === 'root' && a.host === 'localhost:' + servers[0].port)
139 expect(resList).not.to.be.undefined 141 expect(resList).not.to.be.undefined
140 142
141 const resAccount = await getAccount(server.url, resList.name + '@' + resList.host) 143 const account = await server.accountsCommand.get({ accountName: resList.name + '@' + resList.host })
142 const account = resAccount.body as Account
143 144
144 if (!createdAt) createdAt = account.createdAt 145 if (!createdAt) createdAt = account.createdAt
145 146
@@ -193,9 +194,9 @@ describe('Test users with multiple servers', function () {
193 this.timeout(10_000) 194 this.timeout(10_000)
194 195
195 for (const server of servers) { 196 for (const server of servers) {
196 const resAccounts = await getAccountsList(server.url, '-createdAt') 197 const body = await server.accountsCommand.list({ sort: '-createdAt' })
197 198
198 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account 199 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
199 expect(accountDeleted).not.to.be.undefined 200 expect(accountDeleted).not.to.be.undefined
200 201
201 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) 202 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10)
@@ -210,9 +211,9 @@ describe('Test users with multiple servers', function () {
210 await waitJobs(servers) 211 await waitJobs(servers)
211 212
212 for (const server of servers) { 213 for (const server of servers) {
213 const resAccounts = await getAccountsList(server.url, '-createdAt') 214 const body = await server.accountsCommand.list({ sort: '-createdAt' })
214 215
215 const accountDeleted = resAccounts.body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port) as Account 216 const accountDeleted = body.data.find(a => a.name === 'user1' && a.host === 'localhost:' + servers[0].port)
216 expect(accountDeleted).to.be.undefined 217 expect(accountDeleted).to.be.undefined
217 218
218 const resVideoChannels = await getVideoChannelsList(server.url, 0, 10) 219 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 {
11 createUser, 11 createUser,
12 deleteMe, 12 deleteMe,
13 flushAndRunServer, 13 flushAndRunServer,
14 getAccountRatings,
15 getBlacklistedVideosList, 14 getBlacklistedVideosList,
16 getMyUserInformation, 15 getMyUserInformation,
17 getMyUserVideoQuotaUsed, 16 getMyUserVideoQuotaUsed,
@@ -194,25 +193,22 @@ describe('Test users', function () {
194 it('Should retrieve ratings list', async function () { 193 it('Should retrieve ratings list', async function () {
195 await rateVideo(server.url, accessToken, videoId, 'like') 194 await rateVideo(server.url, accessToken, videoId, 'like')
196 195
197 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) 196 const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
198 const ratings = res.body
199 197
200 expect(ratings.total).to.equal(1) 198 expect(body.total).to.equal(1)
201 expect(ratings.data[0].video.id).to.equal(videoId) 199 expect(body.data[0].video.id).to.equal(videoId)
202 expect(ratings.data[0].rating).to.equal('like') 200 expect(body.data[0].rating).to.equal('like')
203 }) 201 })
204 202
205 it('Should retrieve ratings list by rating type', async function () { 203 it('Should retrieve ratings list by rating type', async function () {
206 { 204 {
207 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') 205 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' })
208 const ratings = res.body 206 expect(body.data.length).to.equal(1)
209 expect(ratings.data.length).to.equal(1)
210 } 207 }
211 208
212 { 209 {
213 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') 210 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' })
214 const ratings = res.body 211 expect(body.data.length).to.equal(0)
215 expect(ratings.data.length).to.equal(0)
216 } 212 }
217 }) 213 })
218 }) 214 })