2020-01-31 09:56:52 -06:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2019-02-21 10:19:16 -06:00
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import { expect } from 'chai'
|
2021-03-08 07:24:11 -06:00
|
|
|
import { pathExists, remove } from 'fs-extra'
|
|
|
|
import { join } from 'path'
|
2021-07-16 03:19:16 -05:00
|
|
|
import { FIXTURE_URLS, root, wait } from '../../../shared/extra-utils'
|
2021-03-08 07:24:11 -06:00
|
|
|
import { doRequest, doRequestAndSaveToFile } from '../../helpers/requests'
|
2019-02-21 10:19:16 -06:00
|
|
|
|
|
|
|
describe('Request helpers', function () {
|
|
|
|
const destPath1 = join(root(), 'test-output-1.txt')
|
|
|
|
const destPath2 = join(root(), 'test-output-2.txt')
|
|
|
|
|
|
|
|
it('Should throw an error when the bytes limit is exceeded for request', async function () {
|
|
|
|
try {
|
2021-07-16 03:19:16 -05:00
|
|
|
await doRequest(FIXTURE_URLS.video4K, { bodyKBLimit: 3 })
|
2019-02-21 10:19:16 -06:00
|
|
|
} catch {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('No error thrown by do request')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should throw an error when the bytes limit is exceeded for request and save file', async function () {
|
|
|
|
try {
|
2021-07-16 03:19:16 -05:00
|
|
|
await doRequestAndSaveToFile(FIXTURE_URLS.video4K, destPath1, { bodyKBLimit: 3 })
|
2019-02-21 10:19:16 -06:00
|
|
|
} catch {
|
|
|
|
|
|
|
|
await wait(500)
|
|
|
|
expect(await pathExists(destPath1)).to.be.false
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new Error('No error thrown by do request and save to file')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should succeed if the file is below the limit', async function () {
|
2021-07-16 03:19:16 -05:00
|
|
|
await doRequest(FIXTURE_URLS.video4K, { bodyKBLimit: 5 })
|
|
|
|
await doRequestAndSaveToFile(FIXTURE_URLS.video4K, destPath2, { bodyKBLimit: 5 })
|
2019-02-21 10:19:16 -06:00
|
|
|
|
|
|
|
expect(await pathExists(destPath2)).to.be.true
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
await remove(destPath1)
|
|
|
|
await remove(destPath2)
|
|
|
|
})
|
|
|
|
})
|