aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/plugins/video-constants.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/plugins/video-constants.ts
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/plugins/video-constants.ts')
-rw-r--r--server/tests/plugins/video-constants.ts121
1 files changed, 45 insertions, 76 deletions
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts
index 7b1312f88..19cba6c2c 100644
--- a/server/tests/plugins/video-constants.ts
+++ b/server/tests/plugins/video-constants.ts
@@ -1,47 +1,33 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import * as chai from 'chai'
4import 'mocha' 3import 'mocha'
5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' 4import * as chai from 'chai'
6import { 5import {
7 createVideoPlaylist, 6 cleanupTests,
8 getPluginTestPath, 7 createSingleServer,
9 getVideo,
10 getVideoCategories,
11 getVideoLanguages,
12 getVideoLicences,
13 getVideoPlaylistPrivacies,
14 getVideoPrivacies,
15 installPlugin,
16 makeGetRequest, 8 makeGetRequest,
17 setAccessTokensToServers, 9 PeerTubeServer,
18 uninstallPlugin, 10 PluginsCommand,
19 uploadVideo 11 setAccessTokensToServers
20} from '../../../shared/extra-utils' 12} from '@shared/extra-utils'
21import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' 13import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
22import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
23 14
24const expect = chai.expect 15const expect = chai.expect
25 16
26describe('Test plugin altering video constants', function () { 17describe('Test plugin altering video constants', function () {
27 let server: ServerInfo 18 let server: PeerTubeServer
28 19
29 before(async function () { 20 before(async function () {
30 this.timeout(30000) 21 this.timeout(30000)
31 22
32 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
33 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
34 25
35 await installPlugin({ 26 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
36 url: server.url,
37 accessToken: server.accessToken,
38 path: getPluginTestPath('-video-constants')
39 })
40 }) 27 })
41 28
42 it('Should have updated languages', async function () { 29 it('Should have updated languages', async function () {
43 const res = await getVideoLanguages(server.url) 30 const languages = await server.videos.getLanguages()
44 const languages = res.body
45 31
46 expect(languages['en']).to.not.exist 32 expect(languages['en']).to.not.exist
47 expect(languages['fr']).to.not.exist 33 expect(languages['fr']).to.not.exist
@@ -52,8 +38,7 @@ describe('Test plugin altering video constants', function () {
52 }) 38 })
53 39
54 it('Should have updated categories', async function () { 40 it('Should have updated categories', async function () {
55 const res = await getVideoCategories(server.url) 41 const categories = await server.videos.getCategories()
56 const categories = res.body
57 42
58 expect(categories[1]).to.not.exist 43 expect(categories[1]).to.not.exist
59 expect(categories[2]).to.not.exist 44 expect(categories[2]).to.not.exist
@@ -63,8 +48,7 @@ describe('Test plugin altering video constants', function () {
63 }) 48 })
64 49
65 it('Should have updated licences', async function () { 50 it('Should have updated licences', async function () {
66 const res = await getVideoLicences(server.url) 51 const licences = await server.videos.getLicences()
67 const licences = res.body
68 52
69 expect(licences[1]).to.not.exist 53 expect(licences[1]).to.not.exist
70 expect(licences[7]).to.not.exist 54 expect(licences[7]).to.not.exist
@@ -74,8 +58,7 @@ describe('Test plugin altering video constants', function () {
74 }) 58 })
75 59
76 it('Should have updated video privacies', async function () { 60 it('Should have updated video privacies', async function () {
77 const res = await getVideoPrivacies(server.url) 61 const privacies = await server.videos.getPrivacies()
78 const privacies = res.body
79 62
80 expect(privacies[1]).to.exist 63 expect(privacies[1]).to.exist
81 expect(privacies[2]).to.not.exist 64 expect(privacies[2]).to.not.exist
@@ -84,8 +67,7 @@ describe('Test plugin altering video constants', function () {
84 }) 67 })
85 68
86 it('Should have updated playlist privacies', async function () { 69 it('Should have updated playlist privacies', async function () {
87 const res = await getVideoPlaylistPrivacies(server.url) 70 const playlistPrivacies = await server.playlists.getPrivacies()
88 const playlistPrivacies = res.body
89 71
90 expect(playlistPrivacies[1]).to.exist 72 expect(playlistPrivacies[1]).to.exist
91 expect(playlistPrivacies[2]).to.exist 73 expect(playlistPrivacies[2]).to.exist
@@ -93,38 +75,30 @@ describe('Test plugin altering video constants', function () {
93 }) 75 })
94 76
95 it('Should not be able to create a video with this privacy', async function () { 77 it('Should not be able to create a video with this privacy', async function () {
96 const attrs = { name: 'video', privacy: 2 } 78 const attributes = { name: 'video', privacy: 2 }
97 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) 79 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
98 }) 80 })
99 81
100 it('Should not be able to create a video with this privacy', async function () { 82 it('Should not be able to create a video with this privacy', async function () {
101 const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } 83 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
102 await createVideoPlaylist({ 84 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
103 url: server.url,
104 token: server.accessToken,
105 playlistAttrs: attrs,
106 expectedStatus: HttpStatusCode.BAD_REQUEST_400
107 })
108 }) 85 })
109 86
110 it('Should be able to upload a video with these values', async function () { 87 it('Should be able to upload a video with these values', async function () {
111 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } 88 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
112 const resUpload = await uploadVideo(server.url, server.accessToken, attrs) 89 const { uuid } = await server.videos.upload({ attributes })
113 90
114 const res = await getVideo(server.url, resUpload.body.video.uuid) 91 const video = await server.videos.get({ id: uuid })
115
116 const video: VideoDetails = res.body
117 expect(video.language.label).to.equal('Al Bhed 2') 92 expect(video.language.label).to.equal('Al Bhed 2')
118 expect(video.licence.label).to.equal('Best licence') 93 expect(video.licence.label).to.equal('Best licence')
119 expect(video.category.label).to.equal('Best category') 94 expect(video.category.label).to.equal('Best category')
120 }) 95 })
121 96
122 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { 97 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
123 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' }) 98 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
124 99
125 { 100 {
126 const res = await getVideoLanguages(server.url) 101 const languages = await server.videos.getLanguages()
127 const languages = res.body
128 102
129 expect(languages['en']).to.equal('English') 103 expect(languages['en']).to.equal('English')
130 expect(languages['fr']).to.equal('French') 104 expect(languages['fr']).to.equal('French')
@@ -135,8 +109,7 @@ describe('Test plugin altering video constants', function () {
135 } 109 }
136 110
137 { 111 {
138 const res = await getVideoCategories(server.url) 112 const categories = await server.videos.getCategories()
139 const categories = res.body
140 113
141 expect(categories[1]).to.equal('Music') 114 expect(categories[1]).to.equal('Music')
142 expect(categories[2]).to.equal('Films') 115 expect(categories[2]).to.equal('Films')
@@ -146,8 +119,7 @@ describe('Test plugin altering video constants', function () {
146 } 119 }
147 120
148 { 121 {
149 const res = await getVideoLicences(server.url) 122 const licences = await server.videos.getLicences()
150 const licences = res.body
151 123
152 expect(licences[1]).to.equal('Attribution') 124 expect(licences[1]).to.equal('Attribution')
153 expect(licences[7]).to.equal('Public Domain Dedication') 125 expect(licences[7]).to.equal('Public Domain Dedication')
@@ -157,8 +129,7 @@ describe('Test plugin altering video constants', function () {
157 } 129 }
158 130
159 { 131 {
160 const res = await getVideoPrivacies(server.url) 132 const privacies = await server.videos.getPrivacies()
161 const privacies = res.body
162 133
163 expect(privacies[1]).to.exist 134 expect(privacies[1]).to.exist
164 expect(privacies[2]).to.exist 135 expect(privacies[2]).to.exist
@@ -167,8 +138,7 @@ describe('Test plugin altering video constants', function () {
167 } 138 }
168 139
169 { 140 {
170 const res = await getVideoPlaylistPrivacies(server.url) 141 const playlistPrivacies = await server.playlists.getPrivacies()
171 const playlistPrivacies = res.body
172 142
173 expect(playlistPrivacies[1]).to.exist 143 expect(playlistPrivacies[1]).to.exist
174 expect(playlistPrivacies[2]).to.exist 144 expect(playlistPrivacies[2]).to.exist
@@ -177,35 +147,34 @@ describe('Test plugin altering video constants', function () {
177 }) 147 })
178 148
179 it('Should be able to reset categories', async function () { 149 it('Should be able to reset categories', async function () {
180 await installPlugin({ 150 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
181 url: server.url,
182 accessToken: server.accessToken,
183 path: getPluginTestPath('-video-constants')
184 })
185 151
186 let { body: categories } = await getVideoCategories(server.url) 152 {
153 const categories = await server.videos.getCategories()
187 154
188 expect(categories[1]).to.not.exist 155 expect(categories[1]).to.not.exist
189 expect(categories[2]).to.not.exist 156 expect(categories[2]).to.not.exist
190 157
191 expect(categories[42]).to.exist 158 expect(categories[42]).to.exist
192 expect(categories[43]).to.exist 159 expect(categories[43]).to.exist
160 }
193 161
194 await makeGetRequest({ 162 await makeGetRequest({
195 url: server.url, 163 url: server.url,
196 token: server.accessToken, 164 token: server.accessToken,
197 path: '/plugins/test-video-constants/router/reset-categories', 165 path: '/plugins/test-video-constants/router/reset-categories',
198 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 166 expectedStatus: HttpStatusCode.NO_CONTENT_204
199 }) 167 })
200 168
201 const { body } = await getVideoCategories(server.url) 169 {
202 categories = body 170 const categories = await server.videos.getCategories()
203 171
204 expect(categories[1]).to.exist 172 expect(categories[1]).to.exist
205 expect(categories[2]).to.exist 173 expect(categories[2]).to.exist
206 174
207 expect(categories[42]).to.not.exist 175 expect(categories[42]).to.not.exist
208 expect(categories[43]).to.not.exist 176 expect(categories[43]).to.not.exist
177 }
209 }) 178 })
210 179
211 after(async function () { 180 after(async function () {