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