diff options
-rw-r--r-- | server/tests/api/check-params/videos-overviews.ts | 9 | ||||
-rw-r--r-- | server/tests/api/videos/video-nsfw.ts | 35 | ||||
-rw-r--r-- | server/tests/api/videos/videos-overview.ts | 71 | ||||
-rw-r--r-- | shared/extra-utils/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/overviews/index.ts | 1 | ||||
-rw-r--r-- | shared/extra-utils/overviews/overviews-command.ts | 25 | ||||
-rw-r--r-- | shared/extra-utils/overviews/overviews.ts | 34 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 3 | ||||
-rw-r--r-- | shared/extra-utils/shared/abstract-command.ts | 5 |
9 files changed, 86 insertions, 98 deletions
diff --git a/server/tests/api/check-params/videos-overviews.ts b/server/tests/api/check-params/videos-overviews.ts index 69d7fc471..44a936c9f 100644 --- a/server/tests/api/check-params/videos-overviews.ts +++ b/server/tests/api/check-params/videos-overviews.ts | |||
@@ -1,8 +1,7 @@ | |||
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 { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils' | 4 | import { cleanupTests, flushAndRunServer, ServerInfo } from '@shared/extra-utils' |
5 | import { getVideosOverview } from '@shared/extra-utils/overviews/overviews' | ||
6 | 5 | ||
7 | describe('Test videos overview', function () { | 6 | describe('Test videos overview', function () { |
8 | let server: ServerInfo | 7 | let server: ServerInfo |
@@ -18,12 +17,12 @@ describe('Test videos overview', function () { | |||
18 | describe('When getting videos overview', function () { | 17 | describe('When getting videos overview', function () { |
19 | 18 | ||
20 | it('Should fail with a bad pagination', async function () { | 19 | it('Should fail with a bad pagination', async function () { |
21 | await getVideosOverview(server.url, 0, 400) | 20 | await server.overviewsCommand.getVideos({ page: 0, expectedStatus: 400 }) |
22 | await getVideosOverview(server.url, 100, 400) | 21 | await server.overviewsCommand.getVideos({ page: 100, expectedStatus: 400 }) |
23 | }) | 22 | }) |
24 | 23 | ||
25 | it('Should succeed with a good pagination', async function () { | 24 | it('Should succeed with a good pagination', async function () { |
26 | await getVideosOverview(server.url, 1) | 25 | await server.overviewsCommand.getVideos({ page: 1 }) |
27 | }) | 26 | }) |
28 | }) | 27 | }) |
29 | 28 | ||
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index b16b484b9..6c98c9f12 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts | |||
@@ -1,34 +1,33 @@ | |||
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 { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' | 4 | import * as chai from 'chai' |
6 | import { userLogin } from '../../../../shared/extra-utils/users/login' | ||
7 | import { createUser } from '../../../../shared/extra-utils/users/users' | ||
8 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | ||
9 | import { | 5 | import { |
6 | cleanupTests, | ||
7 | createUser, | ||
10 | flushAndRunServer, | 8 | flushAndRunServer, |
11 | getAccountVideos, | 9 | getAccountVideos, |
12 | getConfig, | 10 | getConfig, |
13 | getCustomConfig, | 11 | getCustomConfig, |
14 | getMyUserInformation, | 12 | getMyUserInformation, |
13 | getMyVideos, | ||
15 | getVideoChannelVideos, | 14 | getVideoChannelVideos, |
15 | getVideosList, | ||
16 | getVideosListWithToken, | 16 | getVideosListWithToken, |
17 | searchVideo, | 17 | searchVideo, |
18 | searchVideoWithToken, | 18 | searchVideoWithToken, |
19 | ServerInfo, | ||
20 | setAccessTokensToServers, | ||
19 | updateCustomConfig, | 21 | updateCustomConfig, |
20 | updateMyUser | 22 | updateMyUser, |
21 | } from '../../../../shared/extra-utils' | 23 | uploadVideo, |
22 | import { ServerConfig, VideosOverview } from '../../../../shared/models' | 24 | userLogin |
23 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | 25 | } from '@shared/extra-utils' |
24 | import { User } from '../../../../shared/models/users' | 26 | import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' |
25 | import { getVideosOverview, getVideosOverviewWithToken } from '@shared/extra-utils/overviews/overviews' | ||
26 | 27 | ||
27 | const expect = chai.expect | 28 | const expect = chai.expect |
28 | 29 | ||
29 | function createOverviewRes (res: any) { | 30 | function createOverviewRes (overview: VideosOverview) { |
30 | const overview = res.body as VideosOverview | ||
31 | |||
32 | const videos = overview.categories[0].videos | 31 | const videos = overview.categories[0].videos |
33 | return { body: { data: videos, total: videos.length } } | 32 | return { body: { data: videos, total: videos.length } } |
34 | } | 33 | } |
@@ -57,7 +56,9 @@ describe('Test video NSFW policy', function () { | |||
57 | 56 | ||
58 | // Overviews do not support video filters | 57 | // Overviews do not support video filters |
59 | if (!hasQuery) { | 58 | if (!hasQuery) { |
60 | promises.push(getVideosOverviewWithToken(server.url, 1, token).then(res => createOverviewRes(res))) | 59 | const p = server.overviewsCommand.getVideos({ page: 1, token }) |
60 | .then(res => createOverviewRes(res)) | ||
61 | promises.push(p) | ||
61 | } | 62 | } |
62 | 63 | ||
63 | return Promise.all(promises) | 64 | return Promise.all(promises) |
@@ -72,7 +73,9 @@ describe('Test video NSFW policy', function () { | |||
72 | 73 | ||
73 | // Overviews do not support video filters | 74 | // Overviews do not support video filters |
74 | if (!hasQuery) { | 75 | if (!hasQuery) { |
75 | promises.push(getVideosOverview(server.url, 1).then(res => createOverviewRes(res))) | 76 | const p = server.overviewsCommand.getVideos({ page: 1 }) |
77 | .then(res => createOverviewRes(res)) | ||
78 | promises.push(p) | ||
76 | } | 79 | } |
77 | 80 | ||
78 | return Promise.all(promises) | 81 | return Promise.all(promises) |
diff --git a/server/tests/api/videos/videos-overview.ts b/server/tests/api/videos/videos-overview.ts index c266a1dc5..c8e3df4bd 100644 --- a/server/tests/api/videos/videos-overview.ts +++ b/server/tests/api/videos/videos-overview.ts | |||
@@ -2,8 +2,9 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | 5 | import { Response } from 'superagent' | |
6 | import { | 6 | import { |
7 | addAccountToAccountBlocklist, | ||
7 | cleanupTests, | 8 | cleanupTests, |
8 | flushAndRunServer, | 9 | flushAndRunServer, |
9 | generateUserAccessToken, | 10 | generateUserAccessToken, |
@@ -11,20 +12,15 @@ import { | |||
11 | setAccessTokensToServers, | 12 | setAccessTokensToServers, |
12 | uploadVideo, | 13 | uploadVideo, |
13 | wait | 14 | wait |
14 | } from '../../../../shared/extra-utils' | 15 | } from '@shared/extra-utils' |
15 | import { getVideosOverview, getVideosOverviewWithToken } from '../../../../shared/extra-utils/overviews/overviews' | 16 | import { VideosOverview } from '@shared/models' |
16 | import { VideosOverview } from '../../../../shared/models/overviews' | ||
17 | import { addAccountToAccountBlocklist } from '@shared/extra-utils/users/blocklist' | ||
18 | import { Response } from 'superagent' | ||
19 | 17 | ||
20 | const expect = chai.expect | 18 | const expect = chai.expect |
21 | 19 | ||
22 | describe('Test a videos overview', function () { | 20 | describe('Test a videos overview', function () { |
23 | let server: ServerInfo = null | 21 | let server: ServerInfo = null |
24 | 22 | ||
25 | function testOverviewCount (res: Response, expected: number) { | 23 | function testOverviewCount (overview: VideosOverview, expected: number) { |
26 | const overview: VideosOverview = res.body | ||
27 | |||
28 | expect(overview.tags).to.have.lengthOf(expected) | 24 | expect(overview.tags).to.have.lengthOf(expected) |
29 | expect(overview.categories).to.have.lengthOf(expected) | 25 | expect(overview.categories).to.have.lengthOf(expected) |
30 | expect(overview.channels).to.have.lengthOf(expected) | 26 | expect(overview.channels).to.have.lengthOf(expected) |
@@ -39,9 +35,9 @@ describe('Test a videos overview', function () { | |||
39 | }) | 35 | }) |
40 | 36 | ||
41 | it('Should send empty overview', async function () { | 37 | it('Should send empty overview', async function () { |
42 | const res = await getVideosOverview(server.url, 1) | 38 | const body = await server.overviewsCommand.getVideos({ page: 1 }) |
43 | 39 | ||
44 | testOverviewCount(res, 0) | 40 | testOverviewCount(body, 0) |
45 | }) | 41 | }) |
46 | 42 | ||
47 | it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { | 43 | it('Should upload 5 videos in a specific category, tag and channel but not include them in overview', async function () { |
@@ -55,34 +51,35 @@ describe('Test a videos overview', function () { | |||
55 | tags: [ 'coucou1', 'coucou2' ] | 51 | tags: [ 'coucou1', 'coucou2' ] |
56 | }) | 52 | }) |
57 | 53 | ||
58 | const res = await getVideosOverview(server.url, 1) | 54 | const body = await server.overviewsCommand.getVideos({ page: 1 }) |
59 | 55 | ||
60 | testOverviewCount(res, 0) | 56 | testOverviewCount(body, 0) |
61 | }) | 57 | }) |
62 | 58 | ||
63 | it('Should upload another video and include all videos in the overview', async function () { | 59 | it('Should upload another video and include all videos in the overview', async function () { |
64 | this.timeout(30000) | 60 | this.timeout(30000) |
65 | 61 | ||
66 | for (let i = 1; i < 6; i++) { | 62 | { |
67 | await uploadVideo(server.url, server.accessToken, { | 63 | for (let i = 1; i < 6; i++) { |
68 | name: 'video ' + i, | 64 | await uploadVideo(server.url, server.accessToken, { |
69 | category: 3, | 65 | name: 'video ' + i, |
70 | tags: [ 'coucou1', 'coucou2' ] | 66 | category: 3, |
71 | }) | 67 | tags: [ 'coucou1', 'coucou2' ] |
68 | }) | ||
69 | } | ||
70 | |||
71 | await wait(3000) | ||
72 | } | 72 | } |
73 | 73 | ||
74 | await wait(3000) | ||
75 | |||
76 | { | 74 | { |
77 | const res = await getVideosOverview(server.url, 1) | 75 | const body = await server.overviewsCommand.getVideos({ page: 1 }) |
78 | 76 | ||
79 | testOverviewCount(res, 1) | 77 | testOverviewCount(body, 1) |
80 | } | 78 | } |
81 | 79 | ||
82 | { | 80 | { |
83 | const res = await getVideosOverview(server.url, 2) | 81 | const overview = await server.overviewsCommand.getVideos({ page: 2 }) |
84 | 82 | ||
85 | const overview: VideosOverview = res.body | ||
86 | expect(overview.tags).to.have.lengthOf(1) | 83 | expect(overview.tags).to.have.lengthOf(1) |
87 | expect(overview.categories).to.have.lengthOf(0) | 84 | expect(overview.categories).to.have.lengthOf(0) |
88 | expect(overview.channels).to.have.lengthOf(0) | 85 | expect(overview.channels).to.have.lengthOf(0) |
@@ -90,20 +87,10 @@ describe('Test a videos overview', function () { | |||
90 | }) | 87 | }) |
91 | 88 | ||
92 | it('Should have the correct overview', async function () { | 89 | it('Should have the correct overview', async function () { |
93 | const res1 = await getVideosOverview(server.url, 1) | 90 | const overview1 = await server.overviewsCommand.getVideos({ page: 1 }) |
94 | const res2 = await getVideosOverview(server.url, 2) | 91 | const overview2 = await server.overviewsCommand.getVideos({ page: 2 }) |
95 | |||
96 | const overview1: VideosOverview = res1.body | ||
97 | const overview2: VideosOverview = res2.body | ||
98 | |||
99 | const tmp = [ | ||
100 | overview1.tags, | ||
101 | overview1.categories, | ||
102 | overview1.channels, | ||
103 | overview2.tags | ||
104 | ] | ||
105 | 92 | ||
106 | for (const arr of tmp) { | 93 | for (const arr of [ overview1.tags, overview1.categories, overview1.channels, overview2.tags ]) { |
107 | expect(arr).to.have.lengthOf(1) | 94 | expect(arr).to.have.lengthOf(1) |
108 | 95 | ||
109 | const obj = arr[0] | 96 | const obj = arr[0] |
@@ -132,15 +119,15 @@ describe('Test a videos overview', function () { | |||
132 | await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) | 119 | await addAccountToAccountBlocklist(server.url, token, 'root@' + server.host) |
133 | 120 | ||
134 | { | 121 | { |
135 | const res = await getVideosOverview(server.url, 1) | 122 | const body = await server.overviewsCommand.getVideos({ page: 1 }) |
136 | 123 | ||
137 | testOverviewCount(res, 1) | 124 | testOverviewCount(body, 1) |
138 | } | 125 | } |
139 | 126 | ||
140 | { | 127 | { |
141 | const res = await getVideosOverviewWithToken(server.url, 1, token) | 128 | const body = await server.overviewsCommand.getVideos({ page: 1, token }) |
142 | 129 | ||
143 | testOverviewCount(res, 0) | 130 | testOverviewCount(body, 0) |
144 | } | 131 | } |
145 | }) | 132 | }) |
146 | 133 | ||
diff --git a/shared/extra-utils/index.ts b/shared/extra-utils/index.ts index 7ca079c78..38c8c4c1c 100644 --- a/shared/extra-utils/index.ts +++ b/shared/extra-utils/index.ts | |||
@@ -6,6 +6,7 @@ export * from './logs' | |||
6 | export * from './miscs' | 6 | export * from './miscs' |
7 | export * from './mock-servers' | 7 | export * from './mock-servers' |
8 | export * from './moderation' | 8 | export * from './moderation' |
9 | export * from './overviews' | ||
9 | 10 | ||
10 | export * from './requests/check-api-params' | 11 | export * from './requests/check-api-params' |
11 | export * from './requests/requests' | 12 | export * from './requests/requests' |
diff --git a/shared/extra-utils/overviews/index.ts b/shared/extra-utils/overviews/index.ts new file mode 100644 index 000000000..e19551907 --- /dev/null +++ b/shared/extra-utils/overviews/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './overviews-command' | |||
diff --git a/shared/extra-utils/overviews/overviews-command.ts b/shared/extra-utils/overviews/overviews-command.ts new file mode 100644 index 000000000..0ac3cbd33 --- /dev/null +++ b/shared/extra-utils/overviews/overviews-command.ts | |||
@@ -0,0 +1,25 @@ | |||
1 | import { HttpStatusCode } from '@shared/core-utils' | ||
2 | import { VideosOverview } from '@shared/models' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class OverviewsCommand extends AbstractCommand { | ||
6 | |||
7 | getVideos (options: OverrideCommandOptions & { | ||
8 | page: number | ||
9 | token?: string | ||
10 | }) { | ||
11 | const { token, page } = options | ||
12 | const path = '/api/v1/overviews/videos' | ||
13 | |||
14 | const query = { page } | ||
15 | |||
16 | return this.getRequestBody<VideosOverview>({ | ||
17 | ...options, | ||
18 | |||
19 | token: token || null, | ||
20 | path, | ||
21 | query, | ||
22 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
23 | }) | ||
24 | } | ||
25 | } | ||
diff --git a/shared/extra-utils/overviews/overviews.ts b/shared/extra-utils/overviews/overviews.ts deleted file mode 100644 index 5e1a13e5e..000000000 --- a/shared/extra-utils/overviews/overviews.ts +++ /dev/null | |||
@@ -1,34 +0,0 @@ | |||
1 | import { makeGetRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function getVideosOverview (url: string, page: number, statusCodeExpected = HttpStatusCode.OK_200) { | ||
5 | const path = '/api/v1/overviews/videos' | ||
6 | |||
7 | const query = { page } | ||
8 | |||
9 | return makeGetRequest({ | ||
10 | url, | ||
11 | path, | ||
12 | query, | ||
13 | statusCodeExpected | ||
14 | }) | ||
15 | } | ||
16 | |||
17 | function getVideosOverviewWithToken (url: string, page: number, token: string, statusCodeExpected = HttpStatusCode.OK_200) { | ||
18 | const path = '/api/v1/overviews/videos' | ||
19 | |||
20 | const query = { page } | ||
21 | |||
22 | return makeGetRequest({ | ||
23 | url, | ||
24 | path, | ||
25 | query, | ||
26 | token, | ||
27 | statusCodeExpected | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | export { | ||
32 | getVideosOverview, | ||
33 | getVideosOverviewWithToken | ||
34 | } | ||
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index f05f0dbbe..70be96cf6 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -13,6 +13,7 @@ import { FeedCommand } from '../feeds' | |||
13 | import { LogsCommand } from '../logs' | 13 | import { LogsCommand } from '../logs' |
14 | import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' | 14 | import { buildServerDirectory, getFileSize, isGithubCI, root, wait } from '../miscs/miscs' |
15 | import { AbusesCommand } from '../moderation' | 15 | import { AbusesCommand } from '../moderation' |
16 | import { OverviewsCommand } from '../overviews' | ||
16 | import { makeGetRequest } from '../requests/requests' | 17 | import { makeGetRequest } from '../requests/requests' |
17 | 18 | ||
18 | interface ServerInfo { | 19 | interface ServerInfo { |
@@ -73,6 +74,7 @@ interface ServerInfo { | |||
73 | feedCommand?: FeedCommand | 74 | feedCommand?: FeedCommand |
74 | logsCommand?: LogsCommand | 75 | logsCommand?: LogsCommand |
75 | abusesCommand?: AbusesCommand | 76 | abusesCommand?: AbusesCommand |
77 | overviewsCommand?: OverviewsCommand | ||
76 | } | 78 | } |
77 | 79 | ||
78 | function parallelTests () { | 80 | function parallelTests () { |
@@ -284,6 +286,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
284 | server.feedCommand = new FeedCommand(server) | 286 | server.feedCommand = new FeedCommand(server) |
285 | server.logsCommand = new LogsCommand(server) | 287 | server.logsCommand = new LogsCommand(server) |
286 | server.abusesCommand = new AbusesCommand(server) | 288 | server.abusesCommand = new AbusesCommand(server) |
289 | server.overviewsCommand = new OverviewsCommand(server) | ||
287 | 290 | ||
288 | res(server) | 291 | res(server) |
289 | }) | 292 | }) |
diff --git a/shared/extra-utils/shared/abstract-command.ts b/shared/extra-utils/shared/abstract-command.ts index 3ee5cd865..3815fab0e 100644 --- a/shared/extra-utils/shared/abstract-command.ts +++ b/shared/extra-utils/shared/abstract-command.ts | |||
@@ -78,7 +78,10 @@ abstract class AbstractCommand { | |||
78 | return { | 78 | return { |
79 | url: this.server.url, | 79 | url: this.server.url, |
80 | path, | 80 | path, |
81 | token: token ?? this.server.accessToken, | 81 | |
82 | // Token can be null if we don't want to add it | ||
83 | token: token !== undefined ? token : this.server.accessToken, | ||
84 | |||
82 | statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus | 85 | statusCodeExpected: expectedStatus ?? this.expectedStatus ?? defaultExpectedStatus |
83 | } | 86 | } |
84 | } | 87 | } |