2017-09-22 03:13:43 -04:00
|
|
|
import * as request from 'supertest'
|
2019-04-15 04:49:46 -04:00
|
|
|
import { VideoBlacklistType } from '../../models/videos'
|
|
|
|
import { makeGetRequest } from '..'
|
2020-12-07 08:32:36 -05:00
|
|
|
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
2017-09-22 03:13:43 -04:00
|
|
|
|
2019-01-10 09:39:51 -05:00
|
|
|
function addVideoToBlacklist (
|
|
|
|
url: string,
|
|
|
|
token: string,
|
|
|
|
videoId: number | string,
|
|
|
|
reason?: string,
|
|
|
|
unfederate?: boolean,
|
2020-12-07 08:32:36 -05:00
|
|
|
specialStatus = HttpStatusCode.NO_CONTENT_204
|
2019-01-10 09:39:51 -05:00
|
|
|
) {
|
2017-09-22 03:13:43 -04:00
|
|
|
const path = '/api/v1/videos/' + videoId + '/blacklist'
|
|
|
|
|
|
|
|
return request(url)
|
2020-01-31 10:56:52 -05:00
|
|
|
.post(path)
|
|
|
|
.send({ reason, unfederate })
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.set('Authorization', 'Bearer ' + token)
|
|
|
|
.expect(specialStatus)
|
2017-09-22 03:13:43 -04:00
|
|
|
}
|
|
|
|
|
2020-12-07 08:32:36 -05:00
|
|
|
function updateVideoBlacklist (
|
|
|
|
url: string,
|
|
|
|
token: string,
|
|
|
|
videoId: number,
|
|
|
|
reason?: string,
|
|
|
|
specialStatus = HttpStatusCode.NO_CONTENT_204
|
|
|
|
) {
|
2018-08-13 10:57:13 -04:00
|
|
|
const path = '/api/v1/videos/' + videoId + '/blacklist'
|
|
|
|
|
|
|
|
return request(url)
|
|
|
|
.put(path)
|
|
|
|
.send({ reason })
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.set('Authorization', 'Bearer ' + token)
|
2018-08-14 03:08:47 -04:00
|
|
|
.expect(specialStatus)
|
|
|
|
}
|
2018-08-13 10:57:13 -04:00
|
|
|
|
2020-12-07 08:32:36 -05:00
|
|
|
function removeVideoFromBlacklist (url: string, token: string, videoId: number | string, specialStatus = HttpStatusCode.NO_CONTENT_204) {
|
2017-10-10 04:02:18 -04:00
|
|
|
const path = '/api/v1/videos/' + videoId + '/blacklist'
|
2017-09-22 03:13:43 -04:00
|
|
|
|
|
|
|
return request(url)
|
2020-01-31 10:56:52 -05:00
|
|
|
.delete(path)
|
|
|
|
.set('Accept', 'application/json')
|
|
|
|
.set('Authorization', 'Bearer ' + token)
|
|
|
|
.expect(specialStatus)
|
2017-09-22 03:13:43 -04:00
|
|
|
}
|
|
|
|
|
2019-04-15 04:49:46 -04:00
|
|
|
function getBlacklistedVideosList (parameters: {
|
2020-01-31 10:56:52 -05:00
|
|
|
url: string
|
|
|
|
token: string
|
|
|
|
sort?: string
|
|
|
|
type?: VideoBlacklistType
|
2020-12-07 08:32:36 -05:00
|
|
|
specialStatus?: HttpStatusCode
|
2019-04-15 04:49:46 -04:00
|
|
|
}) {
|
2020-12-07 08:32:36 -05:00
|
|
|
const { url, token, sort, type, specialStatus = HttpStatusCode.OK_200 } = parameters
|
2017-10-10 04:02:18 -04:00
|
|
|
const path = '/api/v1/videos/blacklist/'
|
2017-09-22 03:13:43 -04:00
|
|
|
|
2019-04-15 04:49:46 -04:00
|
|
|
const query = { sort, type }
|
2019-04-02 05:26:47 -04:00
|
|
|
|
2019-04-15 04:49:46 -04:00
|
|
|
return makeGetRequest({
|
|
|
|
url,
|
|
|
|
path,
|
|
|
|
query,
|
|
|
|
token,
|
|
|
|
statusCodeExpected: specialStatus
|
|
|
|
})
|
2017-09-22 03:13:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
export {
|
|
|
|
addVideoToBlacklist,
|
|
|
|
removeVideoFromBlacklist,
|
|
|
|
getBlacklistedVideosList,
|
2018-08-13 10:57:13 -04:00
|
|
|
updateVideoBlacklist
|
2017-09-22 03:13:43 -04:00
|
|
|
}
|