diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-07 13:38:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | 9fff08cf83f34339df7ed4ac770e1dee536adf9d (patch) | |
tree | 36eac5147a12ae257a3e8aaeffae37c9aed23d0a | |
parent | 87e2635a50ac2decb1c330e55c2ff7b6d07a85de (diff) | |
download | PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.gz PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.tar.zst PeerTube-9fff08cf83f34339df7ed4ac770e1dee536adf9d.zip |
Introduce accounts command
-rw-r--r-- | server/tests/api/activitypub/refresher.ts | 20 | ||||
-rw-r--r-- | server/tests/api/check-params/accounts.ts | 15 | ||||
-rw-r--r-- | server/tests/api/moderation/abuses.ts | 13 | ||||
-rw-r--r-- | server/tests/api/notifications/moderation-notifications.ts | 5 | ||||
-rw-r--r-- | server/tests/api/server/follows.ts | 40 | ||||
-rw-r--r-- | server/tests/api/users/users-multiple-servers.ts | 37 | ||||
-rw-r--r-- | server/tests/api/users/users.ts | 20 | ||||
-rw-r--r-- | server/tests/cli/prune-storage.ts | 17 | ||||
-rw-r--r-- | server/tests/cli/update-host.ts | 18 | ||||
-rw-r--r-- | server/tests/client.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/index.ts | 8 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/users/accounts-command.ts | 54 | ||||
-rw-r--r-- | shared/extra-utils/users/accounts.ts | 83 | ||||
-rw-r--r-- | shared/extra-utils/users/index.ts | 8 |
15 files changed, 175 insertions, 170 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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { HttpStatusCode } from '@shared/core-utils' | ||
4 | import { | 5 | import { |
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' |
25 | import { getAccount } from '../../../../shared/extra-utils/users/accounts' | 27 | import { VideoPlaylistPrivacy } from '@shared/models' |
26 | import { VideoPlaylistPrivacy } from '../../../../shared/models/videos' | ||
27 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | ||
28 | 28 | ||
29 | describe('Test AP refresher', function () { | 29 | describe('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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | 4 | import { HttpStatusCode } from '@shared/core-utils' | |
5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils' | ||
6 | import { | 5 | import { |
7 | checkBadCountPagination, | 6 | checkBadCountPagination, |
8 | checkBadSortPagination, | 7 | checkBadSortPagination, |
9 | checkBadStartPagination | 8 | checkBadStartPagination, |
10 | } from '../../../../shared/extra-utils/requests/check-api-params' | 9 | cleanupTests, |
11 | import { getAccount } from '../../../../shared/extra-utils/users/accounts' | 10 | flushAndRunServer, |
12 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 11 | ServerInfo |
12 | } from '@shared/extra-utils' | ||
13 | 13 | ||
14 | describe('Test accounts API validators', function () { | 14 | describe('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 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | import { Account } from '../../../../shared/models/actors' | 4 | import * as chai from 'chai' |
6 | import { | 5 | import { |
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, |
19 | import { getMyUserInformation, ServerInfo, testImage, updateMyAvatar, uploadVideo } from '../../../../shared/extra-utils/index' | 24 | waitJobs |
20 | import { checkActorFilesWereRemoved, getAccount, getAccountsList } from '../../../../shared/extra-utils/users/accounts' | 25 | } from '@shared/extra-utils' |
21 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | 26 | import { User, VideoChannel } from '@shared/models' |
22 | import { User } from '../../../../shared/models/users' | ||
23 | import { VideoChannel } from '../../../../shared/models/videos' | ||
24 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
25 | 27 | ||
26 | const expect = chai.expect | 28 | const 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 | }) |
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts index 81f91105c..95f573e50 100644 --- a/server/tests/cli/prune-storage.ts +++ b/server/tests/cli/prune-storage.ts | |||
@@ -5,7 +5,7 @@ import * as chai from 'chai' | |||
5 | import { createFile, readdir } from 'fs-extra' | 5 | import { createFile, readdir } from 'fs-extra' |
6 | import { join } from 'path' | 6 | import { join } from 'path' |
7 | import { buildUUID } from '@server/helpers/uuid' | 7 | import { buildUUID } from '@server/helpers/uuid' |
8 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 8 | import { HttpStatusCode } from '@shared/core-utils' |
9 | import { | 9 | import { |
10 | buildServerDirectory, | 10 | buildServerDirectory, |
11 | cleanupTests, | 11 | cleanupTests, |
@@ -13,7 +13,6 @@ import { | |||
13 | createVideoPlaylist, | 13 | createVideoPlaylist, |
14 | doubleFollow, | 14 | doubleFollow, |
15 | flushAndRunMultipleServers, | 15 | flushAndRunMultipleServers, |
16 | getAccount, | ||
17 | killallServers, | 16 | killallServers, |
18 | makeGetRequest, | 17 | makeGetRequest, |
19 | ServerInfo, | 18 | ServerInfo, |
@@ -21,10 +20,10 @@ import { | |||
21 | setDefaultVideoChannel, | 20 | setDefaultVideoChannel, |
22 | updateMyAvatar, | 21 | updateMyAvatar, |
23 | uploadVideo, | 22 | uploadVideo, |
24 | wait | 23 | wait, |
25 | } from '../../../shared/extra-utils' | 24 | waitJobs |
26 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | 25 | } from '@shared/extra-utils' |
27 | import { Account, VideoPlaylistPrivacy } from '../../../shared/models' | 26 | import { VideoPlaylistPrivacy } from '@shared/models' |
28 | 27 | ||
29 | const expect = chai.expect | 28 | const expect = chai.expect |
30 | 29 | ||
@@ -94,8 +93,7 @@ describe('Test prune storage scripts', function () { | |||
94 | 93 | ||
95 | // Lazy load the remote avatar | 94 | // Lazy load the remote avatar |
96 | { | 95 | { |
97 | const res = await getAccount(servers[0].url, 'root@localhost:' + servers[1].port) | 96 | const account = await servers[0].accountsCommand.get({ accountName: 'root@localhost:' + servers[1].port }) |
98 | const account: Account = res.body | ||
99 | await makeGetRequest({ | 97 | await makeGetRequest({ |
100 | url: servers[0].url, | 98 | url: servers[0].url, |
101 | path: account.avatar.path, | 99 | path: account.avatar.path, |
@@ -104,8 +102,7 @@ describe('Test prune storage scripts', function () { | |||
104 | } | 102 | } |
105 | 103 | ||
106 | { | 104 | { |
107 | const res = await getAccount(servers[1].url, 'root@localhost:' + servers[0].port) | 105 | const account = await servers[1].accountsCommand.get({ accountName: 'root@localhost:' + servers[0].port }) |
108 | const account: Account = res.body | ||
109 | await makeGetRequest({ | 106 | await makeGetRequest({ |
110 | url: servers[1].url, | 107 | url: servers[1].url, |
111 | path: account.avatar.path, | 108 | path: account.avatar.path, |
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts index 1b1a76aef..f6131a99f 100644 --- a/server/tests/cli/update-host.ts +++ b/server/tests/cli/update-host.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 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | ||
5 | import { | 4 | import { |
6 | addVideoChannel, | 5 | addVideoChannel, |
6 | addVideoCommentThread, | ||
7 | cleanupTests, | 7 | cleanupTests, |
8 | createUser, | 8 | createUser, |
9 | flushAndRunServer, | 9 | flushAndRunServer, |
@@ -16,12 +16,10 @@ import { | |||
16 | reRunServer, | 16 | reRunServer, |
17 | ServerInfo, | 17 | ServerInfo, |
18 | setAccessTokensToServers, | 18 | setAccessTokensToServers, |
19 | uploadVideo | 19 | uploadVideo, |
20 | } from '../../../shared/extra-utils' | 20 | waitJobs |
21 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | 21 | } from '@shared/extra-utils' |
22 | import { getAccountsList } from '../../../shared/extra-utils/users/accounts' | 22 | import { VideoDetails } from '@shared/models' |
23 | import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments' | ||
24 | import { VideoDetails } from '../../../shared/models/videos' | ||
25 | 23 | ||
26 | const expect = chai.expect | 24 | const expect = chai.expect |
27 | 25 | ||
@@ -104,10 +102,10 @@ describe('Test update host scripts', function () { | |||
104 | }) | 102 | }) |
105 | 103 | ||
106 | it('Should have updated accounts url', async function () { | 104 | it('Should have updated accounts url', async function () { |
107 | const res = await getAccountsList(server.url) | 105 | const body = await server.accountsCommand.list() |
108 | expect(res.body.total).to.equal(3) | 106 | expect(body.total).to.equal(3) |
109 | 107 | ||
110 | for (const account of res.body.data) { | 108 | for (const account of body.data) { |
111 | const usernameWithDomain = account.name | 109 | const usernameWithDomain = account.name |
112 | const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) | 110 | const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) |
113 | 111 | ||
diff --git a/server/tests/client.ts b/server/tests/client.ts index be7ce18b4..60df878d7 100644 --- a/server/tests/client.ts +++ b/server/tests/client.ts | |||
@@ -11,7 +11,6 @@ import { | |||
11 | createVideoPlaylist, | 11 | createVideoPlaylist, |
12 | doubleFollow, | 12 | doubleFollow, |
13 | flushAndRunMultipleServers, | 13 | flushAndRunMultipleServers, |
14 | getAccount, | ||
15 | getVideosList, | 14 | getVideosList, |
16 | makeGetRequest, | 15 | makeGetRequest, |
17 | makeHTMLRequest, | 16 | makeHTMLRequest, |
@@ -105,8 +104,7 @@ describe('Test a client controllers', function () { | |||
105 | 104 | ||
106 | await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' }) | 105 | await updateMyUser({ url: servers[0].url, accessToken: servers[0].accessToken, description: 'my account description' }) |
107 | 106 | ||
108 | const resAccountRequest = await getAccount(servers[0].url, `${servers[0].user.username}@${servers[0].host}`) | 107 | account = await servers[0].accountsCommand.get({ accountName: `${servers[0].user.username}@${servers[0].host}` }) |
109 | account = resAccountRequest.body | ||
110 | 108 | ||
111 | await waitJobs(servers) | 109 | await waitJobs(servers) |
112 | }) | 110 | }) |
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index ed7d7ab04..68900af26 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -10,17 +10,11 @@ export * from './overviews' | |||
10 | export * from './search' | 10 | export * from './search' |
11 | export * from './server' | 11 | export * from './server' |
12 | export * from './socket' | 12 | export * from './socket' |
13 | export * from './users' | ||
13 | 14 | ||
14 | export * from './requests/check-api-params' | 15 | export * from './requests/check-api-params' |
15 | export * from './requests/requests' | 16 | export * from './requests/requests' |
16 | 17 | ||
17 | export * from './users/accounts' | ||
18 | export * from './users/blocklist' | ||
19 | export * from './users/login' | ||
20 | export * from './users/user-notifications' | ||
21 | export * from './users/user-subscriptions' | ||
22 | export * from './users/users' | ||
23 | |||
24 | export * from './videos/live' | 18 | export * from './videos/live' |
25 | export * from './videos/services' | 19 | export * from './videos/services' |
26 | export * from './videos/video-blacklist' | 20 | export * from './videos/video-blacklist' |
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 8bd4446be..c2cab9818 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -17,6 +17,7 @@ import { OverviewsCommand } from '../overviews' | |||
17 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | 19 | import { SocketIOCommand } from '../socket' |
20 | import { AccountsCommand } from '../users' | ||
20 | import { ConfigCommand } from './config-command' | 21 | import { ConfigCommand } from './config-command' |
21 | import { ContactFormCommand } from './contact-form-command' | 22 | import { ContactFormCommand } from './contact-form-command' |
22 | import { DebugCommand } from './debug-command' | 23 | import { DebugCommand } from './debug-command' |
@@ -95,6 +96,7 @@ interface ServerInfo { | |||
95 | statsCommand?: StatsCommand | 96 | statsCommand?: StatsCommand |
96 | configCommand?: ConfigCommand | 97 | configCommand?: ConfigCommand |
97 | socketIOCommand?: SocketIOCommand | 98 | socketIOCommand?: SocketIOCommand |
99 | accountsCommand?: AccountsCommand | ||
98 | } | 100 | } |
99 | 101 | ||
100 | function parallelTests () { | 102 | function parallelTests () { |
@@ -317,6 +319,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
317 | server.statsCommand = new StatsCommand(server) | 319 | server.statsCommand = new StatsCommand(server) |
318 | server.configCommand = new ConfigCommand(server) | 320 | server.configCommand = new ConfigCommand(server) |
319 | server.socketIOCommand = new SocketIOCommand(server) | 321 | server.socketIOCommand = new SocketIOCommand(server) |
322 | server.accountsCommand = new AccountsCommand(server) | ||
320 | 323 | ||
321 | res(server) | 324 | res(server) |
322 | }) | 325 | }) |
diff --git a/shared/extra-utils/users/accounts-command.ts b/shared/extra-utils/users/accounts-command.ts new file mode 100644 index 000000000..89c080e93 --- /dev/null +++ b/shared/extra-utils/users/accounts-command.ts | |||
@@ -0,0 +1,54 @@ | |||
1 | import { ResultList } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { Account } from '../../models/actors' | ||
4 | import { AccountVideoRate, VideoRateType } from '../../models/videos' | ||
5 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
6 | |||
7 | export class AccountsCommand extends AbstractCommand { | ||
8 | |||
9 | list (options: OverrideCommandOptions & { | ||
10 | sort?: string // default -createdAt | ||
11 | } = {}) { | ||
12 | const { sort = '-createdAt' } = options | ||
13 | const path = '/api/v1/accounts' | ||
14 | |||
15 | return this.getRequestBody<ResultList<Account>>({ | ||
16 | ...options, | ||
17 | |||
18 | path, | ||
19 | query: { sort }, | ||
20 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
21 | }) | ||
22 | } | ||
23 | |||
24 | get (options: OverrideCommandOptions & { | ||
25 | accountName: string | ||
26 | }) { | ||
27 | const path = '/api/v1/accounts/' + options.accountName | ||
28 | |||
29 | return this.getRequestBody<Account>({ | ||
30 | ...options, | ||
31 | |||
32 | path, | ||
33 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
34 | }) | ||
35 | } | ||
36 | |||
37 | listRatings (options: OverrideCommandOptions & { | ||
38 | accountName: string | ||
39 | rating?: VideoRateType | ||
40 | }) { | ||
41 | const { rating, accountName } = options | ||
42 | const path = '/api/v1/accounts/' + accountName + '/ratings' | ||
43 | |||
44 | const query = { rating } | ||
45 | |||
46 | return this.getRequestBody<ResultList<AccountVideoRate>>({ | ||
47 | ...options, | ||
48 | |||
49 | path, | ||
50 | query, | ||
51 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
52 | }) | ||
53 | } | ||
54 | } | ||
diff --git a/shared/extra-utils/users/accounts.ts b/shared/extra-utils/users/accounts.ts index 4ea7f1402..ee94351e8 100644 --- a/shared/extra-utils/users/accounts.ts +++ b/shared/extra-utils/users/accounts.ts | |||
@@ -1,43 +1,25 @@ | |||
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 | ||
3 | import * as request from 'supertest' | ||
4 | import { expect } from 'chai' | 3 | import { expect } from 'chai' |
5 | import { existsSync, readdir } from 'fs-extra' | 4 | import { pathExists, readdir } from 'fs-extra' |
6 | import { join } from 'path' | 5 | import { join } from 'path' |
7 | import { Account } from '../../models/actors' | 6 | import { root } from '@server/helpers/core-utils' |
8 | import { root } from '../miscs/miscs' | 7 | import { ServerInfo } from '../server' |
9 | import { makeGetRequest } from '../requests/requests' | 8 | |
10 | import { VideoRateType } from '../../models/videos' | 9 | async function expectAccountFollows (options: { |
11 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | 10 | server: ServerInfo |
12 | 11 | handle: string | |
13 | function getAccountsList (url: string, sort = '-createdAt', statusCodeExpected = HttpStatusCode.OK_200) { | 12 | followers: number |
14 | const path = '/api/v1/accounts' | 13 | following: number |
15 | 14 | }) { | |
16 | return makeGetRequest({ | 15 | const { server, handle, followers, following } = options |
17 | url, | 16 | |
18 | query: { sort }, | 17 | const body = await server.accountsCommand.list() |
19 | path, | 18 | const account = body.data.find(a => a.name + '@' + a.host === handle) |
20 | statusCodeExpected | 19 | |
21 | }) | 20 | const message = `${handle} on ${server.url}` |
22 | } | 21 | expect(account.followersCount).to.equal(followers, message) |
23 | 22 | expect(account.followingCount).to.equal(following, message) | |
24 | function getAccount (url: string, accountName: string, statusCodeExpected = HttpStatusCode.OK_200) { | ||
25 | const path = '/api/v1/accounts/' + accountName | ||
26 | |||
27 | return makeGetRequest({ | ||
28 | url, | ||
29 | path, | ||
30 | statusCodeExpected | ||
31 | }) | ||
32 | } | ||
33 | |||
34 | async function expectAccountFollows (url: string, nameWithDomain: string, followersCount: number, followingCount: number) { | ||
35 | const res = await getAccountsList(url) | ||
36 | const account = res.body.data.find((a: Account) => a.name + '@' + a.host === nameWithDomain) | ||
37 | |||
38 | const message = `${nameWithDomain} on ${url}` | ||
39 | expect(account.followersCount).to.equal(followersCount, message) | ||
40 | expect(account.followingCount).to.equal(followingCount, message) | ||
41 | } | 23 | } |
42 | 24 | ||
43 | async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { | 25 | async function checkActorFilesWereRemoved (filename: string, serverNumber: number) { |
@@ -46,7 +28,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe | |||
46 | for (const directory of [ 'avatars' ]) { | 28 | for (const directory of [ 'avatars' ]) { |
47 | const directoryPath = join(root(), testDirectory, directory) | 29 | const directoryPath = join(root(), testDirectory, directory) |
48 | 30 | ||
49 | const directoryExists = existsSync(directoryPath) | 31 | const directoryExists = await pathExists(directoryPath) |
50 | expect(directoryExists).to.be.true | 32 | expect(directoryExists).to.be.true |
51 | 33 | ||
52 | const files = await readdir(directoryPath) | 34 | const files = await readdir(directoryPath) |
@@ -56,32 +38,7 @@ async function checkActorFilesWereRemoved (filename: string, serverNumber: numbe | |||
56 | } | 38 | } |
57 | } | 39 | } |
58 | 40 | ||
59 | function getAccountRatings ( | ||
60 | url: string, | ||
61 | accountName: string, | ||
62 | accessToken: string, | ||
63 | rating?: VideoRateType, | ||
64 | statusCodeExpected = HttpStatusCode.OK_200 | ||
65 | ) { | ||
66 | const path = '/api/v1/accounts/' + accountName + '/ratings' | ||
67 | |||
68 | const query = rating ? { rating } : {} | ||
69 | |||
70 | return request(url) | ||
71 | .get(path) | ||
72 | .query(query) | ||
73 | .set('Accept', 'application/json') | ||
74 | .set('Authorization', 'Bearer ' + accessToken) | ||
75 | .expect(statusCodeExpected) | ||
76 | .expect('Content-Type', /json/) | ||
77 | } | ||
78 | |||
79 | // --------------------------------------------------------------------------- | ||
80 | |||
81 | export { | 41 | export { |
82 | getAccount, | ||
83 | expectAccountFollows, | 42 | expectAccountFollows, |
84 | getAccountsList, | 43 | checkActorFilesWereRemoved |
85 | checkActorFilesWereRemoved, | ||
86 | getAccountRatings | ||
87 | } | 44 | } |
diff --git a/shared/extra-utils/users/index.ts b/shared/extra-utils/users/index.ts new file mode 100644 index 000000000..b3387ed8a --- /dev/null +++ b/shared/extra-utils/users/index.ts | |||
@@ -0,0 +1,8 @@ | |||
1 | export * from './accounts' | ||
2 | export * from './accounts-command' | ||
3 | |||
4 | export * from './blocklist' | ||
5 | export * from './login' | ||
6 | export * from './user-notifications' | ||
7 | export * from './user-subscriptions' | ||
8 | export * from './users' | ||