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'
10 getConfig, getCustomConfig,
12 getVideosListWithToken,
15 searchVideoWithToken, updateCustomConfig,
18 import { ServerConfig } from '../../../../shared/models'
19 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
21 const expect = chai.expect
23 describe('Test video NSFW policy', function () {
24 let server: ServerInfo
25 let userAccessToken: string
26 let customConfig: CustomConfig
28 before(async function () {
32 server = await runServer(1)
34 // Get the access tokens
35 await setAccessTokensToServers([ server ])
38 const attributes = { name: 'nsfw', nsfw: true }
39 await uploadVideo(server.url, server.accessToken, attributes)
43 const attributes = { name: 'normal', nsfw: false }
44 await uploadVideo(server.url, server.accessToken, attributes)
48 const res = await getCustomConfig(server.url, server.accessToken)
49 customConfig = res.body
53 describe('Instance default NSFW policy', function () {
54 it('Should display NSFW videos with display default NSFW policy', async function () {
55 const resConfig = await getConfig(server.url)
56 const serverConfig: ServerConfig = resConfig.body
57 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
59 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
60 expect(res.body.total).to.equal(2)
62 const videos = res.body.data
63 expect(videos).to.have.lengthOf(2)
64 expect(videos[ 0 ].name).to.equal('normal')
65 expect(videos[ 1 ].name).to.equal('nsfw')
69 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
70 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
71 await updateCustomConfig(server.url, server.accessToken, customConfig)
73 const resConfig = await getConfig(server.url)
74 const serverConfig: ServerConfig = resConfig.body
75 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
77 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
78 expect(res.body.total).to.equal(1)
80 const videos = res.body.data
81 expect(videos).to.have.lengthOf(1)
82 expect(videos[ 0 ].name).to.equal('normal')
86 it('Should display NSFW videos with blur default NSFW policy', async function () {
87 customConfig.instance.defaultNSFWPolicy = 'blur'
88 await updateCustomConfig(server.url, server.accessToken, customConfig)
90 const resConfig = await getConfig(server.url)
91 const serverConfig: ServerConfig = resConfig.body
92 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
94 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) {
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')
105 describe('User NSFW policy', function () {
107 it('Should create a user having the default nsfw policy', async function () {
108 const username = 'user1'
109 const password = 'my super password'
110 await createUser(server.url, server.accessToken, username, password)
112 userAccessToken = await userLogin(server, { username, password })
114 const res = await getMyUserInformation(server.url, userAccessToken)
115 const user = res.body
117 expect(user.nsfwPolicy).to.equal('blur')
120 it('Should display NSFW videos with blur user NSFW policy', async function () {
122 await getVideosListWithToken(server.url, userAccessToken),
123 await searchVideoWithToken(server.url, 'n', userAccessToken)
126 for (const res of results) {
127 expect(res.body.total).to.equal(2)
129 const videos = res.body.data
130 expect(videos).to.have.lengthOf(2)
131 expect(videos[ 0 ].name).to.equal('normal')
132 expect(videos[ 1 ].name).to.equal('nsfw')
136 it('Should display NSFW videos with display user NSFW policy', async function () {
139 accessToken: server.accessToken,
140 nsfwPolicy: 'display'
144 await getVideosListWithToken(server.url, server.accessToken),
145 await searchVideoWithToken(server.url, 'n', server.accessToken)
148 for (const res of results) {
149 expect(res.body.total).to.equal(2)
151 const videos = res.body.data
152 expect(videos).to.have.lengthOf(2)
153 expect(videos[ 0 ].name).to.equal('normal')
154 expect(videos[ 1 ].name).to.equal('nsfw')
158 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
161 accessToken: server.accessToken,
162 nsfwPolicy: 'do_not_list'
166 await getVideosListWithToken(server.url, server.accessToken),
167 await searchVideoWithToken(server.url, 'n', server.accessToken)
169 for (const res of results) {
170 expect(res.body.total).to.equal(1)
172 const videos = res.body.data
173 expect(videos).to.have.lengthOf(1)
174 expect(videos[ 0 ].name).to.equal('normal')
178 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
179 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
180 expect(res.body.total).to.equal(2)
182 const videos = res.body.data
183 expect(videos).to.have.lengthOf(2)
184 expect(videos[ 0 ].name).to.equal('normal')
185 expect(videos[ 1 ].name).to.equal('nsfw')
189 after(async function () {
190 killallServers([ server ])
192 // Keep the logs if the test failed