1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
5 import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index'
6 import { userLogin } from '../../../../shared/extra-utils/users/login'
7 import { createUser } from '../../../../shared/extra-utils/users/users'
8 import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
15 getVideoChannelVideos,
16 getVideosListWithToken,
21 } from '../../../../shared/extra-utils'
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 () {
60 server = await flushAndRunServer(1)
62 // Get the access tokens
63 await setAccessTokensToServers([ server ])
66 const attributes = { name: 'nsfw', nsfw: true }
67 await uploadVideo(server.url, server.accessToken, attributes)
71 const attributes = { name: 'normal', nsfw: false }
72 await uploadVideo(server.url, server.accessToken, attributes)
76 const res = await getCustomConfig(server.url, server.accessToken)
77 customConfig = res.body
81 describe('Instance default NSFW policy', function () {
82 it('Should display NSFW videos with display default NSFW policy', async function () {
83 const resConfig = await getConfig(server.url)
84 const serverConfig: ServerConfig = resConfig.body
85 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
87 for (const res of await getVideosFunctions()) {
88 expect(res.body.total).to.equal(2)
90 const videos = res.body.data
91 expect(videos).to.have.lengthOf(2)
92 expect(videos[ 0 ].name).to.equal('normal')
93 expect(videos[ 1 ].name).to.equal('nsfw')
97 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
98 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
99 await updateCustomConfig(server.url, server.accessToken, customConfig)
101 const resConfig = await getConfig(server.url)
102 const serverConfig: ServerConfig = resConfig.body
103 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
105 for (const res of await getVideosFunctions()) {
106 expect(res.body.total).to.equal(1)
108 const videos = res.body.data
109 expect(videos).to.have.lengthOf(1)
110 expect(videos[ 0 ].name).to.equal('normal')
114 it('Should display NSFW videos with blur default NSFW policy', async function () {
115 customConfig.instance.defaultNSFWPolicy = 'blur'
116 await updateCustomConfig(server.url, server.accessToken, customConfig)
118 const resConfig = await getConfig(server.url)
119 const serverConfig: ServerConfig = resConfig.body
120 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
122 for (const res of await getVideosFunctions()) {
123 expect(res.body.total).to.equal(2)
125 const videos = res.body.data
126 expect(videos).to.have.lengthOf(2)
127 expect(videos[ 0 ].name).to.equal('normal')
128 expect(videos[ 1 ].name).to.equal('nsfw')
133 describe('User NSFW policy', function () {
135 it('Should create a user having the default nsfw policy', async function () {
136 const username = 'user1'
137 const password = 'my super password'
138 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
140 userAccessToken = await userLogin(server, { username, password })
142 const res = await getMyUserInformation(server.url, userAccessToken)
143 const user = res.body
145 expect(user.nsfwPolicy).to.equal('blur')
148 it('Should display NSFW videos with blur user NSFW policy', async function () {
149 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
150 await updateCustomConfig(server.url, server.accessToken, customConfig)
152 for (const res of await getVideosFunctions(userAccessToken)) {
153 expect(res.body.total).to.equal(2)
155 const videos = res.body.data
156 expect(videos).to.have.lengthOf(2)
157 expect(videos[ 0 ].name).to.equal('normal')
158 expect(videos[ 1 ].name).to.equal('nsfw')
162 it('Should display NSFW videos with display user NSFW policy', async function () {
165 accessToken: server.accessToken,
166 nsfwPolicy: 'display'
169 for (const res of await getVideosFunctions(server.accessToken)) {
170 expect(res.body.total).to.equal(2)
172 const videos = res.body.data
173 expect(videos).to.have.lengthOf(2)
174 expect(videos[ 0 ].name).to.equal('normal')
175 expect(videos[ 1 ].name).to.equal('nsfw')
179 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
182 accessToken: server.accessToken,
183 nsfwPolicy: 'do_not_list'
186 for (const res of await getVideosFunctions(server.accessToken)) {
187 expect(res.body.total).to.equal(1)
189 const videos = res.body.data
190 expect(videos).to.have.lengthOf(1)
191 expect(videos[ 0 ].name).to.equal('normal')
195 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
196 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
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')
205 it('Should display NSFW videos when the nsfw param === true', async function () {
206 for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) {
207 expect(res.body.total).to.equal(1)
209 const videos = res.body.data
210 expect(videos).to.have.lengthOf(1)
211 expect(videos[ 0 ].name).to.equal('nsfw')
215 it('Should hide NSFW videos when the nsfw param === true', async function () {
216 for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) {
217 expect(res.body.total).to.equal(1)
219 const videos = res.body.data
220 expect(videos).to.have.lengthOf(1)
221 expect(videos[ 0 ].name).to.equal('normal')
225 it('Should display both videos when the nsfw param === both', async function () {
226 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
227 expect(res.body.total).to.equal(2)
229 const videos = res.body.data
230 expect(videos).to.have.lengthOf(2)
231 expect(videos[ 0 ].name).to.equal('normal')
232 expect(videos[ 1 ].name).to.equal('nsfw')
237 after(async function () {
238 await cleanupTests([ server ])