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