aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-25 10:21:38 +0200
committerChocobozzz <me@florianbigard.com>2018-04-25 13:50:48 +0200
commit6b738c7a31591a83fdcd9c78b6b1f98e543c378b (patch)
treedb771d0e99e9ff27570885fe2a6f58a7c1948fbc /server/tests/api/videos
parent48dce1c90dff4e90a4bcffefaecf157336cf904b (diff)
downloadPeerTube-6b738c7a31591a83fdcd9c78b6b1f98e543c378b.tar.gz
PeerTube-6b738c7a31591a83fdcd9c78b6b1f98e543c378b.tar.zst
PeerTube-6b738c7a31591a83fdcd9c78b6b1f98e543c378b.zip
Video channel API routes refractor
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/video-channels.ts33
-rw-r--r--server/tests/api/videos/video-nsfw.ts55
2 files changed, 58 insertions, 30 deletions
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index a7552a83a..04e7b8c6a 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -3,7 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { User } from '../../../../shared/index' 5import { User } from '../../../../shared/index'
6import { doubleFollow, flushAndRunMultipleServers, uploadVideo, wait } from '../../utils' 6import { doubleFollow, flushAndRunMultipleServers, getVideoChannelVideos, uploadVideo, wait } from '../../utils'
7import { 7import {
8 addVideoChannel, 8 addVideoChannel,
9 deleteVideoChannel, 9 deleteVideoChannel,
@@ -24,8 +24,9 @@ const expect = chai.expect
24describe('Test video channels', function () { 24describe('Test video channels', function () {
25 let servers: ServerInfo[] 25 let servers: ServerInfo[]
26 let userInfo: User 26 let userInfo: User
27 let accountId: number 27 let accountUUID: string
28 let videoChannelId: number 28 let videoChannelId: number
29 let videoChannelUUID: string
29 30
30 before(async function () { 31 before(async function () {
31 this.timeout(30000) 32 this.timeout(30000)
@@ -38,8 +39,9 @@ describe('Test video channels', function () {
38 await doubleFollow(servers[0], servers[1]) 39 await doubleFollow(servers[0], servers[1])
39 40
40 { 41 {
41 const res = await getAccountsList(servers[0].url) 42 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
42 accountId = res.body.data[0].id 43 const user: User = res.body
44 accountUUID = user.account.uuid
43 } 45 }
44 46
45 await wait(5000) 47 await wait(5000)
@@ -61,11 +63,12 @@ describe('Test video channels', function () {
61 description: 'super video channel description', 63 description: 'super video channel description',
62 support: 'super video channel support text' 64 support: 'super video channel support text'
63 } 65 }
64 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannel) 66 const res = await addVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannel)
65 videoChannelId = res.body.videoChannel.id 67 videoChannelId = res.body.videoChannel.id
68 videoChannelUUID = res.body.videoChannel.uuid
66 69
67 // The channel is 1 is propagated to servers 2 70 // The channel is 1 is propagated to servers 2
68 await uploadVideo(servers[0].url, servers[0].accessToken, { channelId: videoChannelId }) 71 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'my video name', channelId: videoChannelId })
69 72
70 await wait(3000) 73 await wait(3000)
71 }) 74 })
@@ -127,7 +130,7 @@ describe('Test video channels', function () {
127 support: 'video channel support text updated' 130 support: 'video channel support text updated'
128 } 131 }
129 132
130 await updateVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannelId, videoChannelAttributes) 133 await updateVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId, videoChannelAttributes)
131 134
132 await wait(3000) 135 await wait(3000)
133 }) 136 })
@@ -146,7 +149,7 @@ describe('Test video channels', function () {
146 }) 149 })
147 150
148 it('Should get video channel', async function () { 151 it('Should get video channel', async function () {
149 const res = await getVideoChannel(servers[0].url, accountId, videoChannelId) 152 const res = await getVideoChannel(servers[0].url, accountUUID, videoChannelId)
150 153
151 const videoChannel = res.body 154 const videoChannel = res.body
152 expect(videoChannel.displayName).to.equal('video channel updated') 155 expect(videoChannel.displayName).to.equal('video channel updated')
@@ -154,8 +157,20 @@ describe('Test video channels', function () {
154 expect(videoChannel.support).to.equal('video channel support text updated') 157 expect(videoChannel.support).to.equal('video channel support text updated')
155 }) 158 })
156 159
160 it('Should list the video channel videos', async function () {
161 this.timeout(10000)
162
163 for (const server of servers) {
164 const res = await getVideoChannelVideos(server.url, server.accessToken, accountUUID, videoChannelUUID, 0, 5)
165 expect(res.body.total).to.equal(1)
166 expect(res.body.data).to.be.an('array')
167 expect(res.body.data).to.have.lengthOf(1)
168 expect(res.body.data[0].name).to.equal('my video name')
169 }
170 })
171
157 it('Should delete video channel', async function () { 172 it('Should delete video channel', async function () {
158 await deleteVideoChannel(servers[0].url, servers[0].accessToken, accountId, videoChannelId) 173 await deleteVideoChannel(servers[0].url, servers[0].accessToken, accountUUID, videoChannelId)
159 }) 174 })
160 175
161 it('Should have video channel deleted', async function () { 176 it('Should have video channel deleted', async function () {
diff --git a/server/tests/api/videos/video-nsfw.ts b/server/tests/api/videos/video-nsfw.ts
index 4e5ab11ce..8901f38f9 100644
--- a/server/tests/api/videos/video-nsfw.ts
+++ b/server/tests/api/videos/video-nsfw.ts
@@ -7,8 +7,9 @@ import { userLogin } from '../../utils/users/login'
7import { createUser } from '../../utils/users/users' 7import { createUser } from '../../utils/users/users'
8import { getMyVideos } from '../../utils/videos/videos' 8import { getMyVideos } from '../../utils/videos/videos'
9import { 9import {
10 getAccountVideos,
10 getConfig, getCustomConfig, 11 getConfig, getCustomConfig,
11 getMyUserInformation, 12 getMyUserInformation, getVideoChannelVideos,
12 getVideosListWithToken, 13 getVideosListWithToken,
13 runServer, 14 runServer,
14 searchVideo, 15 searchVideo,
@@ -17,6 +18,7 @@ import {
17} from '../../utils' 18} from '../../utils'
18import { ServerConfig } from '../../../../shared/models' 19import { ServerConfig } from '../../../../shared/models'
19import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 20import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
21import { User } from '../../../../shared/models/users'
20 22
21const expect = chai.expect 23const expect = chai.expect
22 24
@@ -25,6 +27,31 @@ describe('Test video NSFW policy', function () {
25 let userAccessToken: string 27 let userAccessToken: string
26 let customConfig: CustomConfig 28 let customConfig: CustomConfig
27 29
30 function getVideosFunctions (token?: string) {
31 return getMyUserInformation(server.url, server.accessToken)
32 .then(res => {
33 const user: User = res.body
34 const videoChannelUUID = user.videoChannels[0].uuid
35 const accountUUID = user.account.uuid
36
37 if (token) {
38 return Promise.all([
39 getVideosListWithToken(server.url, token),
40 searchVideoWithToken(server.url, 'n', token),
41 getAccountVideos(server.url, token, accountUUID, 0, 5),
42 getVideoChannelVideos(server.url, token, accountUUID, videoChannelUUID, 0, 5)
43 ])
44 }
45
46 return Promise.all([
47 getVideosList(server.url),
48 searchVideo(server.url, 'n'),
49 getAccountVideos(server.url, undefined, accountUUID, 0, 5),
50 getVideoChannelVideos(server.url, undefined, accountUUID, videoChannelUUID, 0, 5)
51 ])
52 })
53 }
54
28 before(async function () { 55 before(async function () {
29 this.timeout(50000) 56 this.timeout(50000)
30 57
@@ -56,7 +83,7 @@ describe('Test video NSFW policy', function () {
56 const serverConfig: ServerConfig = resConfig.body 83 const serverConfig: ServerConfig = resConfig.body
57 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display') 84 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('display')
58 85
59 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) { 86 for (const res of await getVideosFunctions()) {
60 expect(res.body.total).to.equal(2) 87 expect(res.body.total).to.equal(2)
61 88
62 const videos = res.body.data 89 const videos = res.body.data
@@ -74,7 +101,7 @@ describe('Test video NSFW policy', function () {
74 const serverConfig: ServerConfig = resConfig.body 101 const serverConfig: ServerConfig = resConfig.body
75 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list') 102 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('do_not_list')
76 103
77 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) { 104 for (const res of await getVideosFunctions()) {
78 expect(res.body.total).to.equal(1) 105 expect(res.body.total).to.equal(1)
79 106
80 const videos = res.body.data 107 const videos = res.body.data
@@ -91,7 +118,7 @@ describe('Test video NSFW policy', function () {
91 const serverConfig: ServerConfig = resConfig.body 118 const serverConfig: ServerConfig = resConfig.body
92 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur') 119 expect(serverConfig.instance.defaultNSFWPolicy).to.equal('blur')
93 120
94 for (const res of [ await getVideosList(server.url), await searchVideo(server.url, 'n') ]) { 121 for (const res of await getVideosFunctions()) {
95 expect(res.body.total).to.equal(2) 122 expect(res.body.total).to.equal(2)
96 123
97 const videos = res.body.data 124 const videos = res.body.data
@@ -118,12 +145,7 @@ describe('Test video NSFW policy', function () {
118 }) 145 })
119 146
120 it('Should display NSFW videos with blur user NSFW policy', async function () { 147 it('Should display NSFW videos with blur user NSFW policy', async function () {
121 const results = [ 148 for (const res of await getVideosFunctions(userAccessToken)) {
122 await getVideosListWithToken(server.url, userAccessToken),
123 await searchVideoWithToken(server.url, 'n', userAccessToken)
124 ]
125
126 for (const res of results) {
127 expect(res.body.total).to.equal(2) 149 expect(res.body.total).to.equal(2)
128 150
129 const videos = res.body.data 151 const videos = res.body.data
@@ -140,12 +162,7 @@ describe('Test video NSFW policy', function () {
140 nsfwPolicy: 'display' 162 nsfwPolicy: 'display'
141 }) 163 })
142 164
143 const results = [ 165 for (const res of await getVideosFunctions(server.accessToken)) {
144 await getVideosListWithToken(server.url, server.accessToken),
145 await searchVideoWithToken(server.url, 'n', server.accessToken)
146 ]
147
148 for (const res of results) {
149 expect(res.body.total).to.equal(2) 166 expect(res.body.total).to.equal(2)
150 167
151 const videos = res.body.data 168 const videos = res.body.data
@@ -162,11 +179,7 @@ describe('Test video NSFW policy', function () {
162 nsfwPolicy: 'do_not_list' 179 nsfwPolicy: 'do_not_list'
163 }) 180 })
164 181
165 const results = [ 182 for (const res of await getVideosFunctions(server.accessToken)) {
166 await getVideosListWithToken(server.url, server.accessToken),
167 await searchVideoWithToken(server.url, 'n', server.accessToken)
168 ]
169 for (const res of results) {
170 expect(res.body.total).to.equal(1) 183 expect(res.body.total).to.equal(1)
171 184
172 const videos = res.body.data 185 const videos = res.body.data