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