aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-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
3 files changed, 197 insertions, 5 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})