diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/check-params/config.ts | 3 | ||||
-rw-r--r-- | server/tests/api/check-params/users.ts | 56 | ||||
-rw-r--r-- | server/tests/api/server/config.ts | 5 | ||||
-rw-r--r-- | server/tests/utils/server/config.ts | 3 | ||||
-rw-r--r-- | server/tests/utils/users/users.ts | 6 |
5 files changed, 67 insertions, 6 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index b26dfa252..ecfb76d47 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts | |||
@@ -48,7 +48,8 @@ describe('Test config API validators', function () { | |||
48 | email: 'superadmin1@example.com' | 48 | email: 'superadmin1@example.com' |
49 | }, | 49 | }, |
50 | user: { | 50 | user: { |
51 | videoQuota: 5242881 | 51 | videoQuota: 5242881, |
52 | videoQuotaDaily: 318742 | ||
52 | }, | 53 | }, |
53 | transcoding: { | 54 | transcoding: { |
54 | enabled: true, | 55 | enabled: true, |
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index b3fb61f6c..8b2ed1b04 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts | |||
@@ -94,6 +94,7 @@ describe('Test users API validators', function () { | |||
94 | email: 'test@example.com', | 94 | email: 'test@example.com', |
95 | password: 'my super password', | 95 | password: 'my super password', |
96 | videoQuota: -1, | 96 | videoQuota: -1, |
97 | videoQuotaDaily: -1, | ||
97 | role: UserRole.USER | 98 | role: UserRole.USER |
98 | } | 99 | } |
99 | 100 | ||
@@ -173,12 +174,24 @@ describe('Test users API validators', function () { | |||
173 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 174 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
174 | }) | 175 | }) |
175 | 176 | ||
177 | it('Should fail without a videoQuotaDaily', async function () { | ||
178 | const fields = omit(baseCorrectParams, 'videoQuotaDaily') | ||
179 | |||
180 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
181 | }) | ||
182 | |||
176 | it('Should fail with an invalid videoQuota', async function () { | 183 | it('Should fail with an invalid videoQuota', async function () { |
177 | const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) | 184 | const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) |
178 | 185 | ||
179 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | 186 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
180 | }) | 187 | }) |
181 | 188 | ||
189 | it('Should fail with an invalid videoQuotaDaily', async function () { | ||
190 | const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) | ||
191 | |||
192 | await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | ||
193 | }) | ||
194 | |||
182 | it('Should fail without a user role', async function () { | 195 | it('Should fail without a user role', async function () { |
183 | const fields = omit(baseCorrectParams, 'role') | 196 | const fields = omit(baseCorrectParams, 'role') |
184 | 197 | ||
@@ -607,7 +620,7 @@ describe('Test users API validators', function () { | |||
607 | }) | 620 | }) |
608 | 621 | ||
609 | describe('When having a video quota', function () { | 622 | describe('When having a video quota', function () { |
610 | it('Should fail with a user having too many video', async function () { | 623 | it('Should fail with a user having too many videos', async function () { |
611 | await updateUser({ | 624 | await updateUser({ |
612 | url: server.url, | 625 | url: server.url, |
613 | userId: rootId, | 626 | userId: rootId, |
@@ -618,7 +631,7 @@ describe('Test users API validators', function () { | |||
618 | await uploadVideo(server.url, server.accessToken, {}, 403) | 631 | await uploadVideo(server.url, server.accessToken, {}, 403) |
619 | }) | 632 | }) |
620 | 633 | ||
621 | it('Should fail with a registered user having too many video', async function () { | 634 | it('Should fail with a registered user having too many videos', async function () { |
622 | this.timeout(30000) | 635 | this.timeout(30000) |
623 | 636 | ||
624 | const user = { | 637 | const user = { |
@@ -663,6 +676,45 @@ describe('Test users API validators', function () { | |||
663 | }) | 676 | }) |
664 | }) | 677 | }) |
665 | 678 | ||
679 | describe('When having a daily video quota', function () { | ||
680 | it('Should fail with a user having too many videos', async function () { | ||
681 | await updateUser({ | ||
682 | url: server.url, | ||
683 | userId: rootId, | ||
684 | accessToken: server.accessToken, | ||
685 | videoQuotaDaily: 42 | ||
686 | }) | ||
687 | |||
688 | await uploadVideo(server.url, server.accessToken, {}, 403) | ||
689 | }) | ||
690 | }) | ||
691 | |||
692 | describe('When having an absolute and daily video quota', function () { | ||
693 | it('Should fail if exceeding total quota', async function () { | ||
694 | await updateUser({ | ||
695 | url: server.url, | ||
696 | userId: rootId, | ||
697 | accessToken: server.accessToken, | ||
698 | videoQuota: 42, | ||
699 | videoQuotaDaily: 1024 * 1024 * 1024 | ||
700 | }) | ||
701 | |||
702 | await uploadVideo(server.url, server.accessToken, {}, 403) | ||
703 | }) | ||
704 | |||
705 | it('Should fail if exceeding daily quota', async function () { | ||
706 | await updateUser({ | ||
707 | url: server.url, | ||
708 | userId: rootId, | ||
709 | accessToken: server.accessToken, | ||
710 | videoQuota: 1024 * 1024 * 1024, | ||
711 | videoQuotaDaily: 42 | ||
712 | }) | ||
713 | |||
714 | await uploadVideo(server.url, server.accessToken, {}, 403) | ||
715 | }) | ||
716 | }) | ||
717 | |||
666 | describe('When asking a password reset', function () { | 718 | describe('When asking a password reset', function () { |
667 | const path = '/api/v1/users/ask-reset-password' | 719 | const path = '/api/v1/users/ask-reset-password' |
668 | 720 | ||
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts index f9805b6ea..8a5f27c34 100644 --- a/server/tests/api/server/config.ts +++ b/server/tests/api/server/config.ts | |||
@@ -37,6 +37,7 @@ function checkInitialConfig (data: CustomConfig) { | |||
37 | expect(data.signup.limit).to.equal(4) | 37 | expect(data.signup.limit).to.equal(4) |
38 | expect(data.admin.email).to.equal('admin1@example.com') | 38 | expect(data.admin.email).to.equal('admin1@example.com') |
39 | expect(data.user.videoQuota).to.equal(5242880) | 39 | expect(data.user.videoQuota).to.equal(5242880) |
40 | expect(data.user.videoQuotaDaily).to.equal(318742) | ||
40 | expect(data.transcoding.enabled).to.be.false | 41 | expect(data.transcoding.enabled).to.be.false |
41 | expect(data.transcoding.threads).to.equal(2) | 42 | expect(data.transcoding.threads).to.equal(2) |
42 | expect(data.transcoding.resolutions['240p']).to.be.true | 43 | expect(data.transcoding.resolutions['240p']).to.be.true |
@@ -65,6 +66,7 @@ function checkUpdatedConfig (data: CustomConfig) { | |||
65 | expect(data.signup.limit).to.equal(5) | 66 | expect(data.signup.limit).to.equal(5) |
66 | expect(data.admin.email).to.equal('superadmin1@example.com') | 67 | expect(data.admin.email).to.equal('superadmin1@example.com') |
67 | expect(data.user.videoQuota).to.equal(5242881) | 68 | expect(data.user.videoQuota).to.equal(5242881) |
69 | expect(data.user.videoQuotaDaily).to.equal(318742) | ||
68 | expect(data.transcoding.enabled).to.be.true | 70 | expect(data.transcoding.enabled).to.be.true |
69 | expect(data.transcoding.threads).to.equal(1) | 71 | expect(data.transcoding.threads).to.equal(1) |
70 | expect(data.transcoding.resolutions['240p']).to.be.false | 72 | expect(data.transcoding.resolutions['240p']).to.be.false |
@@ -152,7 +154,8 @@ describe('Test config', function () { | |||
152 | email: 'superadmin1@example.com' | 154 | email: 'superadmin1@example.com' |
153 | }, | 155 | }, |
154 | user: { | 156 | user: { |
155 | videoQuota: 5242881 | 157 | videoQuota: 5242881, |
158 | videoQuotaDaily: 318742 | ||
156 | }, | 159 | }, |
157 | transcoding: { | 160 | transcoding: { |
158 | enabled: true, | 161 | enabled: true, |
diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts index d6ac3ef8a..799c31ae5 100644 --- a/server/tests/utils/server/config.ts +++ b/server/tests/utils/server/config.ts | |||
@@ -80,7 +80,8 @@ function updateCustomSubConfig (url: string, token: string, newConfig: any) { | |||
80 | email: 'superadmin1@example.com' | 80 | email: 'superadmin1@example.com' |
81 | }, | 81 | }, |
82 | user: { | 82 | user: { |
83 | videoQuota: 5242881 | 83 | videoQuota: 5242881, |
84 | videoQuotaDaily: 318742 | ||
84 | }, | 85 | }, |
85 | transcoding: { | 86 | transcoding: { |
86 | enabled: true, | 87 | enabled: true, |
diff --git a/server/tests/utils/users/users.ts b/server/tests/utils/users/users.ts index f786de6e3..5dba34b69 100644 --- a/server/tests/utils/users/users.ts +++ b/server/tests/utils/users/users.ts | |||
@@ -10,6 +10,7 @@ function createUser ( | |||
10 | username: string, | 10 | username: string, |
11 | password: string, | 11 | password: string, |
12 | videoQuota = 1000000, | 12 | videoQuota = 1000000, |
13 | videoQuotaDaily = -1, | ||
13 | role: UserRole = UserRole.USER, | 14 | role: UserRole = UserRole.USER, |
14 | specialStatus = 200 | 15 | specialStatus = 200 |
15 | ) { | 16 | ) { |
@@ -19,7 +20,8 @@ function createUser ( | |||
19 | password, | 20 | password, |
20 | role, | 21 | role, |
21 | email: username + '@example.com', | 22 | email: username + '@example.com', |
22 | videoQuota | 23 | videoQuota, |
24 | videoQuotaDaily | ||
23 | } | 25 | } |
24 | 26 | ||
25 | return request(url) | 27 | return request(url) |
@@ -202,6 +204,7 @@ function updateUser (options: { | |||
202 | accessToken: string, | 204 | accessToken: string, |
203 | email?: string, | 205 | email?: string, |
204 | videoQuota?: number, | 206 | videoQuota?: number, |
207 | videoQuotaDaily?: number, | ||
205 | role?: UserRole | 208 | role?: UserRole |
206 | }) { | 209 | }) { |
207 | const path = '/api/v1/users/' + options.userId | 210 | const path = '/api/v1/users/' + options.userId |
@@ -209,6 +212,7 @@ function updateUser (options: { | |||
209 | const toSend = {} | 212 | const toSend = {} |
210 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email | 213 | if (options.email !== undefined && options.email !== null) toSend['email'] = options.email |
211 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota | 214 | if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota |
215 | if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily | ||
212 | if (options.role !== undefined && options.role !== null) toSend['role'] = options.role | 216 | if (options.role !== undefined && options.role !== null) toSend['role'] = options.role |
213 | 217 | ||
214 | return makePutBodyRequest({ | 218 | return makePutBodyRequest({ |