1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
14 getVideoChannelVideos,
16 getVideosListWithToken,
20 setAccessTokensToServers,
25 } from '@shared/extra-utils'
26 import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models'
28 const expect = chai.expect
30 function createOverviewRes (overview: VideosOverview) {
31 const videos = overview.categories[0].videos
32 return { body: { data: videos, total: videos.length } }
35 describe('Test video NSFW policy', function () {
36 let server: ServerInfo
37 let userAccessToken: string
38 let customConfig: CustomConfig
40 function getVideosFunctions (token?: string, query = {}) {
41 return getMyUserInformation(server.url, server.accessToken)
43 const user: User = res.body
44 const videoChannelName = user.videoChannels[0].name
45 const accountName = user.account.name + '@' + user.account.host
46 const hasQuery = Object.keys(query).length !== 0
47 let promises: Promise<any>[]
51 getVideosListWithToken(server.url, token, query),
52 searchVideoWithToken(server.url, 'n', token, query),
53 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query),
54 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query)
57 // Overviews do not support video filters
59 const p = server.overviewsCommand.getVideos({ page: 1, token })
60 .then(res => createOverviewRes(res))
64 return Promise.all(promises)
68 getVideosList(server.url),
69 searchVideo(server.url, 'n'),
70 getAccountVideos(server.url, undefined, accountName, 0, 5),
71 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5)
74 // Overviews do not support video filters
76 const p = server.overviewsCommand.getVideos({ page: 1 })
77 .then(res => createOverviewRes(res))
81 return Promise.all(promises)
85 before(async function () {
87 server = await flushAndRunServer(1)
89 // Get the access tokens
90 await setAccessTokensToServers([ server ])
93 const attributes = { name: 'nsfw', nsfw: true, category: 1 }
94 await uploadVideo(server.url, server.accessToken, attributes)
98 const attributes = { name: 'normal', nsfw: false, category: 1 }
99 await uploadVideo(server.url, server.accessToken, attributes)
103 const res = await getCustomConfig(server.url, server.accessToken)
104 customConfig = res.body
108 describe('Instance default NSFW policy', function () {
109 it('Should display NSFW videos with display default NSFW policy', async function () {
110 const resConfig = await getConfig(server.url)
111 const serverConfig: ServerConfig = resConfig.body
112 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
114 for (const res of await getVideosFunctions()) {
115 expect(res.body.total).to.equal(2)
117 const videos = res.body.data
118 expect(videos).to.have.lengthOf(2)
119 expect(videos[0].name).to.equal('normal')
120 expect(videos[1].name).to.equal('nsfw')
124 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
125 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
126 await updateCustomConfig(server.url, server.accessToken, customConfig)
128 const resConfig = await getConfig(server.url)
129 const serverConfig: ServerConfig = resConfig.body
130 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
132 for (const res of await getVideosFunctions()) {
133 expect(res.body.total).to.equal(1)
135 const videos = res.body.data
136 expect(videos).to.have.lengthOf(1)
137 expect(videos[0].name).to.equal('normal')
141 it('Should display NSFW videos with blur default NSFW policy', async function () {
142 customConfig.instance.defaultNSFWPolicy = 'blur'
143 await updateCustomConfig(server.url, server.accessToken, customConfig)
145 const resConfig = await getConfig(server.url)
146 const serverConfig: ServerConfig = resConfig.body
147 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
149 for (const res of await getVideosFunctions()) {
150 expect(res.body.total).to.equal(2)
152 const videos = res.body.data
153 expect(videos).to.have.lengthOf(2)
154 expect(videos[0].name).to.equal('normal')
155 expect(videos[1].name).to.equal('nsfw')
160 describe('User NSFW policy', function () {
162 it('Should create a user having the default nsfw policy', async function () {
163 const username = 'user1'
164 const password = 'my super password'
165 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
167 userAccessToken = await userLogin(server, { username, password })
169 const res = await getMyUserInformation(server.url, userAccessToken)
170 const user = res.body
172 expect(user.nsfwPolicy).to.equal('blur')
175 it('Should display NSFW videos with blur user NSFW policy', async function () {
176 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
177 await updateCustomConfig(server.url, server.accessToken, customConfig)
179 for (const res of await getVideosFunctions(userAccessToken)) {
180 expect(res.body.total).to.equal(2)
182 const videos = res.body.data
183 expect(videos).to.have.lengthOf(2)
184 expect(videos[0].name).to.equal('normal')
185 expect(videos[1].name).to.equal('nsfw')
189 it('Should display NSFW videos with display user NSFW policy', async function () {
192 accessToken: server.accessToken,
193 nsfwPolicy: 'display'
196 for (const res of await getVideosFunctions(server.accessToken)) {
197 expect(res.body.total).to.equal(2)
199 const videos = res.body.data
200 expect(videos).to.have.lengthOf(2)
201 expect(videos[0].name).to.equal('normal')
202 expect(videos[1].name).to.equal('nsfw')
206 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
209 accessToken: server.accessToken,
210 nsfwPolicy: 'do_not_list'
213 for (const res of await getVideosFunctions(server.accessToken)) {
214 expect(res.body.total).to.equal(1)
216 const videos = res.body.data
217 expect(videos).to.have.lengthOf(1)
218 expect(videos[0].name).to.equal('normal')
222 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
223 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
224 expect(res.body.total).to.equal(2)
226 const videos = res.body.data
227 expect(videos).to.have.lengthOf(2)
228 expect(videos[0].name).to.equal('normal')
229 expect(videos[1].name).to.equal('nsfw')
232 it('Should display NSFW videos when the nsfw param === true', async function () {
233 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) {
234 expect(res.body.total).to.equal(1)
236 const videos = res.body.data
237 expect(videos).to.have.lengthOf(1)
238 expect(videos[0].name).to.equal('nsfw')
242 it('Should hide NSFW videos when the nsfw param === true', async function () {
243 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) {
244 expect(res.body.total).to.equal(1)
246 const videos = res.body.data
247 expect(videos).to.have.lengthOf(1)
248 expect(videos[0].name).to.equal('normal')
252 it('Should display both videos when the nsfw param === both', async function () {
253 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
254 expect(res.body.total).to.equal(2)
256 const videos = res.body.data
257 expect(videos).to.have.lengthOf(2)
258 expect(videos[0].name).to.equal('normal')
259 expect(videos[1].name).to.equal('nsfw')
264 after(async function () {
265 await cleanupTests([ server ])