]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/helpers/request.ts
Don't display log tag filter for audit logs
[github/Chocobozzz/PeerTube.git] / server / tests / helpers / request.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
bfe2ef6b
C
2
3import 'mocha'
bfe2ef6b 4import { expect } from 'chai'
db4b15f2
C
5import { pathExists, remove } from 'fs-extra'
6import { join } from 'path'
59bbcced 7import { FIXTURE_URLS, root, wait } from '../../../shared/extra-utils'
db4b15f2 8import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
bfe2ef6b
C
9
10describe('Request helpers', function () {
11 const destPath1 = join(root(), 'test-output-1.txt')
12 const destPath2 = join(root(), 'test-output-2.txt')
13
14 it('Should throw an error when the bytes limit is exceeded for request', async function () {
15 try {
0305db28 16 await doRequest(FIXTURE_URLS.file4K, { bodyKBLimit: 3 })
bfe2ef6b
C
17 } catch {
18 return
19 }
20
21 throw new Error('No error thrown by do request')
22 })
23
24 it('Should throw an error when the bytes limit is exceeded for request and save file', async function () {
25 try {
0305db28 26 await doRequestAndSaveToFile(FIXTURE_URLS.file4K, destPath1, { bodyKBLimit: 3 })
bfe2ef6b
C
27 } catch {
28
29 await wait(500)
30 expect(await pathExists(destPath1)).to.be.false
31 return
32 }
33
34 throw new Error('No error thrown by do request and save to file')
35 })
36
37 it('Should succeed if the file is below the limit', async function () {
0305db28
JB
38 await doRequest(FIXTURE_URLS.file4K, { bodyKBLimit: 5 })
39 await doRequestAndSaveToFile(FIXTURE_URLS.file4K, destPath2, { bodyKBLimit: 5 })
bfe2ef6b
C
40
41 expect(await pathExists(destPath2)).to.be.true
42 })
43
44 after(async function () {
45 await remove(destPath1)
46 await remove(destPath2)
47 })
48})