diff options
author | Chocobozzz <me@florianbigard.com> | 2021-05-07 11:53:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-05-07 11:53:46 +0200 |
commit | a1bb73f9b591686b2ddfeb3291f305dae9f7fc6c (patch) | |
tree | 0386b60da767075a890d45d947a6805ca32fd742 | |
parent | bc4c9cc1d75d591c217d61ab22a107b7f1044c76 (diff) | |
download | PeerTube-a1bb73f9b591686b2ddfeb3291f305dae9f7fc6c.tar.gz PeerTube-a1bb73f9b591686b2ddfeb3291f305dae9f7fc6c.tar.zst PeerTube-a1bb73f9b591686b2ddfeb3291f305dae9f7fc6c.zip |
Refactor a little bit live tests
-rw-r--r-- | server/tests/api/live/live-constraints.ts | 70 | ||||
-rw-r--r-- | server/tests/api/live/live-permanent.ts | 21 | ||||
-rw-r--r-- | server/tests/api/live/live-save-replay.ts | 11 | ||||
-rw-r--r-- | shared/extra-utils/server/config.ts | 15 | ||||
-rw-r--r-- | shared/extra-utils/users/users.ts | 23 |
5 files changed, 60 insertions, 80 deletions
diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 5569e6066..cc635de33 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts | |||
@@ -2,15 +2,15 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { User, VideoDetails, VideoPrivacy } from '@shared/models' | 5 | import { VideoDetails, VideoPrivacy } from '@shared/models' |
6 | import { | 6 | import { |
7 | checkLiveCleanup, | 7 | checkLiveCleanup, |
8 | cleanupTests, | 8 | cleanupTests, |
9 | createLive, | 9 | createLive, |
10 | createUser, | ||
11 | doubleFollow, | 10 | doubleFollow, |
12 | flushAndRunMultipleServers, | 11 | flushAndRunMultipleServers, |
13 | getMyUserInformation, | 12 | generateUser, |
13 | getCustomConfigResolutions, | ||
14 | getVideo, | 14 | getVideo, |
15 | runAndTestFfmpegStreamError, | 15 | runAndTestFfmpegStreamError, |
16 | ServerInfo, | 16 | ServerInfo, |
@@ -18,7 +18,6 @@ import { | |||
18 | setDefaultVideoChannel, | 18 | setDefaultVideoChannel, |
19 | updateCustomSubConfig, | 19 | updateCustomSubConfig, |
20 | updateUser, | 20 | updateUser, |
21 | userLogin, | ||
22 | wait, | 21 | wait, |
23 | waitJobs, | 22 | waitJobs, |
24 | waitUntilLivePublished | 23 | waitUntilLivePublished |
@@ -62,6 +61,16 @@ describe('Test live constraints', function () { | |||
62 | } | 61 | } |
63 | } | 62 | } |
64 | 63 | ||
64 | function updateQuota (options: { total: number, daily: number }) { | ||
65 | return updateUser({ | ||
66 | url: servers[0].url, | ||
67 | accessToken: servers[0].accessToken, | ||
68 | userId, | ||
69 | videoQuota: options.total, | ||
70 | videoQuotaDaily: options.daily | ||
71 | }) | ||
72 | } | ||
73 | |||
65 | before(async function () { | 74 | before(async function () { |
66 | this.timeout(120000) | 75 | this.timeout(120000) |
67 | 76 | ||
@@ -82,27 +91,12 @@ describe('Test live constraints', function () { | |||
82 | }) | 91 | }) |
83 | 92 | ||
84 | { | 93 | { |
85 | const user = { username: 'user1', password: 'superpassword' } | 94 | const res = await generateUser(servers[0], 'user1') |
86 | const res = await createUser({ | 95 | userId = res.userId |
87 | url: servers[0].url, | 96 | userChannelId = res.userChannelId |
88 | accessToken: servers[0].accessToken, | 97 | userAccessToken = res.token |
89 | username: user.username, | 98 | |
90 | password: user.password | 99 | await updateQuota({ total: 1, daily: -1 }) |
91 | }) | ||
92 | userId = res.body.user.id | ||
93 | |||
94 | userAccessToken = await userLogin(servers[0], user) | ||
95 | |||
96 | const resMe = await getMyUserInformation(servers[0].url, userAccessToken) | ||
97 | userChannelId = (resMe.body as User).videoChannels[0].id | ||
98 | |||
99 | await updateUser({ | ||
100 | url: servers[0].url, | ||
101 | userId, | ||
102 | accessToken: servers[0].accessToken, | ||
103 | videoQuota: 1, | ||
104 | videoQuotaDaily: -1 | ||
105 | }) | ||
106 | } | 100 | } |
107 | 101 | ||
108 | // Server 1 and server 2 follow each other | 102 | // Server 1 and server 2 follow each other |
@@ -137,13 +131,7 @@ describe('Test live constraints', function () { | |||
137 | // Wait for user quota memoize cache invalidation | 131 | // Wait for user quota memoize cache invalidation |
138 | await wait(5000) | 132 | await wait(5000) |
139 | 133 | ||
140 | await updateUser({ | 134 | await updateQuota({ total: -1, daily: 1 }) |
141 | url: servers[0].url, | ||
142 | userId, | ||
143 | accessToken: servers[0].accessToken, | ||
144 | videoQuota: -1, | ||
145 | videoQuotaDaily: 1 | ||
146 | }) | ||
147 | 135 | ||
148 | const userVideoLiveoId = await createLiveWrapper(true) | 136 | const userVideoLiveoId = await createLiveWrapper(true) |
149 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) | 137 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) |
@@ -160,13 +148,7 @@ describe('Test live constraints', function () { | |||
160 | // Wait for user quota memoize cache invalidation | 148 | // Wait for user quota memoize cache invalidation |
161 | await wait(5000) | 149 | await wait(5000) |
162 | 150 | ||
163 | await updateUser({ | 151 | await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) |
164 | url: servers[0].url, | ||
165 | userId, | ||
166 | accessToken: servers[0].accessToken, | ||
167 | videoQuota: 10 * 1000 * 1000, | ||
168 | videoQuotaDaily: -1 | ||
169 | }) | ||
170 | 152 | ||
171 | const userVideoLiveoId = await createLiveWrapper(true) | 153 | const userVideoLiveoId = await createLiveWrapper(true) |
172 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) | 154 | await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) |
@@ -182,15 +164,7 @@ describe('Test live constraints', function () { | |||
182 | maxDuration: 1, | 164 | maxDuration: 1, |
183 | transcoding: { | 165 | transcoding: { |
184 | enabled: true, | 166 | enabled: true, |
185 | resolutions: { | 167 | resolutions: getCustomConfigResolutions(true) |
186 | '240p': true, | ||
187 | '360p': true, | ||
188 | '480p': true, | ||
189 | '720p': true, | ||
190 | '1080p': true, | ||
191 | '1440p': true, | ||
192 | '2160p': true | ||
193 | } | ||
194 | } | 168 | } |
195 | } | 169 | } |
196 | }) | 170 | }) |
diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index a5bda009f..d52e8c7e4 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts | |||
@@ -8,6 +8,7 @@ import { | |||
8 | createLive, | 8 | createLive, |
9 | doubleFollow, | 9 | doubleFollow, |
10 | flushAndRunMultipleServers, | 10 | flushAndRunMultipleServers, |
11 | getCustomConfigResolutions, | ||
11 | getLive, | 12 | getLive, |
12 | getPlaylistsCount, | 13 | getPlaylistsCount, |
13 | getVideo, | 14 | getVideo, |
@@ -69,15 +70,7 @@ describe('Permenant live', function () { | |||
69 | maxDuration: -1, | 70 | maxDuration: -1, |
70 | transcoding: { | 71 | transcoding: { |
71 | enabled: true, | 72 | enabled: true, |
72 | resolutions: { | 73 | resolutions: getCustomConfigResolutions(true) |
73 | '240p': true, | ||
74 | '360p': true, | ||
75 | '480p': true, | ||
76 | '720p': true, | ||
77 | '1080p': true, | ||
78 | '1440p': true, | ||
79 | '2160p': true | ||
80 | } | ||
81 | } | 74 | } |
82 | } | 75 | } |
83 | }) | 76 | }) |
@@ -159,15 +152,7 @@ describe('Permenant live', function () { | |||
159 | maxDuration: -1, | 152 | maxDuration: -1, |
160 | transcoding: { | 153 | transcoding: { |
161 | enabled: true, | 154 | enabled: true, |
162 | resolutions: { | 155 | resolutions: getCustomConfigResolutions(false) |
163 | '240p': false, | ||
164 | '360p': false, | ||
165 | '480p': false, | ||
166 | '720p': false, | ||
167 | '1080p': false, | ||
168 | '1440p': false, | ||
169 | '2160p': false | ||
170 | } | ||
171 | } | 156 | } |
172 | } | 157 | } |
173 | }) | 158 | }) |
diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 61c8e74dd..3d4736c8f 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts | |||
@@ -12,6 +12,7 @@ import { | |||
12 | createLive, | 12 | createLive, |
13 | doubleFollow, | 13 | doubleFollow, |
14 | flushAndRunMultipleServers, | 14 | flushAndRunMultipleServers, |
15 | getCustomConfigResolutions, | ||
15 | getVideo, | 16 | getVideo, |
16 | getVideosList, | 17 | getVideosList, |
17 | removeVideo, | 18 | removeVideo, |
@@ -108,15 +109,7 @@ describe('Save replay setting', function () { | |||
108 | maxDuration: -1, | 109 | maxDuration: -1, |
109 | transcoding: { | 110 | transcoding: { |
110 | enabled: false, | 111 | enabled: false, |
111 | resolutions: { | 112 | resolutions: getCustomConfigResolutions(true) |
112 | '240p': true, | ||
113 | '360p': true, | ||
114 | '480p': true, | ||
115 | '720p': true, | ||
116 | '1080p': true, | ||
117 | '1440p': true, | ||
118 | '2160p': true | ||
119 | } | ||
120 | } | 113 | } |
121 | } | 114 | } |
122 | }) | 115 | }) |
diff --git a/shared/extra-utils/server/config.ts b/shared/extra-utils/server/config.ts index 026a5e61c..b70110852 100644 --- a/shared/extra-utils/server/config.ts +++ b/shared/extra-utils/server/config.ts | |||
@@ -223,6 +223,18 @@ function updateCustomSubConfig (url: string, token: string, newConfig: DeepParti | |||
223 | return updateCustomConfig(url, token, updateParams) | 223 | return updateCustomConfig(url, token, updateParams) |
224 | } | 224 | } |
225 | 225 | ||
226 | function getCustomConfigResolutions (enabled: boolean) { | ||
227 | return { | ||
228 | '240p': enabled, | ||
229 | '360p': enabled, | ||
230 | '480p': enabled, | ||
231 | '720p': enabled, | ||
232 | '1080p': enabled, | ||
233 | '1440p': enabled, | ||
234 | '2160p': enabled | ||
235 | } | ||
236 | } | ||
237 | |||
226 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { | 238 | function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) { |
227 | const path = '/api/v1/config/custom' | 239 | const path = '/api/v1/config/custom' |
228 | 240 | ||
@@ -242,5 +254,6 @@ export { | |||
242 | updateCustomConfig, | 254 | updateCustomConfig, |
243 | getAbout, | 255 | getAbout, |
244 | deleteCustomConfig, | 256 | deleteCustomConfig, |
245 | updateCustomSubConfig | 257 | updateCustomSubConfig, |
258 | getCustomConfigResolutions | ||
246 | } | 259 | } |
diff --git a/shared/extra-utils/users/users.ts b/shared/extra-utils/users/users.ts index 6040dd9c0..0f15962ad 100644 --- a/shared/extra-utils/users/users.ts +++ b/shared/extra-utils/users/users.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { omit } from 'lodash' | 1 | import { omit } from 'lodash' |
2 | import * as request from 'supertest' | 2 | import * as request from 'supertest' |
3 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | import { UserUpdateMe } from '../../models/users' | 4 | import { UserUpdateMe } from '../../models/users' |
4 | import { UserAdminFlag } from '../../models/users/user-flag.model' | 5 | import { UserAdminFlag } from '../../models/users/user-flag.model' |
5 | import { UserRegister } from '../../models/users/user-register.model' | 6 | import { UserRegister } from '../../models/users/user-register.model' |
@@ -7,9 +8,8 @@ import { UserRole } from '../../models/users/user-role' | |||
7 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests' | 8 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests' |
8 | import { ServerInfo } from '../server/servers' | 9 | import { ServerInfo } from '../server/servers' |
9 | import { userLogin } from './login' | 10 | import { userLogin } from './login' |
10 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
11 | 11 | ||
12 | type CreateUserArgs = { | 12 | function createUser (parameters: { |
13 | url: string | 13 | url: string |
14 | accessToken: string | 14 | accessToken: string |
15 | username: string | 15 | username: string |
@@ -19,8 +19,7 @@ type CreateUserArgs = { | |||
19 | role?: UserRole | 19 | role?: UserRole |
20 | adminFlags?: UserAdminFlag | 20 | adminFlags?: UserAdminFlag |
21 | specialStatus?: number | 21 | specialStatus?: number |
22 | } | 22 | }) { |
23 | function createUser (parameters: CreateUserArgs) { | ||
24 | const { | 23 | const { |
25 | url, | 24 | url, |
26 | accessToken, | 25 | accessToken, |
@@ -52,6 +51,21 @@ function createUser (parameters: CreateUserArgs) { | |||
52 | .expect(specialStatus) | 51 | .expect(specialStatus) |
53 | } | 52 | } |
54 | 53 | ||
54 | async function generateUser (server: ServerInfo, username: string) { | ||
55 | const password = 'my super password' | ||
56 | const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | ||
57 | |||
58 | const token = await userLogin(server, { username, password }) | ||
59 | |||
60 | const resMe = await getMyUserInformation(server.url, token) | ||
61 | |||
62 | return { | ||
63 | token, | ||
64 | userId: resCreate.body.user.id, | ||
65 | userChannelId: resMe.body.videoChannels[0].id | ||
66 | } | ||
67 | } | ||
68 | |||
55 | async function generateUserAccessToken (server: ServerInfo, username: string) { | 69 | async function generateUserAccessToken (server: ServerInfo, username: string) { |
56 | const password = 'my super password' | 70 | const password = 'my super password' |
57 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | 71 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
@@ -393,6 +407,7 @@ export { | |||
393 | resetPassword, | 407 | resetPassword, |
394 | renewUserScopedTokens, | 408 | renewUserScopedTokens, |
395 | updateMyAvatar, | 409 | updateMyAvatar, |
410 | generateUser, | ||
396 | askSendVerifyEmail, | 411 | askSendVerifyEmail, |
397 | generateUserAccessToken, | 412 | generateUserAccessToken, |
398 | verifyEmail, | 413 | verifyEmail, |