]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/video-constants.ts
Merge branch 'master' into release/3.3.0
[github/Chocobozzz/PeerTube.git] / server / tests / plugins / video-constants.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
6 import {
7 createVideoPlaylist,
8 getPluginTestPath,
9 getVideo,
10 getVideoCategories,
11 getVideoLanguages,
12 getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies,
13 installPlugin,
14 setAccessTokensToServers,
15 uninstallPlugin,
16 uploadVideo
17 } from '../../../shared/extra-utils'
18 import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos'
19 import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
20
21 const expect = chai.expect
22
23 describe('Test plugin altering video constants', function () {
24 let server: ServerInfo
25
26 before(async function () {
27 this.timeout(30000)
28
29 server = await flushAndRunServer(1)
30 await setAccessTokensToServers([ server ])
31
32 await installPlugin({
33 url: server.url,
34 accessToken: server.accessToken,
35 path: getPluginTestPath('-video-constants')
36 })
37 })
38
39 it('Should have updated languages', async function () {
40 const res = await getVideoLanguages(server.url)
41 const languages = res.body
42
43 expect(languages['en']).to.not.exist
44 expect(languages['fr']).to.not.exist
45
46 expect(languages['al_bhed']).to.equal('Al Bhed')
47 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
48 expect(languages['al_bhed3']).to.not.exist
49 })
50
51 it('Should have updated categories', async function () {
52 const res = await getVideoCategories(server.url)
53 const categories = res.body
54
55 expect(categories[1]).to.not.exist
56 expect(categories[2]).to.not.exist
57
58 expect(categories[42]).to.equal('Best category')
59 expect(categories[43]).to.equal('High best category')
60 })
61
62 it('Should have updated licences', async function () {
63 const res = await getVideoLicences(server.url)
64 const licences = res.body
65
66 expect(licences[1]).to.not.exist
67 expect(licences[7]).to.not.exist
68
69 expect(licences[42]).to.equal('Best licence')
70 expect(licences[43]).to.equal('High best licence')
71 })
72
73 it('Should have updated video privacies', async function () {
74 const res = await getVideoPrivacies(server.url)
75 const privacies = res.body
76
77 expect(privacies[1]).to.exist
78 expect(privacies[2]).to.not.exist
79 expect(privacies[3]).to.exist
80 expect(privacies[4]).to.exist
81 })
82
83 it('Should have updated playlist privacies', async function () {
84 const res = await getVideoPlaylistPrivacies(server.url)
85 const playlistPrivacies = res.body
86
87 expect(playlistPrivacies[1]).to.exist
88 expect(playlistPrivacies[2]).to.exist
89 expect(playlistPrivacies[3]).to.not.exist
90 })
91
92 it('Should not be able to create a video with this privacy', async function () {
93 const attrs = { name: 'video', privacy: 2 }
94 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400)
95 })
96
97 it('Should not be able to create a video with this privacy', async function () {
98 const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
99 await createVideoPlaylist({
100 url: server.url,
101 token: server.accessToken,
102 playlistAttrs: attrs,
103 expectedStatus: HttpStatusCode.BAD_REQUEST_400
104 })
105 })
106
107 it('Should be able to upload a video with these values', async function () {
108 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
109 const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
110
111 const res = await getVideo(server.url, resUpload.body.video.uuid)
112
113 const video: VideoDetails = res.body
114 expect(video.language.label).to.equal('Al Bhed 2')
115 expect(video.licence.label).to.equal('Best licence')
116 expect(video.category.label).to.equal('Best category')
117 })
118
119 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
120 await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' })
121
122 {
123 const res = await getVideoLanguages(server.url)
124 const languages = res.body
125
126 expect(languages['en']).to.equal('English')
127 expect(languages['fr']).to.equal('French')
128
129 expect(languages['al_bhed']).to.not.exist
130 expect(languages['al_bhed2']).to.not.exist
131 expect(languages['al_bhed3']).to.not.exist
132 }
133
134 {
135 const res = await getVideoCategories(server.url)
136 const categories = res.body
137
138 expect(categories[1]).to.equal('Music')
139 expect(categories[2]).to.equal('Films')
140
141 expect(categories[42]).to.not.exist
142 expect(categories[43]).to.not.exist
143 }
144
145 {
146 const res = await getVideoLicences(server.url)
147 const licences = res.body
148
149 expect(licences[1]).to.equal('Attribution')
150 expect(licences[7]).to.equal('Public Domain Dedication')
151
152 expect(licences[42]).to.not.exist
153 expect(licences[43]).to.not.exist
154 }
155
156 {
157 const res = await getVideoPrivacies(server.url)
158 const privacies = res.body
159
160 expect(privacies[1]).to.exist
161 expect(privacies[2]).to.exist
162 expect(privacies[3]).to.exist
163 expect(privacies[4]).to.exist
164 }
165
166 {
167 const res = await getVideoPlaylistPrivacies(server.url)
168 const playlistPrivacies = res.body
169
170 expect(playlistPrivacies[1]).to.exist
171 expect(playlistPrivacies[2]).to.exist
172 expect(playlistPrivacies[3]).to.exist
173 }
174 })
175
176 after(async function () {
177 await cleanupTests([ server ])
178 })
179 })