]>
Commit | Line | Data |
---|---|---|
0883b324 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
7c3b7976 | 5 | import { cleanupTests, getVideosList, ServerInfo, setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils/index' |
94565d52 C |
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' | |
0883b324 | 9 | import { |
7c3b7976 | 10 | flushAndRunServer, |
6b738c7a | 11 | getAccountVideos, |
3cd0734f C |
12 | getConfig, |
13 | getCustomConfig, | |
14 | getMyUserInformation, | |
15 | getVideoChannelVideos, | |
0883b324 | 16 | getVideosListWithToken, |
0883b324 | 17 | searchVideo, |
3cd0734f C |
18 | searchVideoWithToken, |
19 | updateCustomConfig, | |
0883b324 | 20 | updateMyUser |
94565d52 | 21 | } from '../../../../shared/extra-utils' |
0883b324 C |
22 | import { ServerConfig } from '../../../../shared/models' |
23 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | |
6b738c7a | 24 | import { User } from '../../../../shared/models/users' |
0883b324 C |
25 | |
26 | const expect = chai.expect | |
27 | ||
28 | describe('Test video NSFW policy', function () { | |
29 | let server: ServerInfo | |
30 | let userAccessToken: string | |
31 | let customConfig: CustomConfig | |
32 | ||
d525fc39 | 33 | function getVideosFunctions (token?: string, query = {}) { |
6b738c7a C |
34 | return getMyUserInformation(server.url, server.accessToken) |
35 | .then(res => { | |
36 | const user: User = res.body | |
240085d0 | 37 | const videoChannelName = user.videoChannels[0].name |
ad9e39fb | 38 | const accountName = user.account.name + '@' + user.account.host |
6b738c7a C |
39 | |
40 | if (token) { | |
41 | return Promise.all([ | |
d525fc39 C |
42 | getVideosListWithToken(server.url, token, query), |
43 | searchVideoWithToken(server.url, 'n', token, query), | |
44 | getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), | |
240085d0 | 45 | getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) |
6b738c7a C |
46 | ]) |
47 | } | |
48 | ||
49 | return Promise.all([ | |
50 | getVideosList(server.url), | |
51 | searchVideo(server.url, 'n'), | |
ad9e39fb | 52 | getAccountVideos(server.url, undefined, accountName, 0, 5), |
240085d0 | 53 | getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) |
6b738c7a C |
54 | ]) |
55 | }) | |
56 | } | |
57 | ||
0883b324 C |
58 | before(async function () { |
59 | this.timeout(50000) | |
210feb6c | 60 | server = await flushAndRunServer(1) |
0883b324 C |
61 | |
62 | // Get the access tokens | |
63 | await setAccessTokensToServers([ server ]) | |
64 | ||
65 | { | |
66 | const attributes = { name: 'nsfw', nsfw: true } | |
67 | await uploadVideo(server.url, server.accessToken, attributes) | |
68 | } | |
69 | ||
70 | { | |
71 | const attributes = { name: 'normal', nsfw: false } | |
72 | await uploadVideo(server.url, server.accessToken, attributes) | |
73 | } | |
74 | ||
75 | { | |
76 | const res = await getCustomConfig(server.url, server.accessToken) | |
77 | customConfig = res.body | |
78 | } | |
79 | }) | |
80 | ||
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') | |
86 | ||
6b738c7a | 87 | for (const res of await getVideosFunctions()) { |
0883b324 C |
88 | expect(res.body.total).to.equal(2) |
89 | ||
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') | |
94 | } | |
95 | }) | |
96 | ||
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) | |
100 | ||
101 | const resConfig = await getConfig(server.url) | |
102 | const serverConfig: ServerConfig = resConfig.body | |
103 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') | |
104 | ||
6b738c7a | 105 | for (const res of await getVideosFunctions()) { |
0883b324 C |
106 | expect(res.body.total).to.equal(1) |
107 | ||
108 | const videos = res.body.data | |
109 | expect(videos).to.have.lengthOf(1) | |
110 | expect(videos[ 0 ].name).to.equal('normal') | |
111 | } | |
112 | }) | |
113 | ||
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) | |
117 | ||
118 | const resConfig = await getConfig(server.url) | |
119 | const serverConfig: ServerConfig = resConfig.body | |
120 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') | |
121 | ||
6b738c7a | 122 | for (const res of await getVideosFunctions()) { |
0883b324 C |
123 | expect(res.body.total).to.equal(2) |
124 | ||
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') | |
129 | } | |
130 | }) | |
131 | }) | |
132 | ||
133 | describe('User NSFW policy', function () { | |
134 | ||
135 | it('Should create a user having the default nsfw policy', async function () { | |
136 | const username = 'user1' | |
137 | const password = 'my super password' | |
1eddc9a7 | 138 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
0883b324 C |
139 | |
140 | userAccessToken = await userLogin(server, { username, password }) | |
141 | ||
142 | const res = await getMyUserInformation(server.url, userAccessToken) | |
143 | const user = res.body | |
144 | ||
145 | expect(user.nsfwPolicy).to.equal('blur') | |
146 | }) | |
147 | ||
148 | it('Should display NSFW videos with blur user NSFW policy', async function () { | |
eb87f9a4 C |
149 | customConfig.instance.defaultNSFWPolicy = 'do_not_list' |
150 | await updateCustomConfig(server.url, server.accessToken, customConfig) | |
151 | ||
6b738c7a | 152 | for (const res of await getVideosFunctions(userAccessToken)) { |
0883b324 C |
153 | expect(res.body.total).to.equal(2) |
154 | ||
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') | |
159 | } | |
160 | }) | |
161 | ||
162 | it('Should display NSFW videos with display user NSFW policy', async function () { | |
163 | await updateMyUser({ | |
164 | url: server.url, | |
165 | accessToken: server.accessToken, | |
166 | nsfwPolicy: 'display' | |
167 | }) | |
168 | ||
6b738c7a | 169 | for (const res of await getVideosFunctions(server.accessToken)) { |
0883b324 C |
170 | expect(res.body.total).to.equal(2) |
171 | ||
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') | |
176 | } | |
177 | }) | |
178 | ||
179 | it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { | |
180 | await updateMyUser({ | |
181 | url: server.url, | |
182 | accessToken: server.accessToken, | |
183 | nsfwPolicy: 'do_not_list' | |
184 | }) | |
185 | ||
6b738c7a | 186 | for (const res of await getVideosFunctions(server.accessToken)) { |
0883b324 C |
187 | expect(res.body.total).to.equal(1) |
188 | ||
189 | const videos = res.body.data | |
190 | expect(videos).to.have.lengthOf(1) | |
191 | expect(videos[ 0 ].name).to.equal('normal') | |
192 | } | |
193 | }) | |
194 | ||
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) | |
198 | ||
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') | |
203 | }) | |
d525fc39 C |
204 | |
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) | |
208 | ||
209 | const videos = res.body.data | |
210 | expect(videos).to.have.lengthOf(1) | |
211 | expect(videos[ 0 ].name).to.equal('nsfw') | |
212 | } | |
213 | }) | |
214 | ||
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) | |
218 | ||
219 | const videos = res.body.data | |
220 | expect(videos).to.have.lengthOf(1) | |
221 | expect(videos[ 0 ].name).to.equal('normal') | |
222 | } | |
223 | }) | |
0b18f4aa C |
224 | |
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) | |
228 | ||
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') | |
233 | } | |
234 | }) | |
0883b324 C |
235 | }) |
236 | ||
7c3b7976 C |
237 | after(async function () { |
238 | await cleanupTests([ server ]) | |
0883b324 C |
239 | }) |
240 | }) |