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 videoChannelUUID = user.videoChannels[0].uuid
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, videoChannelUUID, 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, videoChannelUUID, 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 for (const res of await getVideosFunctions(userAccessToken)) {
152 expect(res.body.total).to.equal(2)
154 const videos = res.body.data
155 expect(videos).to.have.lengthOf(2)
156 expect(videos[ 0 ].name).to.equal('normal')
157 expect(videos[ 1 ].name).to.equal('nsfw')
161 it('Should display NSFW videos with display user NSFW policy', async function () {
164 accessToken: server.accessToken,
165 nsfwPolicy: 'display'
168 for (const res of await getVideosFunctions(server.accessToken)) {
169 expect(res.body.total).to.equal(2)
171 const videos = res.body.data
172 expect(videos).to.have.lengthOf(2)
173 expect(videos[ 0 ].name).to.equal('normal')
174 expect(videos[ 1 ].name).to.equal('nsfw')
178 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
181 accessToken: server.accessToken,
182 nsfwPolicy: 'do_not_list'
185 for (const res of await getVideosFunctions(server.accessToken)) {
186 expect(res.body.total).to.equal(1)
188 const videos = res.body.data
189 expect(videos).to.have.lengthOf(1)
190 expect(videos[ 0 ].name).to.equal('normal')
194 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
195 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
196 expect(res.body.total).to.equal(2)
198 const videos = res.body.data
199 expect(videos).to.have.lengthOf(2)
200 expect(videos[ 0 ].name).to.equal('normal')
201 expect(videos[ 1 ].name).to.equal('nsfw')
204 it('Should display NSFW videos when the nsfw param === true', async function () {
205 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) {
206 expect(res.body.total).to.equal(1)
208 const videos = res.body.data
209 expect(videos).to.have.lengthOf(1)
210 expect(videos[ 0 ].name).to.equal('nsfw')
214 it('Should hide NSFW videos when the nsfw param === true', async function () {
215 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) {
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('normal')
224 it('Should display both videos when the nsfw param === both', async function () {
225 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
226 expect(res.body.total).to.equal(2)
228 const videos = res.body.data
229 expect(videos).to.have.lengthOf(2)
230 expect(videos[ 0 ].name).to.equal('normal')
231 expect(videos[ 1 ].name).to.equal('nsfw')
236 after(async function () {
237 killallServers([ server ])