]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
ee286591 C |
2 | |
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
a1587156 | 5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' |
ee286591 | 6 | import { |
b3af2601 | 7 | createVideoPlaylist, |
ee286591 | 8 | getPluginTestPath, |
a1587156 C |
9 | getVideo, |
10 | getVideoCategories, | |
11 | getVideoLanguages, | |
b3af2601 | 12 | getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies, |
ee286591 | 13 | installPlugin, |
ee286591 | 14 | setAccessTokensToServers, |
a1587156 C |
15 | uninstallPlugin, |
16 | uploadVideo | |
ee286591 | 17 | } from '../../../shared/extra-utils' |
b3af2601 | 18 | import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' |
f2eb23cd | 19 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' |
ee286591 C |
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 installPlugin({ | |
33 | url: server.url, | |
34 | accessToken: server.accessToken, | |
799ece6a | 35 | path: getPluginTestPath('-video-constants') |
ee286591 C |
36 | }) |
37 | }) | |
38 | ||
39 | it('Should have updated languages', async function () { | |
40 | const res = await getVideoLanguages(server.url) | |
41 | const languages = res.body | |
42 | ||
43 | expect(languages['en']).to.not.exist | |
44 | expect(languages['fr']).to.not.exist | |
45 | ||
46 | expect(languages['al_bhed']).to.equal('Al Bhed') | |
47 | expect(languages['al_bhed2']).to.equal('Al Bhed 2') | |
799ece6a | 48 | expect(languages['al_bhed3']).to.not.exist |
ee286591 C |
49 | }) |
50 | ||
51 | it('Should have updated categories', async function () { | |
52 | const res = await getVideoCategories(server.url) | |
53 | const categories = res.body | |
54 | ||
55 | expect(categories[1]).to.not.exist | |
56 | expect(categories[2]).to.not.exist | |
57 | ||
58 | expect(categories[42]).to.equal('Best category') | |
59 | expect(categories[43]).to.equal('High best category') | |
60 | }) | |
61 | ||
62 | it('Should have updated licences', async function () { | |
63 | const res = await getVideoLicences(server.url) | |
64 | const licences = res.body | |
65 | ||
66 | expect(licences[1]).to.not.exist | |
67 | expect(licences[7]).to.not.exist | |
68 | ||
69 | expect(licences[42]).to.equal('Best licence') | |
70 | expect(licences[43]).to.equal('High best licence') | |
71 | }) | |
72 | ||
b3af2601 C |
73 | it('Should have updated video privacies', async function () { |
74 | const res = await getVideoPrivacies(server.url) | |
75 | const privacies = res.body | |
76 | ||
77 | expect(privacies[1]).to.exist | |
78 | expect(privacies[2]).to.not.exist | |
79 | expect(privacies[3]).to.exist | |
80 | expect(privacies[4]).to.exist | |
81 | }) | |
82 | ||
83 | it('Should have updated playlist privacies', async function () { | |
84 | const res = await getVideoPlaylistPrivacies(server.url) | |
85 | const playlistPrivacies = res.body | |
86 | ||
87 | expect(playlistPrivacies[1]).to.exist | |
88 | expect(playlistPrivacies[2]).to.exist | |
89 | expect(playlistPrivacies[3]).to.not.exist | |
90 | }) | |
91 | ||
92 | it('Should not be able to create a video with this privacy', async function () { | |
93 | const attrs = { name: 'video', privacy: 2 } | |
f2eb23cd | 94 | await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) |
b3af2601 C |
95 | }) |
96 | ||
97 | it('Should not be able to create a video with this privacy', async function () { | |
98 | const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } | |
f2eb23cd RK |
99 | await createVideoPlaylist({ |
100 | url: server.url, | |
101 | token: server.accessToken, | |
102 | playlistAttrs: attrs, | |
103 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
104 | }) | |
b3af2601 C |
105 | }) |
106 | ||
ee286591 C |
107 | it('Should be able to upload a video with these values', async function () { |
108 | const attrs = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } | |
109 | const resUpload = await uploadVideo(server.url, server.accessToken, attrs) | |
110 | ||
111 | const res = await getVideo(server.url, resUpload.body.video.uuid) | |
112 | ||
113 | const video: VideoDetails = res.body | |
114 | expect(video.language.label).to.equal('Al Bhed 2') | |
115 | expect(video.licence.label).to.equal('Best licence') | |
116 | expect(video.category.label).to.equal('Best category') | |
117 | }) | |
118 | ||
b3af2601 | 119 | it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { |
799ece6a | 120 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' }) |
ee286591 C |
121 | |
122 | { | |
123 | const res = await getVideoLanguages(server.url) | |
124 | const languages = res.body | |
125 | ||
a1587156 C |
126 | expect(languages['en']).to.equal('English') |
127 | expect(languages['fr']).to.equal('French') | |
ee286591 | 128 | |
a1587156 C |
129 | expect(languages['al_bhed']).to.not.exist |
130 | expect(languages['al_bhed2']).to.not.exist | |
799ece6a | 131 | expect(languages['al_bhed3']).to.not.exist |
ee286591 C |
132 | } |
133 | ||
134 | { | |
135 | const res = await getVideoCategories(server.url) | |
136 | const categories = res.body | |
137 | ||
a1587156 C |
138 | expect(categories[1]).to.equal('Music') |
139 | expect(categories[2]).to.equal('Films') | |
ee286591 | 140 | |
a1587156 C |
141 | expect(categories[42]).to.not.exist |
142 | expect(categories[43]).to.not.exist | |
ee286591 C |
143 | } |
144 | ||
145 | { | |
146 | const res = await getVideoLicences(server.url) | |
147 | const licences = res.body | |
148 | ||
a1587156 C |
149 | expect(licences[1]).to.equal('Attribution') |
150 | expect(licences[7]).to.equal('Public Domain Dedication') | |
ee286591 | 151 | |
a1587156 C |
152 | expect(licences[42]).to.not.exist |
153 | expect(licences[43]).to.not.exist | |
ee286591 | 154 | } |
b3af2601 C |
155 | |
156 | { | |
157 | const res = await getVideoPrivacies(server.url) | |
158 | const privacies = res.body | |
159 | ||
160 | expect(privacies[1]).to.exist | |
161 | expect(privacies[2]).to.exist | |
162 | expect(privacies[3]).to.exist | |
163 | expect(privacies[4]).to.exist | |
164 | } | |
165 | ||
166 | { | |
167 | const res = await getVideoPlaylistPrivacies(server.url) | |
168 | const playlistPrivacies = res.body | |
169 | ||
170 | expect(playlistPrivacies[1]).to.exist | |
171 | expect(playlistPrivacies[2]).to.exist | |
172 | expect(playlistPrivacies[3]).to.exist | |
173 | } | |
ee286591 C |
174 | }) |
175 | ||
176 | after(async function () { | |
177 | await cleanupTests([ server ]) | |
178 | }) | |
179 | }) |