]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/plugins/video-constants.ts
Use an object to represent a server
[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'
254d3579 6import { cleanupTests, createSingleServer, PluginsCommand, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
d23dd9fb 7import { VideoPlaylistPrivacy } from '@shared/models'
ee286591
C
8
9const expect = chai.expect
10
11describe('Test plugin altering video constants', function () {
254d3579 12 let server: PeerTubeServer
ee286591
C
13
14 before(async function () {
15 this.timeout(30000)
16
254d3579 17 server = await createSingleServer(1)
ee286591
C
18 await setAccessTokensToServers([ server ])
19
89d241a7 20 await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') })
ee286591
C
21 })
22
23 it('Should have updated languages', async function () {
89d241a7 24 const languages = await server.videos.getLanguages()
ee286591
C
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')
799ece6a 31 expect(languages['al_bhed3']).to.not.exist
ee286591
C
32 })
33
34 it('Should have updated categories', async function () {
89d241a7 35 const categories = await server.videos.getCategories()
ee286591
C
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 () {
89d241a7 45 const licences = await server.videos.getLicences()
ee286591
C
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
b3af2601 54 it('Should have updated video privacies', async function () {
89d241a7 55 const privacies = await server.videos.getPrivacies()
b3af2601
C
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 () {
89d241a7 64 const playlistPrivacies = await server.playlists.getPrivacies()
b3af2601
C
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 () {
d23dd9fb 72 const attributes = { name: 'video', privacy: 2 }
89d241a7 73 await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
b3af2601
C
74 })
75
76 it('Should not be able to create a video with this privacy', async function () {
e6346d59 77 const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE }
89d241a7 78 await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
b3af2601
C
79 })
80
ee286591 81 it('Should be able to upload a video with these values', async function () {
d23dd9fb 82 const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' }
89d241a7 83 const { uuid } = await server.videos.upload({ attributes })
ee286591 84
89d241a7 85 const video = await server.videos.get({ id: uuid })
ee286591
C
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
b3af2601 91 it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () {
89d241a7 92 await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' })
ee286591
C
93
94 {
89d241a7 95 const languages = await server.videos.getLanguages()
ee286591 96
a1587156
C
97 expect(languages['en']).to.equal('English')
98 expect(languages['fr']).to.equal('French')
ee286591 99
a1587156
C
100 expect(languages['al_bhed']).to.not.exist
101 expect(languages['al_bhed2']).to.not.exist
799ece6a 102 expect(languages['al_bhed3']).to.not.exist
ee286591
C
103 }
104
105 {
89d241a7 106 const categories = await server.videos.getCategories()
ee286591 107
a1587156
C
108 expect(categories[1]).to.equal('Music')
109 expect(categories[2]).to.equal('Films')
ee286591 110
a1587156
C
111 expect(categories[42]).to.not.exist
112 expect(categories[43]).to.not.exist
ee286591
C
113 }
114
115 {
89d241a7 116 const licences = await server.videos.getLicences()
ee286591 117
a1587156
C
118 expect(licences[1]).to.equal('Attribution')
119 expect(licences[7]).to.equal('Public Domain Dedication')
ee286591 120
a1587156
C
121 expect(licences[42]).to.not.exist
122 expect(licences[43]).to.not.exist
ee286591 123 }
b3af2601
C
124
125 {
89d241a7 126 const privacies = await server.videos.getPrivacies()
b3af2601
C
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 {
89d241a7 135 const playlistPrivacies = await server.playlists.getPrivacies()
b3af2601
C
136
137 expect(playlistPrivacies[1]).to.exist
138 expect(playlistPrivacies[2]).to.exist
139 expect(playlistPrivacies[3]).to.exist
140 }
ee286591
C
141 })
142
143 after(async function () {
144 await cleanupTests([ server ])
145 })
146})