X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fupload-quota.ts;h=06698c056c241a887d99bef86ca0b7ee95bc6717;hb=cffef25313bdf7a6c435f56ac6715fdd91acf7b3;hp=d0fbec4155ab0aa9e50b436303ec090b783d6fa2;hpb=8f608a4cb22ab232cfab20665050764b38bac9c7;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts index d0fbec415..06698c056 100644 --- a/server/tests/api/check-params/upload-quota.ts +++ b/server/tests/api/check-params/upload-quota.ts @@ -1,98 +1,89 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' import { expect } from 'chai' -import { HttpStatusCode, randomInt } from '@shared/core-utils' -import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports' -import { MyUser, VideoImport, VideoImportState, VideoPrivacy } from '@shared/models' +import { FIXTURE_URLS } from '@server/tests/shared' +import { randomInt } from '@shared/core-utils' +import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models' import { cleanupTests, - flushAndRunServer, - getMyUserInformation, - immutableAssign, - registerUser, - ServerInfo, + createSingleServer, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel, - updateUser, - uploadVideo, - userLogin, + VideosCommand, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/server-commands' describe('Test upload quota', function () { - let server: ServerInfo + let server: PeerTubeServer let rootId: number + let command: VideosCommand // --------------------------------------------------------------- before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) await setDefaultVideoChannel([ server ]) - const res = await getMyUserInformation(server.url, server.accessToken) - rootId = (res.body as MyUser).id + const user = await server.users.getMyInfo() + rootId = user.id - await updateUser({ - url: server.url, - userId: rootId, - accessToken: server.accessToken, - videoQuota: 42 - }) + await server.users.update({ userId: rootId, videoQuota: 42 }) + + command = server.videos }) describe('When having a video quota', function () { it('Should fail with a registered user having too many videos with legacy upload', async function () { - this.timeout(30000) + this.timeout(120000) const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } - await registerUser(server.url, user.username, user.password) - const userAccessToken = await userLogin(server, user) + await server.registrations.register(user) + const userToken = await server.login.getAccessToken(user) - const videoAttributes = { fixture: 'video_short2.webm' } + const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { - await uploadVideo(server.url, userAccessToken, videoAttributes) + await command.upload({ token: userToken, attributes }) } - await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') + await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) }) it('Should fail with a registered user having too many videos with resumable upload', async function () { - this.timeout(30000) + this.timeout(120000) const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } - await registerUser(server.url, user.username, user.password) - const userAccessToken = await userLogin(server, user) + await server.registrations.register(user) + const userToken = await server.login.getAccessToken(user) - const videoAttributes = { fixture: 'video_short2.webm' } + const attributes = { fixture: 'video_short2.webm' } for (let i = 0; i < 5; i++) { - await uploadVideo(server.url, userAccessToken, videoAttributes) + await command.upload({ token: userToken, attributes }) } - await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) it('Should fail to import with HTTP/Torrent/magnet', async function () { - this.timeout(120000) + this.timeout(120_000) const baseAttributes = { - channelId: server.videoChannel.id, + channelId: server.store.channel.id, privacy: VideoPrivacy.PUBLIC } - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) - await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) + await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } }) + await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } }) + await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } }) await waitJobs([ server ]) - const res = await getMyVideoImports(server.url, server.accessToken) + const { total, data: videoImports } = await server.imports.getMyVideoImports() + expect(total).to.equal(3) - expect(res.body.total).to.equal(3) - const videoImports: VideoImport[] = res.body.data expect(videoImports).to.have.lengthOf(3) for (const videoImport of videoImports) { @@ -106,43 +97,34 @@ describe('Test upload quota', function () { describe('When having a daily video quota', function () { it('Should fail with a user having too many videos daily', async function () { - await updateUser({ - url: server.url, - userId: rootId, - accessToken: server.accessToken, - videoQuotaDaily: 42 - }) + await server.users.update({ userId: rootId, videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) }) describe('When having an absolute and daily video quota', function () { it('Should fail if exceeding total quota', async function () { - await updateUser({ - url: server.url, + await server.users.update({ userId: rootId, - accessToken: server.accessToken, videoQuota: 42, videoQuotaDaily: 1024 * 1024 * 1024 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) it('Should fail if exceeding daily quota', async function () { - await updateUser({ - url: server.url, + await server.users.update({ userId: rootId, - accessToken: server.accessToken, videoQuota: 1024 * 1024 * 1024, videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') - await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' }) + await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' }) }) })