aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/video-nsfw.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-09 16:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitdd0ebb715123dfa126a82d4e4fe3a04064ae77b8 (patch)
treee0741f35b31c66f09f7d9ad808b224ef86151bb1 /server/tests/api/videos/video-nsfw.ts
parent9293139fde7091e9badcafa9b570b83cea9a10ad (diff)
downloadPeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.gz
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.tar.zst
PeerTube-dd0ebb715123dfa126a82d4e4fe3a04064ae77b8.zip
Introduce notifications command
Diffstat (limited to 'server/tests/api/videos/video-nsfw.ts')
-rw-r--r--server/tests/api/videos/video-nsfw.ts142
1 files changed, 70 insertions, 72 deletions
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index 65813517d..5f30939cc 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -18,13 +18,13 @@ import {
18 uploadVideo, 18 uploadVideo,
19 userLogin 19 userLogin
20} from '@shared/extra-utils' 20} from '@shared/extra-utils'
21import { BooleanBothQuery, CustomConfig, User, VideosOverview } from '@shared/models' 21import { BooleanBothQuery, CustomConfig, ResultList, User, Video, VideosOverview } from '@shared/models'
22 22
23const expect = chai.expect 23const expect = chai.expect
24 24
25function createOverviewRes (overview: VideosOverview) { 25function createOverviewRes (overview: VideosOverview) {
26 const videos = overview.categories[0].videos 26 const videos = overview.categories[0].videos
27 return { body: { data: videos, total: videos.length } } 27 return { data: videos, total: videos.length }
28} 28}
29 29
30describe('Test video NSFW policy', function () { 30describe('Test video NSFW policy', function () {
@@ -32,49 +32,47 @@ describe('Test video NSFW policy', function () {
32 let userAccessToken: string 32 let userAccessToken: string
33 let customConfig: CustomConfig 33 let customConfig: CustomConfig
34 34
35 function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) { 35 async function getVideosFunctions (token?: string, query: { nsfw?: BooleanBothQuery } = {}) {
36 return getMyUserInformation(server.url, server.accessToken) 36 const res = await getMyUserInformation(server.url, server.accessToken)
37 .then(res => { 37 const user: User = res.body
38 const user: User = res.body 38 const videoChannelName = user.videoChannels[0].name
39 const videoChannelName = user.videoChannels[0].name 39 const accountName = user.account.name + '@' + user.account.host
40 const accountName = user.account.name + '@' + user.account.host 40 const hasQuery = Object.keys(query).length !== 0
41 const hasQuery = Object.keys(query).length !== 0 41 let promises: Promise<ResultList<Video>>[]
42 let promises: Promise<any>[] 42
43 43 if (token) {
44 if (token) { 44 promises = [
45 promises = [ 45 getVideosListWithToken(server.url, token, query).then(res => res.body),
46 getVideosListWithToken(server.url, token, query), 46 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }),
47 server.searchCommand.advancedVideoSearch({ token, search: { search: 'n', ...query } }), 47 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query).then(res => res.body),
48 getAccountVideos(server.url, token, accountName, 0, 5, undefined, query), 48 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query).then(res => res.body)
49 getVideoChannelVideos(server.url, token, videoChannelName, 0, 5, undefined, query) 49 ]
50 ] 50
51 51 // Overviews do not support video filters
52 // Overviews do not support video filters 52 if (!hasQuery) {
53 if (!hasQuery) { 53 const p = server.overviewsCommand.getVideos({ page: 1, token })
54 const p = server.overviewsCommand.getVideos({ page: 1, token }) 54 .then(res => createOverviewRes(res))
55 .then(res => createOverviewRes(res)) 55 promises.push(p)
56 promises.push(p) 56 }
57 } 57
58 58 return Promise.all(promises)
59 return Promise.all(promises) 59 }
60 } 60
61 61 promises = [
62 promises = [ 62 getVideosList(server.url).then(res => res.body),
63 getVideosList(server.url), 63 server.searchCommand.searchVideos({ search: 'n' }),
64 server.searchCommand.searchVideos({ search: 'n' }), 64 getAccountVideos(server.url, undefined, accountName, 0, 5).then(res => res.body),
65 getAccountVideos(server.url, undefined, accountName, 0, 5), 65 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5).then(res => res.body)
66 getVideoChannelVideos(server.url, undefined, videoChannelName, 0, 5) 66 ]
67 ] 67
68 68 // Overviews do not support video filters
69 // Overviews do not support video filters 69 if (!hasQuery) {
70 if (!hasQuery) { 70 const p = server.overviewsCommand.getVideos({ page: 1 })
71 const p = server.overviewsCommand.getVideos({ page: 1 }) 71 .then(res => createOverviewRes(res))
72 .then(res => createOverviewRes(res)) 72 promises.push(p)
73 promises.push(p) 73 }
74 } 74
75 75 return Promise.all(promises)
76 return Promise.all(promises)
77 })
78 } 76 }
79 77
80 before(async function () { 78 before(async function () {
@@ -102,10 +100,10 @@ describe('Test video NSFW policy', function () {
102 const serverConfig = await server.configCommand.getConfig() 100 const serverConfig = await server.configCommand.getConfig()
103 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') 101 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
104 102
105 for (const res of await getVideosFunctions()) { 103 for (const body of await getVideosFunctions()) {
106 expect(res.body.total).to.equal(2) 104 expect(body.total).to.equal(2)
107 105
108 const videos = res.body.data 106 const videos = body.data
109 expect(videos).to.have.lengthOf(2) 107 expect(videos).to.have.lengthOf(2)
110 expect(videos[0].name).to.equal('normal') 108 expect(videos[0].name).to.equal('normal')
111 expect(videos[1].name).to.equal('nsfw') 109 expect(videos[1].name).to.equal('nsfw')
@@ -119,10 +117,10 @@ describe('Test video NSFW policy', function () {
119 const serverConfig = await server.configCommand.getConfig() 117 const serverConfig = await server.configCommand.getConfig()
120 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') 118 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
121 119
122 for (const res of await getVideosFunctions()) { 120 for (const body of await getVideosFunctions()) {
123 expect(res.body.total).to.equal(1) 121 expect(body.total).to.equal(1)
124 122
125 const videos = res.body.data 123 const videos = body.data
126 expect(videos).to.have.lengthOf(1) 124 expect(videos).to.have.lengthOf(1)
127 expect(videos[0].name).to.equal('normal') 125 expect(videos[0].name).to.equal('normal')
128 } 126 }
@@ -135,10 +133,10 @@ describe('Test video NSFW policy', function () {
135 const serverConfig = await server.configCommand.getConfig() 133 const serverConfig = await server.configCommand.getConfig()
136 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') 134 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
137 135
138 for (const res of await getVideosFunctions()) { 136 for (const body of await getVideosFunctions()) {
139 expect(res.body.total).to.equal(2) 137 expect(body.total).to.equal(2)
140 138
141 const videos = res.body.data 139 const videos = body.data
142 expect(videos).to.have.lengthOf(2) 140 expect(videos).to.have.lengthOf(2)
143 expect(videos[0].name).to.equal('normal') 141 expect(videos[0].name).to.equal('normal')
144 expect(videos[1].name).to.equal('nsfw') 142 expect(videos[1].name).to.equal('nsfw')
@@ -165,10 +163,10 @@ describe('Test video NSFW policy', function () {
165 customConfig.instance.defaultNSFWPolicy = 'do_not_list' 163 customConfig.instance.defaultNSFWPolicy = 'do_not_list'
166 await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig }) 164 await server.configCommand.updateCustomConfig({ newCustomConfig: customConfig })
167 165
168 for (const res of await getVideosFunctions(userAccessToken)) { 166 for (const body of await getVideosFunctions(userAccessToken)) {
169 expect(res.body.total).to.equal(2) 167 expect(body.total).to.equal(2)
170 168
171 const videos = res.body.data 169 const videos = body.data
172 expect(videos).to.have.lengthOf(2) 170 expect(videos).to.have.lengthOf(2)
173 expect(videos[0].name).to.equal('normal') 171 expect(videos[0].name).to.equal('normal')
174 expect(videos[1].name).to.equal('nsfw') 172 expect(videos[1].name).to.equal('nsfw')
@@ -182,10 +180,10 @@ describe('Test video NSFW policy', function () {
182 nsfwPolicy: 'display' 180 nsfwPolicy: 'display'
183 }) 181 })
184 182
185 for (const res of await getVideosFunctions(server.accessToken)) { 183 for (const body of await getVideosFunctions(server.accessToken)) {
186 expect(res.body.total).to.equal(2) 184 expect(body.total).to.equal(2)
187 185
188 const videos = res.body.data 186 const videos = body.data
189 expect(videos).to.have.lengthOf(2) 187 expect(videos).to.have.lengthOf(2)
190 expect(videos[0].name).to.equal('normal') 188 expect(videos[0].name).to.equal('normal')
191 expect(videos[1].name).to.equal('nsfw') 189 expect(videos[1].name).to.equal('nsfw')
@@ -199,10 +197,10 @@ describe('Test video NSFW policy', function () {
199 nsfwPolicy: 'do_not_list' 197 nsfwPolicy: 'do_not_list'
200 }) 198 })
201 199
202 for (const res of await getVideosFunctions(server.accessToken)) { 200 for (const body of await getVideosFunctions(server.accessToken)) {
203 expect(res.body.total).to.equal(1) 201 expect(body.total).to.equal(1)
204 202
205 const videos = res.body.data 203 const videos = body.data
206 expect(videos).to.have.lengthOf(1) 204 expect(videos).to.have.lengthOf(1)
207 expect(videos[0].name).to.equal('normal') 205 expect(videos[0].name).to.equal('normal')
208 } 206 }
@@ -219,30 +217,30 @@ describe('Test video NSFW policy', function () {
219 }) 217 })
220 218
221 it('Should display NSFW videos when the nsfw param === true', async function () { 219 it('Should display NSFW videos when the nsfw param === true', async function () {
222 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) { 220 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'true' })) {
223 expect(res.body.total).to.equal(1) 221 expect(body.total).to.equal(1)
224 222
225 const videos = res.body.data 223 const videos = body.data
226 expect(videos).to.have.lengthOf(1) 224 expect(videos).to.have.lengthOf(1)
227 expect(videos[0].name).to.equal('nsfw') 225 expect(videos[0].name).to.equal('nsfw')
228 } 226 }
229 }) 227 })
230 228
231 it('Should hide NSFW videos when the nsfw param === true', async function () { 229 it('Should hide NSFW videos when the nsfw param === true', async function () {
232 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) { 230 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'false' })) {
233 expect(res.body.total).to.equal(1) 231 expect(body.total).to.equal(1)
234 232
235 const videos = res.body.data 233 const videos = body.data
236 expect(videos).to.have.lengthOf(1) 234 expect(videos).to.have.lengthOf(1)
237 expect(videos[0].name).to.equal('normal') 235 expect(videos[0].name).to.equal('normal')
238 } 236 }
239 }) 237 })
240 238
241 it('Should display both videos when the nsfw param === both', async function () { 239 it('Should display both videos when the nsfw param === both', async function () {
242 for (const res of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) { 240 for (const body of await getVideosFunctions(server.accessToken, { nsfw: 'both' })) {
243 expect(res.body.total).to.equal(2) 241 expect(body.total).to.equal(2)
244 242
245 const videos = res.body.data 243 const videos = body.data
246 expect(videos).to.have.lengthOf(2) 244 expect(videos).to.have.lengthOf(2)
247 expect(videos[0].name).to.equal('normal') 245 expect(videos[0].name).to.equal('normal')
248 expect(videos[1].name).to.equal('nsfw') 246 expect(videos[1].name).to.equal('nsfw')