diff options
Diffstat (limited to 'server/tests/api/videos/video-nsfw.ts')
-rw-r--r-- | server/tests/api/videos/video-nsfw.ts | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts index ad6a4b43f..b16b484b9 100644 --- a/server/tests/api/videos/video-nsfw.ts +++ b/server/tests/api/videos/video-nsfw.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
@@ -19,12 +19,20 @@ import { | |||
19 | updateCustomConfig, | 19 | updateCustomConfig, |
20 | updateMyUser | 20 | updateMyUser |
21 | } from '../../../../shared/extra-utils' | 21 | } from '../../../../shared/extra-utils' |
22 | import { ServerConfig } from '../../../../shared/models' | 22 | import { ServerConfig, VideosOverview } from '../../../../shared/models' |
23 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | 23 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' |
24 | import { User } from '../../../../shared/models/users' | 24 | import { User } from '../../../../shared/models/users' |
25 | import { getVideosOverview, getVideosOverviewWithToken } from '@shared/extra-utils/overviews/overviews' | ||
25 | 26 | ||
26 | const expect = chai.expect | 27 | const expect = chai.expect |
27 | 28 | ||
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 | |||
28 | describe('Test video NSFW policy', function () { | 36 | describe('Test video NSFW policy', function () { |
29 | let server: ServerInfo | 37 | let server: ServerInfo |
30 | let userAccessToken: string | 38 | let userAccessToken: string |
@@ -36,22 +44,38 @@ describe('Test video NSFW policy', function () { | |||
36 | const user: User = res.body | 44 | const user: User = res.body |
37 | const videoChannelName = user.videoChannels[0].name | 45 | const videoChannelName = user.videoChannels[0].name |
38 | const accountName = user.account.name + '@' + user.account.host | 46 | const accountName = user.account.name + '@' + user.account.host |
47 | const hasQuery = Object.keys(query).length !== 0 | ||
48 | let promises: Promise<any>[] | ||
39 | 49 | ||
40 | if (token) { | 50 | if (token) { |
41 | return Promise.all([ | 51 | promises = [ |
42 | getVideosListWithToken(server.url, token, query), | 52 | getVideosListWithToken(server.url, token, query), |
43 | searchVideoWithToken(server.url, 'n', token, query), | 53 | searchVideoWithToken(server.url, 'n', token, query), |
44 | getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), | 54 | getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), |
45 | getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) | 55 | getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) |
46 | ]) | 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) | ||
47 | } | 64 | } |
48 | 65 | ||
49 | return Promise.all([ | 66 | promises = [ |
50 | getVideosList(server.url), | 67 | getVideosList(server.url), |
51 | searchVideo(server.url, 'n'), | 68 | searchVideo(server.url, 'n'), |
52 | getAccountVideos(server.url, undefined, accountName, 0, 5), | 69 | getAccountVideos(server.url, undefined, accountName, 0, 5), |
53 | getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) | 70 | getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) |
54 | ]) | 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) | ||
55 | }) | 79 | }) |
56 | } | 80 | } |
57 | 81 | ||
@@ -63,12 +87,12 @@ describe('Test video NSFW policy', function () { | |||
63 | await setAccessTokensToServers([ server ]) | 87 | await setAccessTokensToServers([ server ]) |
64 | 88 | ||
65 | { | 89 | { |
66 | const attributes = { name: 'nsfw', nsfw: true } | 90 | const attributes = { name: 'nsfw', nsfw: true, category: 1 } |
67 | await uploadVideo(server.url, server.accessToken, attributes) | 91 | await uploadVideo(server.url, server.accessToken, attributes) |
68 | } | 92 | } |
69 | 93 | ||
70 | { | 94 | { |
71 | const attributes = { name: 'normal', nsfw: false } | 95 | const attributes = { name: 'normal', nsfw: false, category: 1 } |
72 | await uploadVideo(server.url, server.accessToken, attributes) | 96 | await uploadVideo(server.url, server.accessToken, attributes) |
73 | } | 97 | } |
74 | 98 | ||
@@ -89,8 +113,8 @@ describe('Test video NSFW policy', function () { | |||
89 | 113 | ||
90 | const videos = res.body.data | 114 | const videos = res.body.data |
91 | expect(videos).to.have.lengthOf(2) | 115 | expect(videos).to.have.lengthOf(2) |
92 | expect(videos[ 0 ].name).to.equal('normal') | 116 | expect(videos[0].name).to.equal('normal') |
93 | expect(videos[ 1 ].name).to.equal('nsfw') | 117 | expect(videos[1].name).to.equal('nsfw') |
94 | } | 118 | } |
95 | }) | 119 | }) |
96 | 120 | ||
@@ -107,7 +131,7 @@ describe('Test video NSFW policy', function () { | |||
107 | 131 | ||
108 | const videos = res.body.data | 132 | const videos = res.body.data |
109 | expect(videos).to.have.lengthOf(1) | 133 | expect(videos).to.have.lengthOf(1) |
110 | expect(videos[ 0 ].name).to.equal('normal') | 134 | expect(videos[0].name).to.equal('normal') |
111 | } | 135 | } |
112 | }) | 136 | }) |
113 | 137 | ||
@@ -124,8 +148,8 @@ describe('Test video NSFW policy', function () { | |||
124 | 148 | ||
125 | const videos = res.body.data | 149 | const videos = res.body.data |
126 | expect(videos).to.have.lengthOf(2) | 150 | expect(videos).to.have.lengthOf(2) |
127 | expect(videos[ 0 ].name).to.equal('normal') | 151 | expect(videos[0].name).to.equal('normal') |
128 | expect(videos[ 1 ].name).to.equal('nsfw') | 152 | expect(videos[1].name).to.equal('nsfw') |
129 | } | 153 | } |
130 | }) | 154 | }) |
131 | }) | 155 | }) |
@@ -154,8 +178,8 @@ describe('Test video NSFW policy', function () { | |||
154 | 178 | ||
155 | const videos = res.body.data | 179 | const videos = res.body.data |
156 | expect(videos).to.have.lengthOf(2) | 180 | expect(videos).to.have.lengthOf(2) |
157 | expect(videos[ 0 ].name).to.equal('normal') | 181 | expect(videos[0].name).to.equal('normal') |
158 | expect(videos[ 1 ].name).to.equal('nsfw') | 182 | expect(videos[1].name).to.equal('nsfw') |
159 | } | 183 | } |
160 | }) | 184 | }) |
161 | 185 | ||
@@ -171,8 +195,8 @@ describe('Test video NSFW policy', function () { | |||
171 | 195 | ||
172 | const videos = res.body.data | 196 | const videos = res.body.data |
173 | expect(videos).to.have.lengthOf(2) | 197 | expect(videos).to.have.lengthOf(2) |
174 | expect(videos[ 0 ].name).to.equal('normal') | 198 | expect(videos[0].name).to.equal('normal') |
175 | expect(videos[ 1 ].name).to.equal('nsfw') | 199 | expect(videos[1].name).to.equal('nsfw') |
176 | } | 200 | } |
177 | }) | 201 | }) |
178 | 202 | ||
@@ -188,7 +212,7 @@ describe('Test video NSFW policy', function () { | |||
188 | 212 | ||
189 | const videos = res.body.data | 213 | const videos = res.body.data |
190 | expect(videos).to.have.lengthOf(1) | 214 | expect(videos).to.have.lengthOf(1) |
191 | expect(videos[ 0 ].name).to.equal('normal') | 215 | expect(videos[0].name).to.equal('normal') |
192 | } | 216 | } |
193 | }) | 217 | }) |
194 | 218 | ||
@@ -198,8 +222,8 @@ describe('Test video NSFW policy', function () { | |||
198 | 222 | ||
199 | const videos = res.body.data | 223 | const videos = res.body.data |
200 | expect(videos).to.have.lengthOf(2) | 224 | expect(videos).to.have.lengthOf(2) |
201 | expect(videos[ 0 ].name).to.equal('normal') | 225 | expect(videos[0].name).to.equal('normal') |
202 | expect(videos[ 1 ].name).to.equal('nsfw') | 226 | expect(videos[1].name).to.equal('nsfw') |
203 | }) | 227 | }) |
204 | 228 | ||
205 | it('Should display NSFW videos when the nsfw param === true', async function () { | 229 | it('Should display NSFW videos when the nsfw param === true', async function () { |
@@ -208,7 +232,7 @@ describe('Test video NSFW policy', function () { | |||
208 | 232 | ||
209 | const videos = res.body.data | 233 | const videos = res.body.data |
210 | expect(videos).to.have.lengthOf(1) | 234 | expect(videos).to.have.lengthOf(1) |
211 | expect(videos[ 0 ].name).to.equal('nsfw') | 235 | expect(videos[0].name).to.equal('nsfw') |
212 | } | 236 | } |
213 | }) | 237 | }) |
214 | 238 | ||
@@ -218,7 +242,7 @@ describe('Test video NSFW policy', function () { | |||
218 | 242 | ||
219 | const videos = res.body.data | 243 | const videos = res.body.data |
220 | expect(videos).to.have.lengthOf(1) | 244 | expect(videos).to.have.lengthOf(1) |
221 | expect(videos[ 0 ].name).to.equal('normal') | 245 | expect(videos[0].name).to.equal('normal') |
222 | } | 246 | } |
223 | }) | 247 | }) |
224 | 248 | ||
@@ -228,8 +252,8 @@ describe('Test video NSFW policy', function () { | |||
228 | 252 | ||
229 | const videos = res.body.data | 253 | const videos = res.body.data |
230 | expect(videos).to.have.lengthOf(2) | 254 | expect(videos).to.have.lengthOf(2) |
231 | expect(videos[ 0 ].name).to.equal('normal') | 255 | expect(videos[0].name).to.equal('normal') |
232 | expect(videos[ 1 ].name).to.equal('nsfw') | 256 | expect(videos[1].name).to.equal('nsfw') |
233 | } | 257 | } |
234 | }) | 258 | }) |
235 | }) | 259 | }) |