1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../utils/index'
6 import { userLogin } from '../../utils/users/login'
7 import { createUser } from '../../utils/users/users'
8 import { getMyVideos } from '../../utils/videos/videos'
14 getVideoChannelVideos,
15 getVideosListWithToken,
22 import { ServerConfig } from '../../../../shared/models'
23 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
24 import { User } from '../../../../shared/models/users'
26 const expect = chai.expect
28 describe('Test video NSFW policy', function () {
29 let server: ServerInfo
30 let userAccessToken: string
31 let customConfig: CustomConfig
33 function getVideosFunctions (token?: string, query = {}) {
34 return getMyUserInformation(server.url, server.accessToken)
36 const user: User = res.body
37 const videoChannelName = user.videoChannels[0].name
38 const accountName = user.account.name + '@' + user.account.host
42 getVideosListWithToken(server.url, token, query),
43 searchVideoWithToken(server.url, 'n', token, query),
44 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query),
45 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query)
50 getVideosList(server.url),
51 searchVideo(server.url, 'n'),
52 getAccountVideos(server.url, undefined, accountName, 0, 5),
53 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5)
58 before(async function () {
62 server = await runServer(1)
64 // Get the access tokens
65 await setAccessTokensToServers([ server ])
68 const attributes = { name: 'nsfw', nsfw: true }
69 await uploadVideo(server.url, server.accessToken, attributes)
73 const attributes = { name: 'normal', nsfw: false }
74 await uploadVideo(server.url, server.accessToken, attributes)
78 const res = await getCustomConfig(server.url, server.accessToken)
79 customConfig = res.body
83 describe('Instance default NSFW policy', function () {
84 it('Should display NSFW videos with display default NSFW policy', async function () {
85 const resConfig = await getConfig(server.url)
86 const serverConfig: ServerConfig = resConfig.body
87 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
89 for (const res of await getVideosFunctions()) {
90 expect(res.body.total).to.equal(2)
92 const videos = res.body.data
93 expect(videos).to.have.lengthOf(2)
94 expect(videos[ 0 ].name).to.equal('normal')
95 expect(videos[ 1 ].name).to.equal('nsfw')
99 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
100 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
101 await updateCustomConfig(server.url, server.accessToken, customConfig)
103 const resConfig = await getConfig(server.url)
104 const serverConfig: ServerConfig = resConfig.body
105 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
107 for (const res of await getVideosFunctions()) {
108 expect(res.body.total).to.equal(1)
110 const videos = res.body.data
111 expect(videos).to.have.lengthOf(1)
112 expect(videos[ 0 ].name).to.equal('normal')
116 it('Should display NSFW videos with blur default NSFW policy', async function () {
117 customConfig.instance.defaultNSFWPolicy = 'blur'
118 await updateCustomConfig(server.url, server.accessToken, customConfig)
120 const resConfig = await getConfig(server.url)
121 const serverConfig: ServerConfig = resConfig.body
122 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
124 for (const res of await getVideosFunctions()) {
125 expect(res.body.total).to.equal(2)
127 const videos = res.body.data
128 expect(videos).to.have.lengthOf(2)
129 expect(videos[ 0 ].name).to.equal('normal')
130 expect(videos[ 1 ].name).to.equal('nsfw')
135 describe('User NSFW policy', function () {
137 it('Should create a user having the default nsfw policy', async function () {
138 const username = 'user1'
139 const password = 'my super password'
140 await createUser(server.url, server.accessToken, username, password)
142 userAccessToken = await userLogin(server, { username, password })
144 const res = await getMyUserInformation(server.url, userAccessToken)
145 const user = res.body
147 expect(user.nsfwPolicy).to.equal('blur')
150 it('Should display NSFW videos with blur user NSFW policy', async function () {
151 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
152 await updateCustomConfig(server.url, server.accessToken, customConfig)
154 for (const res of await getVideosFunctions(userAccessToken)) {
155 expect(res.body.total).to.equal(2)
157 const videos = res.body.data
158 expect(videos).to.have.lengthOf(2)
159 expect(videos[ 0 ].name).to.equal('normal')
160 expect(videos[ 1 ].name).to.equal('nsfw')
164 it('Should display NSFW videos with display user NSFW policy', async function () {
167 accessToken: server.accessToken,
168 nsfwPolicy: 'display'
171 for (const res of await getVideosFunctions(server.accessToken)) {
172 expect(res.body.total).to.equal(2)
174 const videos = res.body.data
175 expect(videos).to.have.lengthOf(2)
176 expect(videos[ 0 ].name).to.equal('normal')
177 expect(videos[ 1 ].name).to.equal('nsfw')
181 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
184 accessToken: server.accessToken,
185 nsfwPolicy: 'do_not_list'
188 for (const res of await getVideosFunctions(server.accessToken)) {
189 expect(res.body.total).to.equal(1)
191 const videos = res.body.data
192 expect(videos).to.have.lengthOf(1)
193 expect(videos[ 0 ].name).to.equal('normal')
197 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
198 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
199 expect(res.body.total).to.equal(2)
201 const videos = res.body.data
202 expect(videos).to.have.lengthOf(2)
203 expect(videos[ 0 ].name).to.equal('normal')
204 expect(videos[ 1 ].name).to.equal('nsfw')
207 it('Should display NSFW videos when the nsfw param === true', async function () {
208 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) {
209 expect(res.body.total).to.equal(1)
211 const videos = res.body.data
212 expect(videos).to.have.lengthOf(1)
213 expect(videos[ 0 ].name).to.equal('nsfw')
217 it('Should hide NSFW videos when the nsfw param === true', async function () {
218 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) {
219 expect(res.body.total).to.equal(1)
221 const videos = res.body.data
222 expect(videos).to.have.lengthOf(1)
223 expect(videos[ 0 ].name).to.equal('normal')
227 it('Should display both videos when the nsfw param === both', async function () {
228 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
229 expect(res.body.total).to.equal(2)
231 const videos = res.body.data
232 expect(videos).to.have.lengthOf(2)
233 expect(videos[ 0 ].name).to.equal('normal')
234 expect(videos[ 1 ].name).to.equal('nsfw')
239 after(async function () {
240 killallServers([ server ])