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