1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
10 setAccessTokensToServers,
12 } from '../../../../shared/utils/index'
13 import { userLogin } from '../../../../shared/utils/users/login'
14 import { createUser } from '../../../../shared/utils/users/users'
15 import { getMyVideos } from '../../../../shared/utils/videos/videos'
21 getVideoChannelVideos,
22 getVideosListWithToken,
28 } from '../../../../shared/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 () {
69 server = await runServer(1)
71 // Get the access tokens
72 await setAccessTokensToServers([ server ])
75 const attributes = { name: 'nsfw', nsfw: true }
76 await uploadVideo(server.url, server.accessToken, attributes)
80 const attributes = { name: 'normal', nsfw: false }
81 await uploadVideo(server.url, server.accessToken, attributes)
85 const res = await getCustomConfig(server.url, server.accessToken)
86 customConfig = res.body
90 describe('Instance default NSFW policy', function () {
91 it('Should display NSFW videos with display default NSFW policy', async function () {
92 const resConfig = await getConfig(server.url)
93 const serverConfig: ServerConfig = resConfig.body
94 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
96 for (const res of await getVideosFunctions()) {
97 expect(res.body.total).to.equal(2)
99 const videos = res.body.data
100 expect(videos).to.have.lengthOf(2)
101 expect(videos[ 0 ].name).to.equal('normal')
102 expect(videos[ 1 ].name).to.equal('nsfw')
106 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
107 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
108 await updateCustomConfig(server.url, server.accessToken, customConfig)
110 const resConfig = await getConfig(server.url)
111 const serverConfig: ServerConfig = resConfig.body
112 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
114 for (const res of await getVideosFunctions()) {
115 expect(res.body.total).to.equal(1)
117 const videos = res.body.data
118 expect(videos).to.have.lengthOf(1)
119 expect(videos[ 0 ].name).to.equal('normal')
123 it('Should display NSFW videos with blur default NSFW policy', async function () {
124 customConfig.instance.defaultNSFWPolicy = 'blur'
125 await updateCustomConfig(server.url, server.accessToken, customConfig)
127 const resConfig = await getConfig(server.url)
128 const serverConfig: ServerConfig = resConfig.body
129 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
131 for (const res of await getVideosFunctions()) {
132 expect(res.body.total).to.equal(2)
134 const videos = res.body.data
135 expect(videos).to.have.lengthOf(2)
136 expect(videos[ 0 ].name).to.equal('normal')
137 expect(videos[ 1 ].name).to.equal('nsfw')
142 describe('User NSFW policy', function () {
144 it('Should create a user having the default nsfw policy', async function () {
145 const username = 'user1'
146 const password = 'my super password'
147 await createUser(server.url, server.accessToken, username, password)
149 userAccessToken = await userLogin(server, { username, password })
151 const res = await getMyUserInformation(server.url, userAccessToken)
152 const user = res.body
154 expect(user.nsfwPolicy).to.equal('blur')
157 it('Should display NSFW videos with blur user NSFW policy', async function () {
158 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
159 await updateCustomConfig(server.url, server.accessToken, customConfig)
161 for (const res of await getVideosFunctions(userAccessToken)) {
162 expect(res.body.total).to.equal(2)
164 const videos = res.body.data
165 expect(videos).to.have.lengthOf(2)
166 expect(videos[ 0 ].name).to.equal('normal')
167 expect(videos[ 1 ].name).to.equal('nsfw')
171 it('Should display NSFW videos with display user NSFW policy', async function () {
174 accessToken: server.accessToken,
175 nsfwPolicy: 'display'
178 for (const res of await getVideosFunctions(server.accessToken)) {
179 expect(res.body.total).to.equal(2)
181 const videos = res.body.data
182 expect(videos).to.have.lengthOf(2)
183 expect(videos[ 0 ].name).to.equal('normal')
184 expect(videos[ 1 ].name).to.equal('nsfw')
188 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
191 accessToken: server.accessToken,
192 nsfwPolicy: 'do_not_list'
195 for (const res of await getVideosFunctions(server.accessToken)) {
196 expect(res.body.total).to.equal(1)
198 const videos = res.body.data
199 expect(videos).to.have.lengthOf(1)
200 expect(videos[ 0 ].name).to.equal('normal')
204 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
205 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
206 expect(res.body.total).to.equal(2)
208 const videos = res.body.data
209 expect(videos).to.have.lengthOf(2)
210 expect(videos[ 0 ].name).to.equal('normal')
211 expect(videos[ 1 ].name).to.equal('nsfw')
214 it('Should display NSFW videos when the nsfw param === true', async function () {
215 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) {
216 expect(res.body.total).to.equal(1)
218 const videos = res.body.data
219 expect(videos).to.have.lengthOf(1)
220 expect(videos[ 0 ].name).to.equal('nsfw')
224 it('Should hide NSFW videos when the nsfw param === true', async function () {
225 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) {
226 expect(res.body.total).to.equal(1)
228 const videos = res.body.data
229 expect(videos).to.have.lengthOf(1)
230 expect(videos[ 0 ].name).to.equal('normal')
234 it('Should display both videos when the nsfw param === both', async function () {
235 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
236 expect(res.body.total).to.equal(2)
238 const videos = res.body.data
239 expect(videos).to.have.lengthOf(2)
240 expect(videos[ 0 ].name).to.equal('normal')
241 expect(videos[ 1 ].name).to.equal('nsfw')
246 after(async function () {
247 killallServers([ server ])