1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
14 getVideoChannelVideos,
16 getVideosListWithToken,
18 setAccessTokensToServers,
23 } from '@shared/extra-utils'
24 import { BooleanBothQuery, CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models'
26 const expect = chai.expect
28 function createOverviewRes (overview: VideosOverview) {
29 const videos = overview.categories[0].videos
30 return { body: { data: videos, total: videos.length } }
33 describe('Test video NSFW policy', function () {
34 let server: ServerInfo
35 let userAccessToken: string
36 let customConfig: CustomConfig
38 function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
39 return getMyUserInformation(server.url, server.accessToken)
41 const user: User = res.body
42 const videoChannelName = user.videoChannels[0].name
43 const accountName = user.account.name + '@' + user.account.host
44 const hasQuery = Object.keys(query).length !== 0
45 let promises: Promise<any>[]
49 getVideosListWithToken(server.url, token, query),
50 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }),
51 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query),
52 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query)
55 // Overviews do not support video filters
57 const p = server.overviewsCommand.getVideos({ page: 1, token })
58 .then(res => createOverviewRes(res))
62 return Promise.all(promises)
66 getVideosList(server.url),
67 server.searchCommand.searchVideos({ search: 'n' }),
68 getAccountVideos(server.url, undefined, accountName, 0, 5),
69 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5)
72 // Overviews do not support video filters
74 const p = server.overviewsCommand.getVideos({ page: 1 })
75 .then(res => createOverviewRes(res))
79 return Promise.all(promises)
83 before(async function () {
85 server = await flushAndRunServer(1)
87 // Get the access tokens
88 await setAccessTokensToServers([ server ])
91 const attributes = { name: 'nsfw', nsfw: true, category: 1 }
92 await uploadVideo(server.url, server.accessToken, attributes)
96 const attributes = { name: 'normal', nsfw: false, category: 1 }
97 await uploadVideo(server.url, server.accessToken, attributes)
101 const res = await getCustomConfig(server.url, server.accessToken)
102 customConfig = res.body
106 describe('Instance default NSFW policy', function () {
107 it('Should display NSFW videos with display default NSFW policy', async function () {
108 const resConfig = await getConfig(server.url)
109 const serverConfig: ServerConfig = resConfig.body
110 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
112 for (const res of await getVideosFunctions()) {
113 expect(res.body.total).to.equal(2)
115 const videos = res.body.data
116 expect(videos).to.have.lengthOf(2)
117 expect(videos[0].name).to.equal('normal')
118 expect(videos[1].name).to.equal('nsfw')
122 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
123 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
124 await updateCustomConfig(server.url, server.accessToken, customConfig)
126 const resConfig = await getConfig(server.url)
127 const serverConfig: ServerConfig = resConfig.body
128 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
130 for (const res of await getVideosFunctions()) {
131 expect(res.body.total).to.equal(1)
133 const videos = res.body.data
134 expect(videos).to.have.lengthOf(1)
135 expect(videos[0].name).to.equal('normal')
139 it('Should display NSFW videos with blur default NSFW policy', async function () {
140 customConfig.instance.defaultNSFWPolicy = 'blur'
141 await updateCustomConfig(server.url, server.accessToken, customConfig)
143 const resConfig = await getConfig(server.url)
144 const serverConfig: ServerConfig = resConfig.body
145 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
147 for (const res of await getVideosFunctions()) {
148 expect(res.body.total).to.equal(2)
150 const videos = res.body.data
151 expect(videos).to.have.lengthOf(2)
152 expect(videos[0].name).to.equal('normal')
153 expect(videos[1].name).to.equal('nsfw')
158 describe('User NSFW policy', function () {
160 it('Should create a user having the default nsfw policy', async function () {
161 const username = 'user1'
162 const password = 'my super password'
163 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
165 userAccessToken = await userLogin(server, { username, password })
167 const res = await getMyUserInformation(server.url, userAccessToken)
168 const user = res.body
170 expect(user.nsfwPolicy).to.equal('blur')
173 it('Should display NSFW videos with blur user NSFW policy', async function () {
174 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
175 await updateCustomConfig(server.url, server.accessToken, customConfig)
177 for (const res of await getVideosFunctions(userAccessToken)) {
178 expect(res.body.total).to.equal(2)
180 const videos = res.body.data
181 expect(videos).to.have.lengthOf(2)
182 expect(videos[0].name).to.equal('normal')
183 expect(videos[1].name).to.equal('nsfw')
187 it('Should display NSFW videos with display user NSFW policy', async function () {
190 accessToken: server.accessToken,
191 nsfwPolicy: 'display'
194 for (const res of await getVideosFunctions(server.accessToken)) {
195 expect(res.body.total).to.equal(2)
197 const videos = res.body.data
198 expect(videos).to.have.lengthOf(2)
199 expect(videos[0].name).to.equal('normal')
200 expect(videos[1].name).to.equal('nsfw')
204 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
207 accessToken: server.accessToken,
208 nsfwPolicy: 'do_not_list'
211 for (const res of await getVideosFunctions(server.accessToken)) {
212 expect(res.body.total).to.equal(1)
214 const videos = res.body.data
215 expect(videos).to.have.lengthOf(1)
216 expect(videos[0].name).to.equal('normal')
220 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
221 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
222 expect(res.body.total).to.equal(2)
224 const videos = res.body.data
225 expect(videos).to.have.lengthOf(2)
226 expect(videos[0].name).to.equal('normal')
227 expect(videos[1].name).to.equal('nsfw')
230 it('Should display NSFW videos when the nsfw param === true', async function () {
231 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) {
232 expect(res.body.total).to.equal(1)
234 const videos = res.body.data
235 expect(videos).to.have.lengthOf(1)
236 expect(videos[0].name).to.equal('nsfw')
240 it('Should hide NSFW videos when the nsfw param === true', async function () {
241 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) {
242 expect(res.body.total).to.equal(1)
244 const videos = res.body.data
245 expect(videos).to.have.lengthOf(1)
246 expect(videos[0].name).to.equal('normal')
250 it('Should display both videos when the nsfw param === both', async function () {
251 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
252 expect(res.body.total).to.equal(2)
254 const videos = res.body.data
255 expect(videos).to.have.lengthOf(2)
256 expect(videos[0].name).to.equal('normal')
257 expect(videos[1].name).to.equal('nsfw')
262 after(async function () {
263 await cleanupTests([ server ])