]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/video-constants.ts
Introduce change ownership command
[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 2
ee286591 3import 'mocha'
ae2abfd3
C
4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils'
ee286591 6import {
ae2abfd3 7 cleanupTests,
b3af2601 8 createVideoPlaylist,
ae2abfd3 9 flushAndRunServer,
a1587156
C
10 getVideo,
11 getVideoCategories,
12 getVideoLanguages,
ae2abfd3
C
13 getVideoLicences,
14 getVideoPlaylistPrivacies,
15 getVideoPrivacies,
16 PluginsCommand,
17 ServerInfo,
ee286591 18 setAccessTokensToServers,
a1587156 19 uploadVideo
ae2abfd3
C
20} from '@shared/extra-utils'
21import { VideoDetails, VideoPlaylistPrivacy } from '@shared/models'
ee286591
C
22
23const expect = chai.expect
24
25describe('Test plugin altering video constants', function () {
26 let server: ServerInfo
27
28 before(async function () {
29 this.timeout(30000)
30
31 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
33
ae2abfd3 34 await server.pluginsCommand.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
ee286591
C
35 })
36
37 it('Should have updated languages', async function () {
38 const res = await getVideoLanguages(server.url)
39 const languages = res.body
40
41 expect(languages['en']).to.not.exist
42 expect(languages['fr']).to.not.exist
43
44 expect(languages['al_bhed']).to.equal('Al Bhed')
45 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
799ece6a 46 expect(languages['al_bhed3']).to.not.exist
ee286591
C
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 }
f2eb23cd 92 await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400)
b3af2601
C
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 }
f2eb23cd
RK
97 await createVideoPlaylist({
98 url: server.url,
99 token: server.accessToken,
100 playlistAttrs: attrs,
101 expectedStatus: HttpStatusCode.BAD_REQUEST_400
102 })
b3af2601
C
103 })
104
ee286591
C
105 it('Should be able to upload a video with these values', async function () {
106 const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
107 const resUpload = await uploadVideo(server.url, server.accessToken, attrs)
108
109 const res = await getVideo(server.url, resUpload.body.video.uuid)
110
111 const video: VideoDetails = res.body
112 expect(video.language.label).to.equal('Al Bhed 2')
113 expect(video.licence.label).to.equal('Best licence')
114 expect(video.category.label).to.equal('Best category')
115 })
116
b3af2601 117 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
ae2abfd3 118 await server.pluginsCommand.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
ee286591
C
119
120 {
121 const res = await getVideoLanguages(server.url)
122 const languages = res.body
123
a1587156
C
124 expect(languages['en']).to.equal('English')
125 expect(languages['fr']).to.equal('French')
ee286591 126
a1587156
C
127 expect(languages['al_bhed']).to.not.exist
128 expect(languages['al_bhed2']).to.not.exist
799ece6a 129 expect(languages['al_bhed3']).to.not.exist
ee286591
C
130 }
131
132 {
133 const res = await getVideoCategories(server.url)
134 const categories = res.body
135
a1587156
C
136 expect(categories[1]).to.equal('Music')
137 expect(categories[2]).to.equal('Films')
ee286591 138
a1587156
C
139 expect(categories[42]).to.not.exist
140 expect(categories[43]).to.not.exist
ee286591
C
141 }
142
143 {
144 const res = await getVideoLicences(server.url)
145 const licences = res.body
146
a1587156
C
147 expect(licences[1]).to.equal('Attribution')
148 expect(licences[7]).to.equal('Public Domain Dedication')
ee286591 149
a1587156
C
150 expect(licences[42]).to.not.exist
151 expect(licences[43]).to.not.exist
ee286591 152 }
b3af2601
C
153
154 {
155 const res = await getVideoPrivacies(server.url)
156 const privacies = res.body
157
158 expect(privacies[1]).to.exist
159 expect(privacies[2]).to.exist
160 expect(privacies[3]).to.exist
161 expect(privacies[4]).to.exist
162 }
163
164 {
165 const res = await getVideoPlaylistPrivacies(server.url)
166 const playlistPrivacies = res.body
167
168 expect(playlistPrivacies[1]).to.exist
169 expect(playlistPrivacies[2]).to.exist
170 expect(playlistPrivacies[3]).to.exist
171 }
ee286591
C
172 })
173
174 after(async function () {
175 await cleanupTests([ server ])
176 })
177})