diff options
Diffstat (limited to 'server/tests')
-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 |
3 files changed, 52 insertions, 63 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 | ||