]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
0883b324 | 2 | |
0883b324 | 3 | import 'mocha' |
23a3a882 | 4 | import * as chai from 'chai' |
0883b324 | 5 | import { |
23a3a882 C |
6 | cleanupTests, |
7 | createUser, | |
7c3b7976 | 8 | flushAndRunServer, |
6b738c7a | 9 | getAccountVideos, |
3cd0734f C |
10 | getConfig, |
11 | getCustomConfig, | |
12 | getMyUserInformation, | |
23a3a882 | 13 | getMyVideos, |
3cd0734f | 14 | getVideoChannelVideos, |
23a3a882 | 15 | getVideosList, |
0883b324 | 16 | getVideosListWithToken, |
0883b324 | 17 | searchVideo, |
3cd0734f | 18 | searchVideoWithToken, |
23a3a882 C |
19 | ServerInfo, |
20 | setAccessTokensToServers, | |
3cd0734f | 21 | updateCustomConfig, |
23a3a882 C |
22 | updateMyUser, |
23 | uploadVideo, | |
24 | userLogin | |
25 | } from '@shared/extra-utils' | |
26 | import { CustomConfig, ServerConfig, User, VideosOverview } from '@shared/models' | |
0883b324 C |
27 | |
28 | const expect = chai.expect | |
29 | ||
23a3a882 | 30 | function createOverviewRes (overview: VideosOverview) { |
764a9657 C |
31 | const videos = overview.categories[0].videos |
32 | return { body: { data: videos, total: videos.length } } | |
33 | } | |
34 | ||
0883b324 C |
35 | describe('Test video NSFW policy', function () { |
36 | let server: ServerInfo | |
37 | let userAccessToken: string | |
38 | let customConfig: CustomConfig | |
39 | ||
d525fc39 | 40 | function getVideosFunctions (token?: string, query = {}) { |
6b738c7a C |
41 | return getMyUserInformation(server.url, server.accessToken) |
42 | .then(res => { | |
43 | const user: User = res.body | |
240085d0 | 44 | const videoChannelName = user.videoChannels[0].name |
ad9e39fb | 45 | const accountName = user.account.name + '@' + user.account.host |
764a9657 C |
46 | const hasQuery = Object.keys(query).length !== 0 |
47 | let promises: Promise<any>[] | |
6b738c7a C |
48 | |
49 | if (token) { | |
764a9657 | 50 | promises = [ |
d525fc39 C |
51 | getVideosListWithToken(server.url, token, query), |
52 | searchVideoWithToken(server.url, 'n', token, query), | |
53 | getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), | |
240085d0 | 54 | getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) |
764a9657 C |
55 | ] |
56 | ||
57 | // Overviews do not support video filters | |
58 | if (!hasQuery) { | |
23a3a882 C |
59 | const p = server.overviewsCommand.getVideos({ page: 1, token }) |
60 | .then(res => createOverviewRes(res)) | |
61 | promises.push(p) | |
764a9657 C |
62 | } |
63 | ||
64 | return Promise.all(promises) | |
6b738c7a C |
65 | } |
66 | ||
764a9657 | 67 | promises = [ |
6b738c7a C |
68 | getVideosList(server.url), |
69 | searchVideo(server.url, 'n'), | |
ad9e39fb | 70 | getAccountVideos(server.url, undefined, accountName, 0, 5), |
240085d0 | 71 | getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) |
764a9657 C |
72 | ] |
73 | ||
74 | // Overviews do not support video filters | |
75 | if (!hasQuery) { | |
23a3a882 C |
76 | const p = server.overviewsCommand.getVideos({ page: 1 }) |
77 | .then(res => createOverviewRes(res)) | |
78 | promises.push(p) | |
764a9657 C |
79 | } |
80 | ||
81 | return Promise.all(promises) | |
6b738c7a C |
82 | }) |
83 | } | |
84 | ||
0883b324 C |
85 | before(async function () { |
86 | this.timeout(50000) | |
210feb6c | 87 | server = await flushAndRunServer(1) |
0883b324 C |
88 | |
89 | // Get the access tokens | |
90 | await setAccessTokensToServers([ server ]) | |
91 | ||
92 | { | |
764a9657 | 93 | const attributes = { name: 'nsfw', nsfw: true, category: 1 } |
0883b324 C |
94 | await uploadVideo(server.url, server.accessToken, attributes) |
95 | } | |
96 | ||
97 | { | |
764a9657 | 98 | const attributes = { name: 'normal', nsfw: false, category: 1 } |
0883b324 C |
99 | await uploadVideo(server.url, server.accessToken, attributes) |
100 | } | |
101 | ||
102 | { | |
103 | const res = await getCustomConfig(server.url, server.accessToken) | |
104 | customConfig = res.body | |
105 | } | |
106 | }) | |
107 | ||
108 | describe('Instance default NSFW policy', function () { | |
109 | it('Should display NSFW videos with display default NSFW policy', async function () { | |
110 | const resConfig = await getConfig(server.url) | |
111 | const serverConfig: ServerConfig = resConfig.body | |
112 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') | |
113 | ||
6b738c7a | 114 | for (const res of await getVideosFunctions()) { |
0883b324 C |
115 | expect(res.body.total).to.equal(2) |
116 | ||
117 | const videos = res.body.data | |
118 | expect(videos).to.have.lengthOf(2) | |
a1587156 C |
119 | expect(videos[0].name).to.equal('normal') |
120 | expect(videos[1].name).to.equal('nsfw') | |
0883b324 C |
121 | } |
122 | }) | |
123 | ||
124 | it('Should not display NSFW videos with do_not_list default NSFW policy', async function () { | |
125 | customConfig.instance.defaultNSFWPolicy = 'do_not_list' | |
126 | await updateCustomConfig(server.url, server.accessToken, customConfig) | |
127 | ||
128 | const resConfig = await getConfig(server.url) | |
129 | const serverConfig: ServerConfig = resConfig.body | |
130 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') | |
131 | ||
6b738c7a | 132 | for (const res of await getVideosFunctions()) { |
0883b324 C |
133 | expect(res.body.total).to.equal(1) |
134 | ||
135 | const videos = res.body.data | |
136 | expect(videos).to.have.lengthOf(1) | |
a1587156 | 137 | expect(videos[0].name).to.equal('normal') |
0883b324 C |
138 | } |
139 | }) | |
140 | ||
141 | it('Should display NSFW videos with blur default NSFW policy', async function () { | |
142 | customConfig.instance.defaultNSFWPolicy = 'blur' | |
143 | await updateCustomConfig(server.url, server.accessToken, customConfig) | |
144 | ||
145 | const resConfig = await getConfig(server.url) | |
146 | const serverConfig: ServerConfig = resConfig.body | |
147 | expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') | |
148 | ||
6b738c7a | 149 | for (const res of await getVideosFunctions()) { |
0883b324 C |
150 | expect(res.body.total).to.equal(2) |
151 | ||
152 | const videos = res.body.data | |
153 | expect(videos).to.have.lengthOf(2) | |
a1587156 C |
154 | expect(videos[0].name).to.equal('normal') |
155 | expect(videos[1].name).to.equal('nsfw') | |
0883b324 C |
156 | } |
157 | }) | |
158 | }) | |
159 | ||
160 | describe('User NSFW policy', function () { | |
161 | ||
162 | it('Should create a user having the default nsfw policy', async function () { | |
163 | const username = 'user1' | |
164 | const password = 'my super password' | |
1eddc9a7 | 165 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) |
0883b324 C |
166 | |
167 | userAccessToken = await userLogin(server, { username, password }) | |
168 | ||
169 | const res = await getMyUserInformation(server.url, userAccessToken) | |
170 | const user = res.body | |
171 | ||
172 | expect(user.nsfwPolicy).to.equal('blur') | |
173 | }) | |
174 | ||
175 | it('Should display NSFW videos with blur user NSFW policy', async function () { | |
eb87f9a4 C |
176 | customConfig.instance.defaultNSFWPolicy = 'do_not_list' |
177 | await updateCustomConfig(server.url, server.accessToken, customConfig) | |
178 | ||
6b738c7a | 179 | for (const res of await getVideosFunctions(userAccessToken)) { |
0883b324 C |
180 | expect(res.body.total).to.equal(2) |
181 | ||
182 | const videos = res.body.data | |
183 | expect(videos).to.have.lengthOf(2) | |
a1587156 C |
184 | expect(videos[0].name).to.equal('normal') |
185 | expect(videos[1].name).to.equal('nsfw') | |
0883b324 C |
186 | } |
187 | }) | |
188 | ||
189 | it('Should display NSFW videos with display user NSFW policy', async function () { | |
190 | await updateMyUser({ | |
191 | url: server.url, | |
192 | accessToken: server.accessToken, | |
193 | nsfwPolicy: 'display' | |
194 | }) | |
195 | ||
6b738c7a | 196 | for (const res of await getVideosFunctions(server.accessToken)) { |
0883b324 C |
197 | expect(res.body.total).to.equal(2) |
198 | ||
199 | const videos = res.body.data | |
200 | expect(videos).to.have.lengthOf(2) | |
a1587156 C |
201 | expect(videos[0].name).to.equal('normal') |
202 | expect(videos[1].name).to.equal('nsfw') | |
0883b324 C |
203 | } |
204 | }) | |
205 | ||
206 | it('Should not display NSFW videos with do_not_list user NSFW policy', async function () { | |
207 | await updateMyUser({ | |
208 | url: server.url, | |
209 | accessToken: server.accessToken, | |
210 | nsfwPolicy: 'do_not_list' | |
211 | }) | |
212 | ||
6b738c7a | 213 | for (const res of await getVideosFunctions(server.accessToken)) { |
0883b324 C |
214 | expect(res.body.total).to.equal(1) |
215 | ||
216 | const videos = res.body.data | |
217 | expect(videos).to.have.lengthOf(1) | |
a1587156 | 218 | expect(videos[0].name).to.equal('normal') |
0883b324 C |
219 | } |
220 | }) | |
221 | ||
222 | it('Should be able to see my NSFW videos even with do_not_list user NSFW policy', async function () { | |
223 | const res = await getMyVideos(server.url, server.accessToken, 0, 5) | |
224 | expect(res.body.total).to.equal(2) | |
225 | ||
226 | const videos = res.body.data | |
227 | expect(videos).to.have.lengthOf(2) | |
a1587156 C |
228 | expect(videos[0].name).to.equal('normal') |
229 | expect(videos[1].name).to.equal('nsfw') | |
0883b324 | 230 | }) |
d525fc39 C |
231 | |
232 | it('Should display NSFW videos when the nsfw param === true', async function () { | |
233 | for (const res of await getVideosFunctions(server.accessToken, { nsfw: true })) { | |
234 | expect(res.body.total).to.equal(1) | |
235 | ||
236 | const videos = res.body.data | |
237 | expect(videos).to.have.lengthOf(1) | |
a1587156 | 238 | expect(videos[0].name).to.equal('nsfw') |
d525fc39 C |
239 | } |
240 | }) | |
241 | ||
242 | it('Should hide NSFW videos when the nsfw param === true', async function () { | |
243 | for (const res of await getVideosFunctions(server.accessToken, { nsfw: false })) { | |
244 | expect(res.body.total).to.equal(1) | |
245 | ||
246 | const videos = res.body.data | |
247 | expect(videos).to.have.lengthOf(1) | |
a1587156 | 248 | expect(videos[0].name).to.equal('normal') |
d525fc39 C |
249 | } |
250 | }) | |
0b18f4aa C |
251 | |
252 | it('Should display both videos when the nsfw param === both', async function () { | |
253 | for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { | |
254 | expect(res.body.total).to.equal(2) | |
255 | ||
256 | const videos = res.body.data | |
257 | expect(videos).to.have.lengthOf(2) | |
a1587156 C |
258 | expect(videos[0].name).to.equal('normal') |
259 | expect(videos[1].name).to.equal('nsfw') | |
0b18f4aa C |
260 | } |
261 | }) | |
0883b324 C |
262 | }) |
263 | ||
7c3b7976 C |
264 | after(async function () { |
265 | await cleanupTests([ server ]) | |
0883b324 C |
266 | }) |
267 | }) |