PeerTube/shared/extra-utils/requests/check-api-params.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-12-28 07:29:57 -06:00
import { makeGetRequest } from './requests'
2018-11-19 10:08:18 -06:00
import { immutableAssign } from '../miscs/miscs'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
2017-12-28 07:29:57 -06:00
2018-07-20 07:35:18 -05:00
function checkBadStartPagination (url: string, path: string, token?: string, query = {}) {
2017-12-28 07:29:57 -06:00
return makeGetRequest({
url,
path,
2017-12-28 07:40:11 -06:00
token,
2018-07-20 07:35:18 -05:00
query: immutableAssign(query, { start: 'hello' }),
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
2017-12-28 07:29:57 -06:00
})
}
async function checkBadCountPagination (url: string, path: string, token?: string, query = {}) {
await makeGetRequest({
2017-12-28 07:29:57 -06:00
url,
path,
2017-12-28 07:40:11 -06:00
token,
2018-07-20 07:35:18 -05:00
query: immutableAssign(query, { count: 'hello' }),
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
2017-12-28 07:29:57 -06:00
})
await makeGetRequest({
url,
path,
token,
query: immutableAssign(query, { count: 2000 }),
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
})
2017-12-28 07:29:57 -06:00
}
2018-07-20 07:35:18 -05:00
function checkBadSortPagination (url: string, path: string, token?: string, query = {}) {
2017-12-28 07:29:57 -06:00
return makeGetRequest({
url,
path,
2017-12-28 07:40:11 -06:00
token,
2018-07-20 07:35:18 -05:00
query: immutableAssign(query, { sort: 'hello' }),
statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
2017-12-28 07:29:57 -06:00
})
}
// ---------------------------------------------------------------------------
export {
checkBadStartPagination,
checkBadCountPagination,
checkBadSortPagination
}