aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/video-imports.ts39
-rw-r--r--server/tests/api/index-slow.ts2
-rw-r--r--server/tests/api/videos/video-imports.ts161
-rw-r--r--server/tests/client.ts69
-rw-r--r--server/tests/utils/server/config.ts66
-rw-r--r--server/tests/utils/videos/video-imports.ts37
6 files changed, 311 insertions, 63 deletions
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index 7f58efb74..0ead34a47 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -16,9 +16,11 @@ import {
16 runServer, 16 runServer,
17 ServerInfo, 17 ServerInfo,
18 setAccessTokensToServers, 18 setAccessTokensToServers,
19 updateCustomSubConfig,
19 userLogin 20 userLogin
20} from '../../utils' 21} from '../../utils'
21import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' 22import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
23import { getYoutubeVideoUrl } from '../../utils/videos/video-imports'
22 24
23describe('Test video imports API validator', function () { 25describe('Test video imports API validator', function () {
24 const path = '/api/v1/videos/imports' 26 const path = '/api/v1/videos/imports'
@@ -77,7 +79,7 @@ describe('Test video imports API validator', function () {
77 79
78 before(function () { 80 before(function () {
79 baseCorrectParams = { 81 baseCorrectParams = {
80 targetUrl: 'https://youtu.be/msX3jv1XdvM', 82 targetUrl: getYoutubeVideoUrl(),
81 name: 'my super name', 83 name: 'my super name',
82 category: 5, 84 category: 5,
83 licence: 1, 85 licence: 1,
@@ -98,6 +100,17 @@ describe('Test video imports API validator', function () {
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 100 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
99 }) 101 })
100 102
103 it('Should fail without a target url', async function () {
104 const fields = omit(baseCorrectParams, 'targetUrl')
105 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
106 })
107
108 it('Should fail with a bad target url', async function () {
109 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
110
111 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
112 })
113
101 it('Should fail with a long name', async function () { 114 it('Should fail with a long name', async function () {
102 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 115 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
103 116
@@ -219,20 +232,36 @@ describe('Test video imports API validator', function () {
219 it('Should succeed with the correct parameters', async function () { 232 it('Should succeed with the correct parameters', async function () {
220 this.timeout(10000) 233 this.timeout(10000)
221 234
222 const fields = baseCorrectParams
223
224 { 235 {
225 await makePostBodyRequest({ 236 await makePostBodyRequest({
226 url: server.url, 237 url: server.url,
227 path, 238 path,
228 token: server.accessToken, 239 token: server.accessToken,
229 fields, 240 fields: baseCorrectParams,
230 statusCodeExpected: 200 241 statusCodeExpected: 200
231 }) 242 })
232 } 243 }
233 }) 244 })
234 245
235 it('Should forbid importing') 246 it('Should forbid to import videos', async function () {
247 await updateCustomSubConfig(server.url, server.accessToken, {
248 import: {
249 videos: {
250 http: {
251 enabled: false
252 }
253 }
254 }
255 })
256
257 await makePostBodyRequest({
258 url: server.url,
259 path,
260 token: server.accessToken,
261 fields: baseCorrectParams,
262 statusCodeExpected: 409
263 })
264 })
236 }) 265 })
237 266
238 after(async function () { 267 after(async function () {
diff --git a/server/tests/api/index-slow.ts b/server/tests/api/index-slow.ts
index d987442b3..243c941cb 100644
--- a/server/tests/api/index-slow.ts
+++ b/server/tests/api/index-slow.ts
@@ -1,4 +1,5 @@
1// Order of the tests we want to execute 1// Order of the tests we want to execute
2import './videos/video-channels'
2import './videos/video-transcoder' 3import './videos/video-transcoder'
3import './videos/multiple-servers' 4import './videos/multiple-servers'
4import './server/follows' 5import './server/follows'
@@ -7,3 +8,4 @@ import './videos/video-comments'
7import './users/users-multiple-servers' 8import './users/users-multiple-servers'
8import './server/handle-down' 9import './server/handle-down'
9import './videos/video-schedule-update' 10import './videos/video-schedule-update'
11import './videos/video-imports'
diff --git a/server/tests/api/videos/video-imports.ts b/server/tests/api/videos/video-imports.ts
new file mode 100644
index 000000000..f21ade5c3
--- /dev/null
+++ b/server/tests/api/videos/video-imports.ts
@@ -0,0 +1,161 @@
1/* tslint:disable:no-unused-expression */
2
3import * as chai from 'chai'
4import 'mocha'
5import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
6import {
7 doubleFollow,
8 flushAndRunMultipleServers,
9 getMyUserInformation,
10 getMyVideos,
11 getVideo,
12 getVideosList,
13 killallServers,
14 ServerInfo,
15 setAccessTokensToServers
16} from '../../utils'
17import { waitJobs } from '../../utils/server/jobs'
18import { getMyVideoImports, getYoutubeVideoUrl, importVideo } from '../../utils/videos/video-imports'
19
20const expect = chai.expect
21
22describe('Test video imports', function () {
23 let servers: ServerInfo[] = []
24 let channelIdServer1: number
25 let channelIdServer2: number
26
27 async function checkVideoServer1 (url: string, id: number | string) {
28 const res = await getVideo(url, id)
29 const video: VideoDetails = res.body
30
31 expect(video.name).to.equal('small video - youtube')
32 expect(video.category.label).to.equal('News')
33 expect(video.licence.label).to.equal('Attribution')
34 expect(video.language.label).to.equal('Unknown')
35 expect(video.nsfw).to.be.false
36 expect(video.description).to.equal('this is a super description')
37 expect(video.tags).to.deep.equal([ 'tag1', 'tag2' ])
38
39 expect(video.files).to.have.lengthOf(1)
40 }
41
42 async function checkVideoServer2 (url: string, id: number | string) {
43 const res = await getVideo(url, id)
44 const video = res.body
45
46 expect(video.name).to.equal('my super name')
47 expect(video.category.label).to.equal('Entertainment')
48 expect(video.licence.label).to.equal('Public Domain Dedication')
49 expect(video.language.label).to.equal('English')
50 expect(video.nsfw).to.be.false
51 expect(video.description).to.equal('my super description')
52 expect(video.tags).to.deep.equal([ 'supertag1', 'supertag2' ])
53
54 expect(video.files).to.have.lengthOf(1)
55 }
56
57 before(async function () {
58 this.timeout(30000)
59
60 // Run servers
61 servers = await flushAndRunMultipleServers(2)
62
63 await setAccessTokensToServers(servers)
64
65 {
66 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
67 channelIdServer1 = res.body.videoChannels[ 0 ].id
68 }
69
70 {
71 const res = await getMyUserInformation(servers[1].url, servers[1].accessToken)
72 channelIdServer2 = res.body.videoChannels[ 0 ].id
73 }
74
75 await doubleFollow(servers[0], servers[1])
76 })
77
78 it('Should import a video on server 1', async function () {
79 this.timeout(60000)
80
81 const attributes = {
82 targetUrl: getYoutubeVideoUrl(),
83 channelId: channelIdServer1,
84 privacy: VideoPrivacy.PUBLIC
85 }
86 const res = await importVideo(servers[0].url, servers[0].accessToken, attributes)
87 expect(res.body.video.name).to.equal('small video - youtube')
88 })
89
90 it('Should list the video to import in my videos on server 1', async function () {
91 const res = await getMyVideos(servers[0].url, servers[0].accessToken, 0, 5)
92
93 expect(res.body.total).to.equal(1)
94
95 const videos = res.body.data
96 expect(videos).to.have.lengthOf(1)
97 expect(videos[0].name).to.equal('small video - youtube')
98 })
99
100 it('Should list the video to import in my imports on server 1', async function () {
101 const res = await getMyVideoImports(servers[0].url, servers[0].accessToken)
102
103 expect(res.body.total).to.equal(1)
104 const videoImports = res.body.data
105 expect(videoImports).to.have.lengthOf(1)
106
107 expect(videoImports[0].targetUrl).to.equal(getYoutubeVideoUrl())
108 expect(videoImports[0].video.name).to.equal('small video - youtube')
109 })
110
111 it('Should have the video listed on the two instances1', async function () {
112 this.timeout(120000)
113
114 await waitJobs(servers)
115
116 for (const server of servers) {
117 const res = await getVideosList(server.url)
118 expect(res.body.total).to.equal(1)
119 expect(res.body.data).to.have.lengthOf(1)
120
121 await checkVideoServer1(server.url, res.body.data[0].uuid)
122 }
123 })
124
125 it('Should import a video on server 2 with some fields', async function () {
126 this.timeout(60000)
127
128 const attributes = {
129 targetUrl: getYoutubeVideoUrl(),
130 channelId: channelIdServer1,
131 privacy: VideoPrivacy.PUBLIC,
132 category: 10,
133 licence: 7,
134 language: 'en',
135 name: 'my super name',
136 description: 'my super description',
137 tags: [ 'supertag1', 'supertag2' ]
138 }
139 const res = await importVideo(servers[1].url, servers[1].accessToken, attributes)
140 expect(res.body.video.name).to.equal('my super name')
141 })
142
143 it('Should have the video listed on the two instances', async function () {
144 this.timeout(120000)
145
146 await waitJobs(servers)
147
148 for (const server of servers) {
149 const res = await getVideosList(server.url)
150 expect(res.body.total).to.equal(2)
151 expect(res.body.data).to.have.lengthOf(2)
152
153 await checkVideoServer2(server.url, res.body.data[0].uuid)
154 await checkVideoServer1(server.url, res.body.data[1].uuid)
155 }
156 })
157
158 after(async function () {
159 killallServers(servers)
160 })
161})
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 129b40cdf..48f2ee4fc 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -3,17 +3,21 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import * as request from 'supertest' 5import * as request from 'supertest'
6const expect = chai.expect
7
8import { 6import {
9 ServerInfo,
10 flushTests, 7 flushTests,
8 getCustomConfig,
9 getVideosList,
10 killallServers,
11 makeHTMLRequest,
11 runServer, 12 runServer,
13 ServerInfo,
12 serverLogin, 14 serverLogin,
13 uploadVideo, 15 updateCustomConfig,
14 getVideosList, updateCustomConfig, getCustomConfig, killallServers, makeHTMLRequest 16 updateCustomSubConfig,
17 uploadVideo
15} from './utils' 18} from './utils'
16import { CustomConfig } from '../../shared/models/server/custom-config.model' 19
20const expect = chai.expect
17 21
18function checkIndexTags (html: string, title: string, description: string, css: string) { 22function checkIndexTags (html: string, title: string, description: string, css: string) {
19 expect(html).to.contain('<title>' + title + '</title>') 23 expect(html).to.contain('<title>' + title + '</title>')
@@ -117,63 +121,14 @@ describe('Test a client controllers', function () {
117 }) 121 })
118 122
119 it('Should update the customized configuration and have the correct index html tags', async function () { 123 it('Should update the customized configuration and have the correct index html tags', async function () {
120 const newCustomConfig: CustomConfig = { 124 await updateCustomSubConfig(server.url, server.accessToken, {
121 instance: { 125 instance: {
122 name: 'PeerTube updated',
123 shortDescription: 'my short description',
124 description: 'my super description',
125 terms: 'my super terms',
126 defaultClientRoute: '/videos/recently-added',
127 defaultNSFWPolicy: 'blur' as 'blur',
128 customizations: { 126 customizations: {
129 javascript: 'alert("coucou")', 127 javascript: 'alert("coucou")',
130 css: 'body { background-color: red; }' 128 css: 'body { background-color: red; }'
131 } 129 }
132 },
133 services: {
134 twitter: {
135 username: '@Kuja',
136 whitelisted: true
137 }
138 },
139 cache: {
140 previews: {
141 size: 2
142 },
143 captions: {
144 size: 3
145 }
146 },
147 signup: {
148 enabled: false,
149 limit: 5
150 },
151 admin: {
152 email: 'superadmin1@example.com'
153 },
154 user: {
155 videoQuota: 5242881
156 },
157 transcoding: {
158 enabled: true,
159 threads: 1,
160 resolutions: {
161 '240p': false,
162 '360p': true,
163 '480p': true,
164 '720p': false,
165 '1080p': false
166 }
167 },
168 import: {
169 videos: {
170 http: {
171 enabled: false
172 }
173 }
174 } 130 }
175 } 131 })
176 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
177 132
178 const res = await makeHTMLRequest(server.url, '/videos/trending') 133 const res = await makeHTMLRequest(server.url, '/videos/trending')
179 134
diff --git a/server/tests/utils/server/config.ts b/server/tests/utils/server/config.ts
index 57f95a603..e21614282 100644
--- a/server/tests/utils/server/config.ts
+++ b/server/tests/utils/server/config.ts
@@ -44,6 +44,69 @@ function updateCustomConfig (url: string, token: string, newCustomConfig: Custom
44 }) 44 })
45} 45}
46 46
47function updateCustomSubConfig (url: string, token: string, newConfig: any) {
48 const updateParams: CustomConfig = {
49 instance: {
50 name: 'PeerTube updated',
51 shortDescription: 'my short description',
52 description: 'my super description',
53 terms: 'my super terms',
54 defaultClientRoute: '/videos/recently-added',
55 defaultNSFWPolicy: 'blur',
56 customizations: {
57 javascript: 'alert("coucou")',
58 css: 'body { background-color: red; }'
59 }
60 },
61 services: {
62 twitter: {
63 username: '@MySuperUsername',
64 whitelisted: true
65 }
66 },
67 cache: {
68 previews: {
69 size: 2
70 },
71 captions: {
72 size: 3
73 }
74 },
75 signup: {
76 enabled: false,
77 limit: 5
78 },
79 admin: {
80 email: 'superadmin1@example.com'
81 },
82 user: {
83 videoQuota: 5242881
84 },
85 transcoding: {
86 enabled: true,
87 threads: 1,
88 resolutions: {
89 '240p': false,
90 '360p': true,
91 '480p': true,
92 '720p': false,
93 '1080p': false
94 }
95 },
96 import: {
97 videos: {
98 http: {
99 enabled: false
100 }
101 }
102 }
103 }
104
105 Object.assign(updateParams, newConfig)
106
107 return updateCustomConfig(url, token, updateParams)
108}
109
47function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) { 110function deleteCustomConfig (url: string, token: string, statusCodeExpected = 200) {
48 const path = '/api/v1/config/custom' 111 const path = '/api/v1/config/custom'
49 112
@@ -62,5 +125,6 @@ export {
62 getCustomConfig, 125 getCustomConfig,
63 updateCustomConfig, 126 updateCustomConfig,
64 getAbout, 127 getAbout,
65 deleteCustomConfig 128 deleteCustomConfig,
129 updateCustomSubConfig
66} 130}
diff --git a/server/tests/utils/videos/video-imports.ts b/server/tests/utils/videos/video-imports.ts
new file mode 100644
index 000000000..e0f916990
--- /dev/null
+++ b/server/tests/utils/videos/video-imports.ts
@@ -0,0 +1,37 @@
1import { VideoImportCreate } from '../../../../shared/models/videos'
2import { makeGetRequest, makePostBodyRequest } from '..'
3
4function getYoutubeVideoUrl () {
5 return 'https://youtu.be/msX3jv1XdvM'
6}
7
8function importVideo (url: string, token: string, attributes: VideoImportCreate) {
9 const path = '/api/v1/videos/imports'
10
11 return makePostBodyRequest({
12 url,
13 path,
14 token,
15 fields: attributes,
16 statusCodeExpected: 200
17 })
18}
19
20function getMyVideoImports (url: string, token: string) {
21 const path = '/api/v1/users/me/videos/imports'
22
23 return makeGetRequest({
24 url,
25 path,
26 token,
27 statusCodeExpected: 200
28 })
29}
30
31// ---------------------------------------------------------------------------
32
33export {
34 getYoutubeVideoUrl,
35 importVideo,
36 getMyVideoImports
37}