aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-11 11:40:18 +0100
committerChocobozzz <me@florianbigard.com>2018-01-11 11:47:44 +0100
commit7bc29171456ffa91c7ec8dc77e892c7dca359989 (patch)
treec7682072919bf00f8b082c1c49f24567e181800f /server/tests
parent85cd9bde5a93500f973773f46680c07dd90d5912 (diff)
downloadPeerTube-7bc29171456ffa91c7ec8dc77e892c7dca359989.tar.gz
PeerTube-7bc29171456ffa91c7ec8dc77e892c7dca359989.tar.zst
PeerTube-7bc29171456ffa91c7ec8dc77e892c7dca359989.zip
Add tests to handle down server
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/index-slow.ts1
-rw-r--r--server/tests/api/server/handle-down.ts136
-rw-r--r--server/tests/api/videos/video-channels.ts16
-rw-r--r--server/tests/utils/server/servers.ts10
-rw-r--r--server/tests/utils/videos/videos.ts3
5 files changed, 147 insertions, 19 deletions
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts
index fe86fc018..0082bcb56 100644
--- a/server/tests/api/index-slow.ts
+++ b/server/tests/api/index-slow.ts
@@ -6,3 +6,4 @@ import './server/follows'
6import './server/jobs' 6import './server/jobs'
7import './videos/video-comments' 7import './videos/video-comments'
8import './users/users-multiple-servers' 8import './users/users-multiple-servers'
9import './server/handle-down'
diff --git a/server/tests/api/server/handle-down.ts b/server/tests/api/server/handle-down.ts
index f8ba8bd66..cc1ff9a9f 100644
--- a/server/tests/api/server/handle-down.ts
+++ b/server/tests/api/server/handle-down.ts
@@ -3,7 +3,8 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { VideoPrivacy } from '../../../../shared/models/videos' 5import { VideoPrivacy } from '../../../../shared/models/videos'
6import { completeVideoCheck, runServer, viewVideo } from '../../utils' 6import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
7import { completeVideoCheck, getVideo, immutableAssign, reRunServer, viewVideo } from '../../utils'
7 8
8import { 9import {
9 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo, 10 flushAndRunMultipleServers, flushTests, getVideosList, killallServers, ServerInfo, setAccessTokensToServers, uploadVideo,
@@ -11,11 +12,20 @@ import {
11} from '../../utils/index' 12} from '../../utils/index'
12import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows' 13import { follow, getFollowersListPaginationAndSort } from '../../utils/server/follows'
13import { getJobsListPaginationAndSort } from '../../utils/server/jobs' 14import { getJobsListPaginationAndSort } from '../../utils/server/jobs'
15import {
16 addVideoCommentReply, addVideoCommentThread, getVideoCommentThreads,
17 getVideoThreadComments
18} from '../../utils/videos/video-comments'
14 19
15const expect = chai.expect 20const expect = chai.expect
16 21
17describe('Test handle downs', function () { 22describe('Test handle downs', function () {
18 let servers: ServerInfo[] = [] 23 let servers: ServerInfo[] = []
24 const videos = []
25 let threadIdServer1: number
26 let threadIdServer2: number
27 let commentIdServer1: number
28 let commentIdServer2: number
19 29
20 const videoAttributes = { 30 const videoAttributes = {
21 name: 'my super name for server 1', 31 name: 'my super name for server 1',
@@ -23,11 +33,16 @@ describe('Test handle downs', function () {
23 licence: 4, 33 licence: 4,
24 language: 9, 34 language: 9,
25 nsfw: true, 35 nsfw: true,
36 privacy: VideoPrivacy.PUBLIC,
26 description: 'my super description for server 1', 37 description: 'my super description for server 1',
27 tags: [ 'tag1p1', 'tag2p1' ], 38 tags: [ 'tag1p1', 'tag2p1' ],
28 fixture: 'video_short1.webm' 39 fixture: 'video_short1.webm'
29 } 40 }
30 41
42 const unlistedVideoAttributes = immutableAssign(videoAttributes, {
43 privacy: VideoPrivacy.UNLISTED
44 })
45
31 const checkAttributes = { 46 const checkAttributes = {
32 name: 'my super name for server 1', 47 name: 'my super name for server 1',
33 category: 5, 48 category: 5,
@@ -56,6 +71,10 @@ describe('Test handle downs', function () {
56 ] 71 ]
57 } 72 }
58 73
74 const unlistedCheckAttributes = immutableAssign(checkAttributes, {
75 privacy: VideoPrivacy.UNLISTED
76 })
77
59 before(async function () { 78 before(async function () {
60 this.timeout(20000) 79 this.timeout(20000)
61 80
@@ -85,9 +104,27 @@ describe('Test handle downs', function () {
85 // Kill server 1 104 // Kill server 1
86 killallServers([ servers[1] ]) 105 killallServers([ servers[1] ])
87 106
107 let resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, unlistedVideoAttributes)
108 videos.push(resVideo.body.video)
109
88 // Remove server 2 follower 110 // Remove server 2 follower
89 for (let i = 0; i < 10; i++) { 111 for (let i = 0; i < 10; i++) {
90 await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes) 112 resVideo = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
113 videos.push(resVideo.body.video)
114 }
115
116 // Add comments to video 2
117 {
118 const text = 'thread 1'
119 let resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videos[1].uuid, text)
120 let comment = resComment.body.comment
121 threadIdServer1 = comment.id
122
123 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-1')
124 comment = resComment.body.comment
125
126 resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, comment.id, 'comment 1-2')
127 commentIdServer1 = resComment.body.comment.id
91 } 128 }
92 129
93 await wait(10000) 130 await wait(10000)
@@ -108,7 +145,9 @@ describe('Test handle downs', function () {
108 }) 145 })
109 146
110 it('Should follow server 1', async function () { 147 it('Should follow server 1', async function () {
111 servers[1] = await runServer(2) 148 this.timeout(15000)
149
150 await reRunServer(servers[1])
112 151
113 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken) 152 await follow(servers[1].url, [ servers[0].url ], servers[1].accessToken)
114 153
@@ -120,19 +159,98 @@ describe('Test handle downs', function () {
120 }) 159 })
121 160
122 it('Should send a view to server 2, and automatically fetch the video', async function () { 161 it('Should send a view to server 2, and automatically fetch the video', async function () {
123 const resVideo = await getVideosList(servers[0].url) 162 this.timeout(15000)
124 const videoServer1 = resVideo.body.data[0]
125 163
126 await viewVideo(servers[0].url, videoServer1.uuid) 164 await viewVideo(servers[0].url, videos[0].uuid)
127 165
128 await wait(5000) 166 await wait(5000)
129 167
130 const res = await getVideosList(servers[1].url) 168 const res = await getVideosList(servers[1].url)
131 const videoServer2 = res.body.data.find(v => v.url === videoServer1.url) 169 expect(res.body.data).to.be.an('array')
170 // Video is unlisted
171 expect(res.body.data).to.have.lengthOf(1)
172
173 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
174 expect(resVideo.body).not.to.be.undefined
175
176 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
177 })
178
179 it('Should send comments on a video to server 2, and automatically fetch the video', async function () {
180 this.timeout(25000)
132 181
133 expect(videoServer2).not.to.be.undefined 182 await addVideoCommentReply(servers[0].url, servers[0].accessToken, videos[1].uuid, commentIdServer1, 'comment 1-3')
183
184 await wait(5000)
185
186 const res = await getVideosList(servers[1].url)
187 expect(res.body.data).to.be.an('array')
188 expect(res.body.data).to.have.lengthOf(2)
134 189
135 await completeVideoCheck(servers[1].url, videoServer2, checkAttributes) 190 const resVideo = await getVideo(servers[1].url, videos[0].uuid)
191 expect(resVideo.body).not.to.be.undefined
192
193 await completeVideoCheck(servers[1].url, resVideo.body, unlistedCheckAttributes)
194
195 {
196 let resComment = await getVideoCommentThreads(servers[1].url, videos[1].uuid, 0, 5)
197 expect(resComment.body.data).to.be.an('array')
198 expect(resComment.body.data).to.have.lengthOf(1)
199
200 threadIdServer2 = resComment.body.data[0].id
201
202 resComment = await getVideoThreadComments(servers[1].url, videos[1].uuid, threadIdServer2)
203
204 const tree: VideoCommentThreadTree = resComment.body
205 expect(tree.comment.text).equal('thread 1')
206 expect(tree.children).to.have.lengthOf(1)
207
208 const firstChild = tree.children[0]
209 expect(firstChild.comment.text).to.equal('comment 1-1')
210 expect(firstChild.children).to.have.lengthOf(1)
211
212 const childOfFirstChild = firstChild.children[0]
213 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
214 expect(childOfFirstChild.children).to.have.lengthOf(1)
215
216 const childOfChildFirstChild = childOfFirstChild.children[0]
217 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
218 expect(childOfChildFirstChild.children).to.have.lengthOf(0)
219
220 commentIdServer2 = childOfChildFirstChild.comment.id
221 }
222 })
223
224 it('Should correctly reply to the comment', async function () {
225 this.timeout(15000)
226
227 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videos[1].uuid, commentIdServer2, 'comment 1-4')
228
229 await wait(5000)
230
231 {
232 const resComment = await getVideoThreadComments(servers[0].url, videos[1].uuid, threadIdServer1)
233
234 const tree: VideoCommentThreadTree = resComment.body
235 expect(tree.comment.text).equal('thread 1')
236 expect(tree.children).to.have.lengthOf(1)
237
238 const firstChild = tree.children[0]
239 expect(firstChild.comment.text).to.equal('comment 1-1')
240 expect(firstChild.children).to.have.lengthOf(1)
241
242 const childOfFirstChild = firstChild.children[0]
243 expect(childOfFirstChild.comment.text).to.equal('comment 1-2')
244 expect(childOfFirstChild.children).to.have.lengthOf(1)
245
246 const childOfChildFirstChild = childOfFirstChild.children[0]
247 expect(childOfChildFirstChild.comment.text).to.equal('comment 1-3')
248 expect(childOfChildFirstChild.children).to.have.lengthOf(1)
249
250 const childOfChildOfChildOfFirstChild = childOfChildFirstChild.children[0]
251 expect(childOfChildOfChildOfFirstChild.comment.text).to.equal('comment 1-4')
252 expect(childOfChildOfChildOfFirstChild.children).to.have.lengthOf(0)
253 }
136 }) 254 })
137 255
138 after(async function () { 256 after(async function () {
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 454a96da6..8d33c6025 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -59,8 +59,8 @@ describe('Test a video channels', function () {
59 expect(userInfo.videoChannels).to.have.lengthOf(2) 59 expect(userInfo.videoChannels).to.have.lengthOf(2)
60 60
61 const videoChannels = userInfo.videoChannels 61 const videoChannels = userInfo.videoChannels
62 expect(videoChannels[0].name).to.equal('Default root channel') 62 expect(videoChannels[0].displayName).to.equal('Default root channel')
63 expect(videoChannels[1].name).to.equal('second video channel') 63 expect(videoChannels[1].displayName).to.equal('second video channel')
64 expect(videoChannels[1].description).to.equal('super video channel description') 64 expect(videoChannels[1].description).to.equal('super video channel description')
65 }) 65 })
66 66
@@ -72,8 +72,8 @@ describe('Test a video channels', function () {
72 expect(res.body.data).to.have.lengthOf(2) 72 expect(res.body.data).to.have.lengthOf(2)
73 73
74 const videoChannels = res.body.data 74 const videoChannels = res.body.data
75 expect(videoChannels[0].name).to.equal('Default root channel') 75 expect(videoChannels[0].displayName).to.equal('Default root channel')
76 expect(videoChannels[1].name).to.equal('second video channel') 76 expect(videoChannels[1].displayName).to.equal('second video channel')
77 expect(videoChannels[1].description).to.equal('super video channel description') 77 expect(videoChannels[1].description).to.equal('super video channel description')
78 78
79 videoChannelId = videoChannels[1].id 79 videoChannelId = videoChannels[1].id
@@ -85,7 +85,7 @@ describe('Test a video channels', function () {
85 expect(res.body.total).to.equal(2) 85 expect(res.body.total).to.equal(2)
86 expect(res.body.data).to.be.an('array') 86 expect(res.body.data).to.be.an('array')
87 expect(res.body.data).to.have.lengthOf(1) 87 expect(res.body.data).to.have.lengthOf(1)
88 expect(res.body.data[0].name).to.equal('Default root channel') 88 expect(res.body.data[0].displayName).to.equal('Default root channel')
89 }) 89 })
90 90
91 it('Should update video channel', async () => { 91 it('Should update video channel', async () => {
@@ -103,7 +103,7 @@ describe('Test a video channels', function () {
103 expect(res.body.total).to.equal(2) 103 expect(res.body.total).to.equal(2)
104 expect(res.body.data).to.be.an('array') 104 expect(res.body.data).to.be.an('array')
105 expect(res.body.data).to.have.lengthOf(1) 105 expect(res.body.data).to.have.lengthOf(1)
106 expect(res.body.data[0].name).to.equal('video channel updated') 106 expect(res.body.data[0].displayName).to.equal('video channel updated')
107 expect(res.body.data[0].description).to.equal('video channel description updated') 107 expect(res.body.data[0].description).to.equal('video channel description updated')
108 }) 108 })
109 109
@@ -111,7 +111,7 @@ describe('Test a video channels', function () {
111 const res = await getVideoChannel(server.url, videoChannelId) 111 const res = await getVideoChannel(server.url, videoChannelId)
112 112
113 const videoChannel = res.body 113 const videoChannel = res.body
114 expect(videoChannel.name).to.equal('video channel updated') 114 expect(videoChannel.displayName).to.equal('video channel updated')
115 expect(videoChannel.description).to.equal('video channel description updated') 115 expect(videoChannel.description).to.equal('video channel description updated')
116 }) 116 })
117 117
@@ -125,7 +125,7 @@ describe('Test a video channels', function () {
125 expect(res.body.total).to.equal(1) 125 expect(res.body.total).to.equal(1)
126 expect(res.body.data).to.be.an('array') 126 expect(res.body.data).to.be.an('array')
127 expect(res.body.data).to.have.lengthOf(1) 127 expect(res.body.data).to.have.lengthOf(1)
128 expect(res.body.data[0].name).to.equal('Default root channel') 128 expect(res.body.data[0].displayName).to.equal('Default root channel')
129 }) 129 })
130 130
131 after(async function () { 131 after(async function () {
diff --git a/server/tests/utils/server/servers.ts b/server/tests/utils/server/servers.ts
index 4add2f69a..878efe91a 100644
--- a/server/tests/utils/server/servers.ts
+++ b/server/tests/utils/server/servers.ts
@@ -145,6 +145,13 @@ function runServer (serverNumber: number, configOverride?: Object) {
145 }) 145 })
146} 146}
147 147
148async function reRunServer (server: ServerInfo) {
149 const newServer = await runServer(server.serverNumber)
150 server.app = newServer.app
151
152 return server
153}
154
148function killallServers (servers: ServerInfo[]) { 155function killallServers (servers: ServerInfo[]) {
149 for (const server of servers) { 156 for (const server of servers) {
150 process.kill(-server.app.pid) 157 process.kill(-server.app.pid)
@@ -158,5 +165,6 @@ export {
158 flushAndRunMultipleServers, 165 flushAndRunMultipleServers,
159 flushTests, 166 flushTests,
160 runServer, 167 runServer,
161 killallServers 168 killallServers,
169 reRunServer
162} 170}
diff --git a/server/tests/utils/videos/videos.ts b/server/tests/utils/videos/videos.ts
index c437c21b2..dc1327215 100644
--- a/server/tests/utils/videos/videos.ts
+++ b/server/tests/utils/videos/videos.ts
@@ -383,7 +383,8 @@ async function completeVideoCheck (
383 expect(videoDetails.account.name).to.equal(attributes.account) 383 expect(videoDetails.account.name).to.equal(attributes.account)
384 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled) 384 expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
385 385
386 expect(videoDetails.channel.name).to.equal(attributes.channel.name) 386 expect(videoDetails.channel.displayName).to.equal(attributes.channel.name)
387 expect(videoDetails.channel.name).to.have.lengthOf(36)
387 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal) 388 expect(videoDetails.channel.isLocal).to.equal(attributes.channel.isLocal)
388 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true 389 expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true
389 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true 390 expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true