1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
10 setAccessTokensToServers,
12 } from '../../../../shared/extra-utils/index'
13 import { userLogin } from '../../../../shared/extra-utils/users/login'
14 import { createUser } from '../../../../shared/extra-utils/users/users'
15 import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
21 getVideoChannelVideos,
22 getVideosListWithToken,
28 } from '../../../../shared/extra-utils'
29 import { ServerConfig } from '../../../../shared/models'
30 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
31 import { User } from '../../../../shared/models/users'
33 const expect = chai.expect
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
49 getVideosListWithToken(server.url, token, query),
50 searchVideoWithToken(server.url, 'n', token, query),
51 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query),
52 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query)
57 getVideosList(server.url),
58 searchVideo(server.url, 'n'),
59 getAccountVideos(server.url, undefined, accountName, 0, 5),
60 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5)
65 before(async function () {
67 server = await flushAndRunServer(1)
69 // Get the access tokens
70 await setAccessTokensToServers([ server ])
73 const attributes = { name: 'nsfw', nsfw: true }
74 await uploadVideo(server.url, server.accessToken, attributes)
78 const attributes = { name: 'normal', nsfw: false }
79 await uploadVideo(server.url, server.accessToken, attributes)
83 const res = await getCustomConfig(server.url, server.accessToken)
84 customConfig = res.body
88 describe('Instance default NSFW policy', function () {
89 it('Should display NSFW videos with display default NSFW policy', async function () {
90 const resConfig = await getConfig(server.url)
91 const serverConfig: ServerConfig = resConfig.body
92 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
94 for (const res of await getVideosFunctions()) {
95 expect(res.body.total).to.equal(2)
97 const videos = res.body.data
98 expect(videos).to.have.lengthOf(2)
99 expect(videos[ 0 ].name).to.equal('normal')
100 expect(videos[ 1 ].name).to.equal('nsfw')
104 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
105 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
106 await updateCustomConfig(server.url, server.accessToken, customConfig)
108 const resConfig = await getConfig(server.url)
109 const serverConfig: ServerConfig = resConfig.body
110 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
112 for (const res of await getVideosFunctions()) {
113 expect(res.body.total).to.equal(1)
115 const videos = res.body.data
116 expect(videos).to.have.lengthOf(1)
117 expect(videos[ 0 ].name).to.equal('normal')
121 it('Should display NSFW videos with blur default NSFW policy', async function () {
122 customConfig.instance.defaultNSFWPolicy = 'blur'
123 await updateCustomConfig(server.url, server.accessToken, customConfig)
125 const resConfig = await getConfig(server.url)
126 const serverConfig: ServerConfig = resConfig.body
127 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
129 for (const res of await getVideosFunctions()) {
130 expect(res.body.total).to.equal(2)
132 const videos = res.body.data
133 expect(videos).to.have.lengthOf(2)
134 expect(videos[ 0 ].name).to.equal('normal')
135 expect(videos[ 1 ].name).to.equal('nsfw')
140 describe('User NSFW policy', function () {
142 it('Should create a user having the default nsfw policy', async function () {
143 const username = 'user1'
144 const password = 'my super password'
145 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
147 userAccessToken = await userLogin(server, { username, password })
149 const res = await getMyUserInformation(server.url, userAccessToken)
150 const user = res.body
152 expect(user.nsfwPolicy).to.equal('blur')
155 it('Should display NSFW videos with blur user NSFW policy', async function () {
156 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
157 await updateCustomConfig(server.url, server.accessToken, customConfig)
159 for (const res of await getVideosFunctions(userAccessToken)) {
160 expect(res.body.total).to.equal(2)
162 const videos = res.body.data
163 expect(videos).to.have.lengthOf(2)
164 expect(videos[ 0 ].name).to.equal('normal')
165 expect(videos[ 1 ].name).to.equal('nsfw')
169 it('Should display NSFW videos with display user NSFW policy', async function () {
172 accessToken: server.accessToken,
173 nsfwPolicy: 'display'
176 for (const res of await getVideosFunctions(server.accessToken)) {
177 expect(res.body.total).to.equal(2)
179 const videos = res.body.data
180 expect(videos).to.have.lengthOf(2)
181 expect(videos[ 0 ].name).to.equal('normal')
182 expect(videos[ 1 ].name).to.equal('nsfw')
186 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
189 accessToken: server.accessToken,
190 nsfwPolicy: 'do_not_list'
193 for (const res of await getVideosFunctions(server.accessToken)) {
194 expect(res.body.total).to.equal(1)
196 const videos = res.body.data
197 expect(videos).to.have.lengthOf(1)
198 expect(videos[ 0 ].name).to.equal('normal')
202 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
203 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
204 expect(res.body.total).to.equal(2)
206 const videos = res.body.data
207 expect(videos).to.have.lengthOf(2)
208 expect(videos[ 0 ].name).to.equal('normal')
209 expect(videos[ 1 ].name).to.equal('nsfw')
212 it('Should display NSFW videos when the nsfw param === true', async function () {
213 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) {
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('nsfw')
222 it('Should hide NSFW videos when the nsfw param === true', async function () {
223 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) {
224 expect(res.body.total).to.equal(1)
226 const videos = res.body.data
227 expect(videos).to.have.lengthOf(1)
228 expect(videos[ 0 ].name).to.equal('normal')
232 it('Should display both videos when the nsfw param === both', async function () {
233 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
234 expect(res.body.total).to.equal(2)
236 const videos = res.body.data
237 expect(videos).to.have.lengthOf(2)
238 expect(videos[ 0 ].name).to.equal('normal')
239 expect(videos[ 1 ].name).to.equal('nsfw')
245 killallServers([ server ])