1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { HttpStatusCode, randomInt } from '@shared/core-utils'
6 import { MyUser, VideoImportState, VideoPrivacy } from '@shared/models'
14 setAccessTokensToServers,
15 setDefaultVideoChannel,
20 } from '../../../../shared/extra-utils'
22 describe('Test upload quota', function () {
23 let server: ServerInfo
26 // ---------------------------------------------------------------
28 before(async function () {
31 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
33 await setDefaultVideoChannel([ server ])
35 const res = await getMyUserInformation(server.url, server.accessToken)
36 rootId = (res.body as MyUser).id
41 accessToken: server.accessToken,
46 describe('When having a video quota', function () {
48 it('Should fail with a registered user having too many videos with legacy upload', async function () {
51 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
52 await registerUser(server.url, user.username, user.password)
53 const userAccessToken = await userLogin(server, user)
55 const videoAttributes = { fixture: 'video_short2.webm' }
56 for (let i = 0; i < 5; i++) {
57 await uploadVideo(server.url, userAccessToken, videoAttributes)
60 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
63 it('Should fail with a registered user having too many videos with resumable upload', async function () {
66 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
67 await registerUser(server.url, user.username, user.password)
68 const userAccessToken = await userLogin(server, user)
70 const videoAttributes = { fixture: 'video_short2.webm' }
71 for (let i = 0; i < 5; i++) {
72 await uploadVideo(server.url, userAccessToken, videoAttributes)
75 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
78 it('Should fail to import with HTTP/Torrent/magnet', async function () {
81 const baseAttributes = {
82 channelId: server.videoChannel.id,
83 privacy: VideoPrivacy.PUBLIC
85 await server.importsCommand.importVideo({ attributes: { ...baseAttributes, targetUrl: ImportsCommand.getGoodVideoUrl() } })
86 await server.importsCommand.importVideo({ attributes: { ...baseAttributes, magnetUri: ImportsCommand.getMagnetURI() } })
87 await server.importsCommand.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
89 await waitJobs([ server ])
91 const { total, data: videoImports } = await server.importsCommand.getMyVideoImports()
92 expect(total).to.equal(3)
94 expect(videoImports).to.have.lengthOf(3)
96 for (const videoImport of videoImports) {
97 expect(videoImport.state.id).to.equal(VideoImportState.FAILED)
98 expect(videoImport.error).not.to.be.undefined
99 expect(videoImport.error).to.contain('user video quota is exceeded')
104 describe('When having a daily video quota', function () {
106 it('Should fail with a user having too many videos daily', async function () {
110 accessToken: server.accessToken,
114 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
115 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
119 describe('When having an absolute and daily video quota', function () {
120 it('Should fail if exceeding total quota', async function () {
124 accessToken: server.accessToken,
126 videoQuotaDaily: 1024 * 1024 * 1024
129 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
130 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
133 it('Should fail if exceeding daily quota', async function () {
137 accessToken: server.accessToken,
138 videoQuota: 1024 * 1024 * 1024,
142 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy')
143 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable')
147 after(async function () {
148 await cleanupTests([ server ])