]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/plugins/video-constants.ts
Use an object to represent a server
[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 'mocha'
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
6 import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
7 import { VideoPlaylistPrivacy } from '@shared/models'
8
9 const expect = chai.expect
10
11 describe('Test plugin altering video constants', function () {
12 let server: PeerTubeServer
13
14 before(async function () {
15 this.timeout(30000)
16
17 server = await createSingleServer(1)
18 await setAccessTokensToServers([ server ])
19
20 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
21 })
22
23 it('Should have updated languages', async function () {
24 const languages = await server.videos.getLanguages()
25
26 expect(languages['en']).to.not.exist
27 expect(languages['fr']).to.not.exist
28
29 expect(languages['al_bhed']).to.equal('Al Bhed')
30 expect(languages['al_bhed2']).to.equal('Al Bhed 2')
31 expect(languages['al_bhed3']).to.not.exist
32 })
33
34 it('Should have updated categories', async function () {
35 const categories = await server.videos.getCategories()
36
37 expect(categories[1]).to.not.exist
38 expect(categories[2]).to.not.exist
39
40 expect(categories[42]).to.equal('Best category')
41 expect(categories[43]).to.equal('High best category')
42 })
43
44 it('Should have updated licences', async function () {
45 const licences = await server.videos.getLicences()
46
47 expect(licences[1]).to.not.exist
48 expect(licences[7]).to.not.exist
49
50 expect(licences[42]).to.equal('Best licence')
51 expect(licences[43]).to.equal('High best licence')
52 })
53
54 it('Should have updated video privacies', async function () {
55 const privacies = await server.videos.getPrivacies()
56
57 expect(privacies[1]).to.exist
58 expect(privacies[2]).to.not.exist
59 expect(privacies[3]).to.exist
60 expect(privacies[4]).to.exist
61 })
62
63 it('Should have updated playlist privacies', async function () {
64 const playlistPrivacies = await server.playlists.getPrivacies()
65
66 expect(playlistPrivacies[1]).to.exist
67 expect(playlistPrivacies[2]).to.exist
68 expect(playlistPrivacies[3]).to.not.exist
69 })
70
71 it('Should not be able to create a video with this privacy', async function () {
72 const attributes = { name: 'video', privacy: 2 }
73 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
74 })
75
76 it('Should not be able to create a video with this privacy', async function () {
77 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
78 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
79 })
80
81 it('Should be able to upload a video with these values', async function () {
82 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
83 const { uuid } = await server.videos.upload({ attributes })
84
85 const video = await server.videos.get({ id: uuid })
86 expect(video.language.label).to.equal('Al Bhed 2')
87 expect(video.licence.label).to.equal('Best licence')
88 expect(video.category.label).to.equal('Best category')
89 })
90
91 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
92 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
93
94 {
95 const languages = await server.videos.getLanguages()
96
97 expect(languages['en']).to.equal('English')
98 expect(languages['fr']).to.equal('French')
99
100 expect(languages['al_bhed']).to.not.exist
101 expect(languages['al_bhed2']).to.not.exist
102 expect(languages['al_bhed3']).to.not.exist
103 }
104
105 {
106 const categories = await server.videos.getCategories()
107
108 expect(categories[1]).to.equal('Music')
109 expect(categories[2]).to.equal('Films')
110
111 expect(categories[42]).to.not.exist
112 expect(categories[43]).to.not.exist
113 }
114
115 {
116 const licences = await server.videos.getLicences()
117
118 expect(licences[1]).to.equal('Attribution')
119 expect(licences[7]).to.equal('Public Domain Dedication')
120
121 expect(licences[42]).to.not.exist
122 expect(licences[43]).to.not.exist
123 }
124
125 {
126 const privacies = await server.videos.getPrivacies()
127
128 expect(privacies[1]).to.exist
129 expect(privacies[2]).to.exist
130 expect(privacies[3]).to.exist
131 expect(privacies[4]).to.exist
132 }
133
134 {
135 const playlistPrivacies = await server.playlists.getPrivacies()
136
137 expect(playlistPrivacies[1]).to.exist
138 expect(playlistPrivacies[2]).to.exist
139 expect(playlistPrivacies[3]).to.exist
140 }
141 })
142
143 after(async function () {
144 await cleanupTests([ server ])
145 })
146 })