]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
bfe2ef6b C |
2 | |
3 | import 'mocha' | |
bfe2ef6b | 4 | import { expect } from 'chai' |
db4b15f2 C |
5 | import { pathExists, remove } from 'fs-extra' |
6 | import { join } from 'path' | |
7 | import { get4KFileUrl, root, wait } from '../../../shared/extra-utils' | |
8 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | |
bfe2ef6b C |
9 | |
10 | describe('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 { | |
db4b15f2 | 16 | await doRequest(get4KFileUrl(), { 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 { | |
db4b15f2 | 26 | await doRequestAndSaveToFile(get4KFileUrl(), 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 () { | |
db4b15f2 C |
38 | await doRequest(get4KFileUrl(), { bodyKBLimit: 5 }) |
39 | await doRequestAndSaveToFile(get4KFileUrl(), 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 | }) |