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'
11 getConfig, getCustomConfig,
12 getMyUserInformation, getVideoChannelVideos,
13 getVideosListWithToken,
16 searchVideoWithToken, updateCustomConfig,
19 import { ServerConfig } from '../../../../shared/models'
20 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
21 import { User } from '../../../../shared/models/users'
23 const expect = chai.expect
25 describe('Test video NSFW policy', function () {
26 let server: ServerInfo
27 let userAccessToken: string
28 let customConfig: CustomConfig
30 function getVideosFunctions (token?: string) {
31 return getMyUserInformation(server.url, server.accessToken)
33 const user: User = res.body
34 const videoChannelUUID = user.videoChannels[0].uuid
35 const accountName = user.account.name + '@' + user.account.host
39 getVideosListWithToken(server.url, token),
40 searchVideoWithToken(server.url, 'n', token),
41 getAccountVideos(server.url, token, accountName, 0, 5),
42 getVideoChannelVideos(server.url, token, videoChannelUUID, 0, 5)
47 getVideosList(server.url),
48 searchVideo(server.url, 'n'),
49 getAccountVideos(server.url, undefined, accountName, 0, 5),
50 getVideoChannelVideos(server.url, undefined, videoChannelUUID, 0, 5)
55 before(async function () {
59 server = await runServer(1)
61 // Get the access tokens
62 await setAccessTokensToServers([ server ])
65 const attributes = { name: 'nsfw', nsfw: true }
66 await uploadVideo(server.url, server.accessToken, attributes)
70 const attributes = { name: 'normal', nsfw: false }
71 await uploadVideo(server.url, server.accessToken, attributes)
75 const res = await getCustomConfig(server.url, server.accessToken)
76 customConfig = res.body
80 describe('Instance default NSFW policy', function () {
81 it('Should display NSFW videos with display default NSFW policy', async function () {
82 const resConfig = await getConfig(server.url)
83 const serverConfig: ServerConfig = resConfig.body
84 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
86 for (const res of await getVideosFunctions()) {
87 expect(res.body.total).to.equal(2)
89 const videos = res.body.data
90 expect(videos).to.have.lengthOf(2)
91 expect(videos[ 0 ].name).to.equal('normal')
92 expect(videos[ 1 ].name).to.equal('nsfw')
96 it('Should not display NSFW videos with do_not_list default NSFW policy', async function () {
97 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
98 await updateCustomConfig(server.url, server.accessToken, customConfig)
100 const resConfig = await getConfig(server.url)
101 const serverConfig: ServerConfig = resConfig.body
102 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
104 for (const res of await getVideosFunctions()) {
105 expect(res.body.total).to.equal(1)
107 const videos = res.body.data
108 expect(videos).to.have.lengthOf(1)
109 expect(videos[ 0 ].name).to.equal('normal')
113 it('Should display NSFW videos with blur default NSFW policy', async function () {
114 customConfig.instance.defaultNSFWPolicy = 'blur'
115 await updateCustomConfig(server.url, server.accessToken, customConfig)
117 const resConfig = await getConfig(server.url)
118 const serverConfig: ServerConfig = resConfig.body
119 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
121 for (const res of await getVideosFunctions()) {
122 expect(res.body.total).to.equal(2)
124 const videos = res.body.data
125 expect(videos).to.have.lengthOf(2)
126 expect(videos[ 0 ].name).to.equal('normal')
127 expect(videos[ 1 ].name).to.equal('nsfw')
132 describe('User NSFW policy', function () {
134 it('Should create a user having the default nsfw policy', async function () {
135 const username = 'user1'
136 const password = 'my super password'
137 await createUser(server.url, server.accessToken, username, password)
139 userAccessToken = await userLogin(server, { username, password })
141 const res = await getMyUserInformation(server.url, userAccessToken)
142 const user = res.body
144 expect(user.nsfwPolicy).to.equal('blur')
147 it('Should display NSFW videos with blur user NSFW policy', async function () {
148 for (const res of await getVideosFunctions(userAccessToken)) {
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 display NSFW videos with display user NSFW policy', async function () {
161 accessToken: server.accessToken,
162 nsfwPolicy: 'display'
165 for (const res of await getVideosFunctions(server.accessToken)) {
166 expect(res.body.total).to.equal(2)
168 const videos = res.body.data
169 expect(videos).to.have.lengthOf(2)
170 expect(videos[ 0 ].name).to.equal('normal')
171 expect(videos[ 1 ].name).to.equal('nsfw')
175 it('Should not display NSFW videos with do_not_list user NSFW policy', async function () {
178 accessToken: server.accessToken,
179 nsfwPolicy: 'do_not_list'
182 for (const res of await getVideosFunctions(server.accessToken)) {
183 expect(res.body.total).to.equal(1)
185 const videos = res.body.data
186 expect(videos).to.have.lengthOf(1)
187 expect(videos[ 0 ].name).to.equal('normal')
191 it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () {
192 const res = await getMyVideos(server.url, server.accessToken, 0, 5)
193 expect(res.body.total).to.equal(2)
195 const videos = res.body.data
196 expect(videos).to.have.lengthOf(2)
197 expect(videos[ 0 ].name).to.equal('normal')
198 expect(videos[ 1 ].name).to.equal('nsfw')
202 after(async function () {
203 killallServers([ server ])
205 // Keep the logs if the test failed