aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-16 10:42:24 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitc0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea (patch)
treebaf29753ac5d4598643e3bee719f8df0cc36c59d /server/tests/plugins
parent08642a765ea514a00f159db898edf14c376fbe6c (diff)
downloadPeerTube-c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea.tar.gz
PeerTube-c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea.tar.zst
PeerTube-c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea.zip
Refactor requests
Diffstat (limited to 'server/tests/plugins')
-rw-r--r--server/tests/plugins/external-auth.ts20
-rw-r--r--server/tests/plugins/filter-hooks.ts10
-rw-r--r--server/tests/plugins/id-and-pass-auth.ts2
-rw-r--r--server/tests/plugins/plugin-helpers.ts20
-rw-r--r--server/tests/plugins/plugin-router.ts14
-rw-r--r--server/tests/plugins/plugin-storage.ts4
-rw-r--r--server/tests/plugins/plugin-unloading.ts10
-rw-r--r--server/tests/plugins/video-constants.ts2
8 files changed, 41 insertions, 41 deletions
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index c0834a14c..a2828603a 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 decodeQueryString, 8 decodeQueryString,
@@ -20,15 +20,15 @@ async function loginExternal (options: {
20 authName: string 20 authName: string
21 username: string 21 username: string
22 query?: any 22 query?: any
23 statusCodeExpected?: HttpStatusCode 23 expectedStatus?: HttpStatusCode
24 statusCodeExpectedStep2?: HttpStatusCode 24 expectedStatusStep2?: HttpStatusCode
25}) { 25}) {
26 const res = await options.server.plugins.getExternalAuth({ 26 const res = await options.server.plugins.getExternalAuth({
27 npmName: options.npmName, 27 npmName: options.npmName,
28 npmVersion: '0.0.1', 28 npmVersion: '0.0.1',
29 authName: options.authName, 29 authName: options.authName,
30 query: options.query, 30 query: options.query,
31 expectedStatus: options.statusCodeExpected || HttpStatusCode.FOUND_302 31 expectedStatus: options.expectedStatus || HttpStatusCode.FOUND_302
32 }) 32 })
33 33
34 if (res.status !== HttpStatusCode.FOUND_302) return 34 if (res.status !== HttpStatusCode.FOUND_302) return
@@ -39,7 +39,7 @@ async function loginExternal (options: {
39 const resLogin = await options.server.login.loginUsingExternalToken({ 39 const resLogin = await options.server.login.loginUsingExternalToken({
40 username: options.username, 40 username: options.username,
41 externalAuthToken: externalAuthToken as string, 41 externalAuthToken: externalAuthToken as string,
42 expectedStatus: options.statusCodeExpectedStep2 42 expectedStatus: options.expectedStatusStep2
43 }) 43 })
44 44
45 return resLogin.body 45 return resLogin.body
@@ -268,7 +268,7 @@ describe('Test external auth plugins', function () {
268 username: 'kefka' 268 username: 'kefka'
269 }, 269 },
270 username: 'kefka', 270 username: 'kefka',
271 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 271 expectedStatus: HttpStatusCode.NOT_FOUND_404
272 }) 272 })
273 }) 273 })
274 274
@@ -293,7 +293,7 @@ describe('Test external auth plugins', function () {
293 username: 'cyan' 293 username: 'cyan'
294 }, 294 },
295 username: 'cyan', 295 username: 'cyan',
296 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 296 expectedStatus: HttpStatusCode.NOT_FOUND_404
297 }) 297 })
298 298
299 await server.login.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 299 await server.login.login({ user: { username: 'cyan', password: null }, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
@@ -307,7 +307,7 @@ describe('Test external auth plugins', function () {
307 npmName: 'test-external-auth-two', 307 npmName: 'test-external-auth-two',
308 authName: 'external-auth-4', 308 authName: 'external-auth-4',
309 username: 'kefka2', 309 username: 'kefka2',
310 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 310 expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
311 }) 311 })
312 312
313 await loginExternal({ 313 await loginExternal({
@@ -315,7 +315,7 @@ describe('Test external auth plugins', function () {
315 npmName: 'test-external-auth-two', 315 npmName: 'test-external-auth-two',
316 authName: 'external-auth-4', 316 authName: 'external-auth-4',
317 username: 'kefka', 317 username: 'kefka',
318 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 318 expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
319 }) 319 })
320 }) 320 })
321 321
@@ -327,7 +327,7 @@ describe('Test external auth plugins', function () {
327 npmName: 'test-external-auth-two', 327 npmName: 'test-external-auth-two',
328 authName: 'external-auth-6', 328 authName: 'external-auth-6',
329 username: 'existing_user', 329 username: 'existing_user',
330 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400 330 expectedStatusStep2: HttpStatusCode.BAD_REQUEST_400
331 }) 331 })
332 }) 332 })
333 333
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index df52bb3b5..ba84dd27a 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createMultipleServers, 8 createMultipleServers,
@@ -71,28 +71,28 @@ describe('Test plugin filter hooks', function () {
71 }) 71 })
72 72
73 it('Should run filter:api.accounts.videos.list.params', async function () { 73 it('Should run filter:api.accounts.videos.list.params', async function () {
74 const { data } = await servers[0].videos.listByAccount({ accountName: 'root', start: 0, count: 2 }) 74 const { data } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
75 75
76 // 1 plugin do +1 to the count parameter 76 // 1 plugin do +1 to the count parameter
77 expect(data).to.have.lengthOf(3) 77 expect(data).to.have.lengthOf(3)
78 }) 78 })
79 79
80 it('Should run filter:api.accounts.videos.list.result', async function () { 80 it('Should run filter:api.accounts.videos.list.result', async function () {
81 const { total } = await servers[0].videos.listByAccount({ accountName: 'root', start: 0, count: 2 }) 81 const { total } = await servers[0].videos.listByAccount({ handle: 'root', start: 0, count: 2 })
82 82
83 // Plugin do +2 to the total result 83 // Plugin do +2 to the total result
84 expect(total).to.equal(12) 84 expect(total).to.equal(12)
85 }) 85 })
86 86
87 it('Should run filter:api.video-channels.videos.list.params', async function () { 87 it('Should run filter:api.video-channels.videos.list.params', async function () {
88 const { data } = await servers[0].videos.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) 88 const { data } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
89 89
90 // 1 plugin do +3 to the count parameter 90 // 1 plugin do +3 to the count parameter
91 expect(data).to.have.lengthOf(5) 91 expect(data).to.have.lengthOf(5)
92 }) 92 })
93 93
94 it('Should run filter:api.video-channels.videos.list.result', async function () { 94 it('Should run filter:api.video-channels.videos.list.result', async function () {
95 const { total } = await servers[0].videos.listByChannel({ videoChannelName: 'root_channel', start: 0, count: 2 }) 95 const { total } = await servers[0].videos.listByChannel({ handle: 'root_channel', start: 0, count: 2 })
96 96
97 // Plugin do +3 to the total result 97 // Plugin do +3 to the total result
98 expect(total).to.equal(13) 98 expect(total).to.equal(13)
diff --git a/server/tests/plugins/id-and-pass-auth.ts b/server/tests/plugins/id-and-pass-auth.ts
index 981bcad91..a73d76caa 100644
--- a/server/tests/plugins/id-and-pass-auth.ts
+++ b/server/tests/plugins/id-and-pass-auth.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils' 6import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers, wait } from '@shared/extra-utils'
7import { UserRole } from '@shared/models' 7import { UserRole } from '@shared/models'
8 8
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index 1d87b84ae..5cb664bda 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { 6import {
7 checkVideoFilesWereRemoved, 7 checkVideoFilesWereRemoved,
8 cleanupTests, 8 cleanupTests,
@@ -24,7 +24,7 @@ function postCommand (server: PeerTubeServer, command: string, bodyArg?: object)
24 url: server.url, 24 url: server.url,
25 path: '/plugins/test-four/router/commander', 25 path: '/plugins/test-four/router/commander',
26 fields: body, 26 fields: body,
27 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 27 expectedStatus: HttpStatusCode.NO_CONTENT_204
28 }) 28 })
29} 29}
30 30
@@ -67,7 +67,7 @@ describe('Test plugin helpers', function () {
67 const res = await makeGetRequest({ 67 const res = await makeGetRequest({
68 url: servers[0].url, 68 url: servers[0].url,
69 path: '/plugins/test-four/router/server-config', 69 path: '/plugins/test-four/router/server-config',
70 statusCodeExpected: HttpStatusCode.OK_200 70 expectedStatus: HttpStatusCode.OK_200
71 }) 71 })
72 72
73 expect(res.body.serverConfig).to.exist 73 expect(res.body.serverConfig).to.exist
@@ -88,7 +88,7 @@ describe('Test plugin helpers', function () {
88 const res = await makeGetRequest({ 88 const res = await makeGetRequest({
89 url: servers[0].url, 89 url: servers[0].url,
90 path: '/plugins/test-four/router/static-route', 90 path: '/plugins/test-four/router/static-route',
91 statusCodeExpected: HttpStatusCode.OK_200 91 expectedStatus: HttpStatusCode.OK_200
92 }) 92 })
93 93
94 expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/') 94 expect(res.body.staticRoute).to.equal('/plugins/test-four/0.0.1/static/')
@@ -100,7 +100,7 @@ describe('Test plugin helpers', function () {
100 const res = await makeGetRequest({ 100 const res = await makeGetRequest({
101 url: servers[0].url, 101 url: servers[0].url,
102 path: baseRouter + 'router-route', 102 path: baseRouter + 'router-route',
103 statusCodeExpected: HttpStatusCode.OK_200 103 expectedStatus: HttpStatusCode.OK_200
104 }) 104 })
105 105
106 expect(res.body.routerRoute).to.equal(baseRouter) 106 expect(res.body.routerRoute).to.equal(baseRouter)
@@ -113,7 +113,7 @@ describe('Test plugin helpers', function () {
113 await makeGetRequest({ 113 await makeGetRequest({
114 url: servers[0].url, 114 url: servers[0].url,
115 path: '/plugins/test-four/router/user', 115 path: '/plugins/test-four/router/user',
116 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 116 expectedStatus: HttpStatusCode.NOT_FOUND_404
117 }) 117 })
118 }) 118 })
119 119
@@ -122,7 +122,7 @@ describe('Test plugin helpers', function () {
122 url: servers[0].url, 122 url: servers[0].url,
123 token: servers[0].accessToken, 123 token: servers[0].accessToken,
124 path: '/plugins/test-four/router/user', 124 path: '/plugins/test-four/router/user',
125 statusCodeExpected: HttpStatusCode.OK_200 125 expectedStatus: HttpStatusCode.OK_200
126 }) 126 })
127 127
128 expect(res.body.username).to.equal('root') 128 expect(res.body.username).to.equal('root')
@@ -140,12 +140,12 @@ describe('Test plugin helpers', function () {
140 this.timeout(60000) 140 this.timeout(60000)
141 141
142 { 142 {
143 const res = await await servers[0].videos.quickUpload({ name: 'video server 1' }) 143 const res = await servers[0].videos.quickUpload({ name: 'video server 1' })
144 videoUUIDServer1 = res.uuid 144 videoUUIDServer1 = res.uuid
145 } 145 }
146 146
147 { 147 {
148 await await servers[1].videos.quickUpload({ name: 'video server 2' }) 148 await servers[1].videos.quickUpload({ name: 'video server 2' })
149 } 149 }
150 150
151 await waitJobs(servers) 151 await waitJobs(servers)
@@ -224,7 +224,7 @@ describe('Test plugin helpers', function () {
224 let videoUUID: string 224 let videoUUID: string
225 225
226 before(async () => { 226 before(async () => {
227 const res = await await servers[0].videos.quickUpload({ name: 'video1' }) 227 const res = await servers[0].videos.quickUpload({ name: 'video1' })
228 videoUUID = res.uuid 228 videoUUID = res.uuid
229 }) 229 })
230 230
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts
index dec8ca4bb..becb7c47b 100644
--- a/server/tests/plugins/plugin-router.ts
+++ b/server/tests/plugins/plugin-router.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createSingleServer, 8 createSingleServer,
@@ -34,7 +34,7 @@ describe('Test plugin helpers', function () {
34 const res = await makeGetRequest({ 34 const res = await makeGetRequest({
35 url: server.url, 35 url: server.url,
36 path: path + 'ping', 36 path: path + 'ping',
37 statusCodeExpected: HttpStatusCode.OK_200 37 expectedStatus: HttpStatusCode.OK_200
38 }) 38 })
39 39
40 expect(res.body.message).to.equal('pong') 40 expect(res.body.message).to.equal('pong')
@@ -47,7 +47,7 @@ describe('Test plugin helpers', function () {
47 url: server.url, 47 url: server.url,
48 path: path + 'is-authenticated', 48 path: path + 'is-authenticated',
49 token: server.accessToken, 49 token: server.accessToken,
50 statusCodeExpected: 200 50 expectedStatus: 200
51 }) 51 })
52 52
53 expect(res.body.isAuthenticated).to.equal(true) 53 expect(res.body.isAuthenticated).to.equal(true)
@@ -55,7 +55,7 @@ describe('Test plugin helpers', function () {
55 const secRes = await makeGetRequest({ 55 const secRes = await makeGetRequest({
56 url: server.url, 56 url: server.url,
57 path: path + 'is-authenticated', 57 path: path + 'is-authenticated',
58 statusCodeExpected: 200 58 expectedStatus: 200
59 }) 59 })
60 60
61 expect(secRes.body.isAuthenticated).to.equal(false) 61 expect(secRes.body.isAuthenticated).to.equal(false)
@@ -74,7 +74,7 @@ describe('Test plugin helpers', function () {
74 url: server.url, 74 url: server.url,
75 path: path + 'form/post/mirror', 75 path: path + 'form/post/mirror',
76 fields: body, 76 fields: body,
77 statusCodeExpected: HttpStatusCode.OK_200 77 expectedStatus: HttpStatusCode.OK_200
78 }) 78 })
79 79
80 expect(res.body).to.deep.equal(body) 80 expect(res.body).to.deep.equal(body)
@@ -88,14 +88,14 @@ describe('Test plugin helpers', function () {
88 await makeGetRequest({ 88 await makeGetRequest({
89 url: server.url, 89 url: server.url,
90 path: path + 'ping', 90 path: path + 'ping',
91 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 91 expectedStatus: HttpStatusCode.NOT_FOUND_404
92 }) 92 })
93 93
94 await makePostBodyRequest({ 94 await makePostBodyRequest({
95 url: server.url, 95 url: server.url,
96 path: path + 'ping', 96 path: path + 'ping',
97 fields: {}, 97 fields: {},
98 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 98 expectedStatus: HttpStatusCode.NOT_FOUND_404
99 }) 99 })
100 } 100 }
101 }) 101 })
diff --git a/server/tests/plugins/plugin-storage.ts b/server/tests/plugins/plugin-storage.ts
index 5745914a5..90dafa3e1 100644
--- a/server/tests/plugins/plugin-storage.ts
+++ b/server/tests/plugins/plugin-storage.ts
@@ -4,7 +4,7 @@ import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { pathExists, readdir, readFile } from 'fs-extra' 5import { pathExists, readdir, readFile } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { HttpStatusCode } from '@shared/core-utils' 7import { HttpStatusCode } from '@shared/models'
8import { 8import {
9 cleanupTests, 9 cleanupTests,
10 createSingleServer, 10 createSingleServer,
@@ -63,7 +63,7 @@ describe('Test plugin storage', function () {
63 url: server.url, 63 url: server.url,
64 token: server.accessToken, 64 token: server.accessToken,
65 path: '/plugins/test-six/router/create-file', 65 path: '/plugins/test-six/router/create-file',
66 statusCodeExpected: HttpStatusCode.OK_200 66 expectedStatus: HttpStatusCode.OK_200
67 }) 67 })
68 68
69 const content = await getFileContent() 69 const content = await getFileContent()
diff --git a/server/tests/plugins/plugin-unloading.ts b/server/tests/plugins/plugin-unloading.ts
index 6c405b7f5..faf9cc599 100644
--- a/server/tests/plugins/plugin-unloading.ts
+++ b/server/tests/plugins/plugin-unloading.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 createSingleServer, 8 createSingleServer,
@@ -30,7 +30,7 @@ describe('Test plugins module unloading', function () {
30 const res = await makeGetRequest({ 30 const res = await makeGetRequest({
31 url: server.url, 31 url: server.url,
32 path: requestPath, 32 path: requestPath,
33 statusCodeExpected: HttpStatusCode.OK_200 33 expectedStatus: HttpStatusCode.OK_200
34 }) 34 })
35 35
36 expect(res.body.message).to.match(/^\d+$/) 36 expect(res.body.message).to.match(/^\d+$/)
@@ -41,7 +41,7 @@ describe('Test plugins module unloading', function () {
41 const res = await makeGetRequest({ 41 const res = await makeGetRequest({
42 url: server.url, 42 url: server.url,
43 path: requestPath, 43 path: requestPath,
44 statusCodeExpected: HttpStatusCode.OK_200 44 expectedStatus: HttpStatusCode.OK_200
45 }) 45 })
46 46
47 expect(res.body.message).to.be.equal(value) 47 expect(res.body.message).to.be.equal(value)
@@ -53,7 +53,7 @@ describe('Test plugins module unloading', function () {
53 await makeGetRequest({ 53 await makeGetRequest({
54 url: server.url, 54 url: server.url,
55 path: requestPath, 55 path: requestPath,
56 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 56 expectedStatus: HttpStatusCode.NOT_FOUND_404
57 }) 57 })
58 }) 58 })
59 59
@@ -63,7 +63,7 @@ describe('Test plugins module unloading', function () {
63 const res = await makeGetRequest({ 63 const res = await makeGetRequest({
64 url: server.url, 64 url: server.url,
65 path: requestPath, 65 path: requestPath,
66 statusCodeExpected: HttpStatusCode.OK_200 66 expectedStatus: HttpStatusCode.OK_200
67 }) 67 })
68 68
69 expect(res.body.message).to.match(/^\d+$/) 69 expect(res.body.message).to.match(/^\d+$/)
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index 953916e8e..dd3b40225 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -2,7 +2,7 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/models'
6import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils' 6import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
7import { VideoPlaylistPrivacy } from '@shared/models' 7import { VideoPlaylistPrivacy } from '@shared/models'
8 8