aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/upload-quota.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 14:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch)
tree7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/api/check-params/upload-quota.ts
parentd0a0fa429d4651710ed951a3c11af0219e408964 (diff)
downloadPeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip
Introduce user command
Diffstat (limited to 'server/tests/api/check-params/upload-quota.ts')
-rw-r--r--server/tests/api/check-params/upload-quota.ts35
1 files changed, 9 insertions, 26 deletions
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index 3dc6cf2b4..d94dec624 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -3,17 +3,14 @@
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode, randomInt } from '@shared/core-utils' 5import { HttpStatusCode, randomInt } from '@shared/core-utils'
6import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models' 6import { VideoImportState, VideoPrivacy } from '@shared/models'
7import { 7import {
8 cleanupTests, 8 cleanupTests,
9 flushAndRunServer, 9 flushAndRunServer,
10 getMyUserInformation,
11 ImportsCommand, 10 ImportsCommand,
12 registerUser,
13 ServerInfo, 11 ServerInfo,
14 setAccessTokensToServers, 12 setAccessTokensToServers,
15 setDefaultVideoChannel, 13 setDefaultVideoChannel,
16 updateUser,
17 uploadVideo, 14 uploadVideo,
18 waitJobs 15 waitJobs
19} from '../../../../shared/extra-utils' 16} from '../../../../shared/extra-utils'
@@ -31,15 +28,10 @@ describe('Test upload quota', function () {
31 await setAccessTokensToServers([ server ]) 28 await setAccessTokensToServers([ server ])
32 await setDefaultVideoChannel([ server ]) 29 await setDefaultVideoChannel([ server ])
33 30
34 const res = await getMyUserInformation(server.url, server.accessToken) 31 const user = await server.usersCommand.getMyInfo()
35 rootId = (res.body as MyUser).id 32 rootId = user.id
36 33
37 await updateUser({ 34 await server.usersCommand.update({ userId: rootId, videoQuota: 42 })
38 url: server.url,
39 userId: rootId,
40 accessToken: server.accessToken,
41 videoQuota: 42
42 })
43 }) 35 })
44 36
45 describe('When having a video quota', function () { 37 describe('When having a video quota', function () {
@@ -48,7 +40,7 @@ describe('Test upload quota', function () {
48 this.timeout(30000) 40 this.timeout(30000)
49 41
50 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 42 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
51 await registerUser(server.url, user.username, user.password) 43 await server.usersCommand.register(user)
52 const userAccessToken = await server.loginCommand.getAccessToken(user) 44 const userAccessToken = await server.loginCommand.getAccessToken(user)
53 45
54 const videoAttributes = { fixture: 'video_short2.webm' } 46 const videoAttributes = { fixture: 'video_short2.webm' }
@@ -63,7 +55,7 @@ describe('Test upload quota', function () {
63 this.timeout(30000) 55 this.timeout(30000)
64 56
65 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 57 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
66 await registerUser(server.url, user.username, user.password) 58 await server.usersCommand.register(user)
67 const userAccessToken = await server.loginCommand.getAccessToken(user) 59 const userAccessToken = await server.loginCommand.getAccessToken(user)
68 60
69 const videoAttributes = { fixture: 'video_short2.webm' } 61 const videoAttributes = { fixture: 'video_short2.webm' }
@@ -103,12 +95,7 @@ describe('Test upload quota', function () {
103 describe('When having a daily video quota', function () { 95 describe('When having a daily video quota', function () {
104 96
105 it('Should fail with a user having too many videos daily', async function () { 97 it('Should fail with a user having too many videos daily', async function () {
106 await updateUser({ 98 await server.usersCommand.update({ userId: rootId, videoQuotaDaily: 42 })
107 url: server.url,
108 userId: rootId,
109 accessToken: server.accessToken,
110 videoQuotaDaily: 42
111 })
112 99
113 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 100 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
114 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 101 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
@@ -117,10 +104,8 @@ describe('Test upload quota', function () {
117 104
118 describe('When having an absolute and daily video quota', function () { 105 describe('When having an absolute and daily video quota', function () {
119 it('Should fail if exceeding total quota', async function () { 106 it('Should fail if exceeding total quota', async function () {
120 await updateUser({ 107 await server.usersCommand.update({
121 url: server.url,
122 userId: rootId, 108 userId: rootId,
123 accessToken: server.accessToken,
124 videoQuota: 42, 109 videoQuota: 42,
125 videoQuotaDaily: 1024 * 1024 * 1024 110 videoQuotaDaily: 1024 * 1024 * 1024
126 }) 111 })
@@ -130,10 +115,8 @@ describe('Test upload quota', function () {
130 }) 115 })
131 116
132 it('Should fail if exceeding daily quota', async function () { 117 it('Should fail if exceeding daily quota', async function () {
133 await updateUser({ 118 await server.usersCommand.update({
134 url: server.url,
135 userId: rootId, 119 userId: rootId,
136 accessToken: server.accessToken,
137 videoQuota: 1024 * 1024 * 1024, 120 videoQuota: 1024 * 1024 * 1024,
138 videoQuotaDaily: 42 121 videoQuotaDaily: 42
139 }) 122 })