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