]>
Commit | Line | Data |
---|---|---|
bfe2ef6b C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests' | |
5 | import { get4KFileUrl, root, wait } from '../../../shared/utils' | |
6 | import { join } from 'path' | |
7 | import { pathExists, remove } from 'fs-extra' | |
8 | import { expect } from 'chai' | |
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 { | |
16 | await doRequest({ uri: get4KFileUrl() }, 3) | |
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 { | |
26 | await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath1, 3) | |
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 () { | |
38 | await doRequest({ uri: get4KFileUrl() }, 5) | |
39 | await doRequestAndSaveToFile({ uri: get4KFileUrl() }, destPath2, 5) | |
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 | }) |