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