diff options
Diffstat (limited to 'server/tests/plugins/video-constants.ts')
-rw-r--r-- | server/tests/plugins/video-constants.ts | 118 |
1 files changed, 61 insertions, 57 deletions
diff --git a/server/tests/plugins/video-constants.ts b/server/tests/plugins/video-constants.ts index eb014c596..19cba6c2c 100644 --- a/server/tests/plugins/video-constants.ts +++ b/server/tests/plugins/video-constants.ts | |||
@@ -1,44 +1,33 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | 3 | import 'mocha' |
5 | import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers' | 4 | import * as chai from 'chai' |
6 | import { | 5 | import { |
7 | createVideoPlaylist, | 6 | cleanupTests, |
8 | getPluginTestPath, | 7 | createSingleServer, |
9 | getVideo, | 8 | makeGetRequest, |
10 | getVideoCategories, | 9 | PeerTubeServer, |
11 | getVideoLanguages, | 10 | PluginsCommand, |
12 | getVideoLicences, getVideoPlaylistPrivacies, getVideoPrivacies, | 11 | setAccessTokensToServers |
13 | installPlugin, | 12 | } from '@shared/extra-utils' |
14 | setAccessTokensToServers, | 13 | import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models' |
15 | uninstallPlugin, | ||
16 | uploadVideo | ||
17 | } from '../../../shared/extra-utils' | ||
18 | import { VideoDetails, VideoPlaylistPrivacy } from '../../../shared/models/videos' | ||
19 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
20 | 14 | ||
21 | const expect = chai.expect | 15 | const expect = chai.expect |
22 | 16 | ||
23 | describe('Test plugin altering video constants', function () { | 17 | describe('Test plugin altering video constants', function () { |
24 | let server: ServerInfo | 18 | let server: PeerTubeServer |
25 | 19 | ||
26 | before(async function () { | 20 | before(async function () { |
27 | this.timeout(30000) | 21 | this.timeout(30000) |
28 | 22 | ||
29 | server = await flushAndRunServer(1) | 23 | server = await createSingleServer(1) |
30 | await setAccessTokensToServers([ server ]) | 24 | await setAccessTokensToServers([ server ]) |
31 | 25 | ||
32 | await installPlugin({ | 26 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) |
33 | url: server.url, | ||
34 | accessToken: server.accessToken, | ||
35 | path: getPluginTestPath('-video-constants') | ||
36 | }) | ||
37 | }) | 27 | }) |
38 | 28 | ||
39 | it('Should have updated languages', async function () { | 29 | it('Should have updated languages', async function () { |
40 | const res = await getVideoLanguages(server.url) | 30 | const languages = await server.videos.getLanguages() |
41 | const languages = res.body | ||
42 | 31 | ||
43 | expect(languages['en']).to.not.exist | 32 | expect(languages['en']).to.not.exist |
44 | expect(languages['fr']).to.not.exist | 33 | expect(languages['fr']).to.not.exist |
@@ -49,8 +38,7 @@ describe('Test plugin altering video constants', function () { | |||
49 | }) | 38 | }) |
50 | 39 | ||
51 | it('Should have updated categories', async function () { | 40 | it('Should have updated categories', async function () { |
52 | const res = await getVideoCategories(server.url) | 41 | const categories = await server.videos.getCategories() |
53 | const categories = res.body | ||
54 | 42 | ||
55 | expect(categories[1]).to.not.exist | 43 | expect(categories[1]).to.not.exist |
56 | expect(categories[2]).to.not.exist | 44 | expect(categories[2]).to.not.exist |
@@ -60,8 +48,7 @@ describe('Test plugin altering video constants', function () { | |||
60 | }) | 48 | }) |
61 | 49 | ||
62 | it('Should have updated licences', async function () { | 50 | it('Should have updated licences', async function () { |
63 | const res = await getVideoLicences(server.url) | 51 | const licences = await server.videos.getLicences() |
64 | const licences = res.body | ||
65 | 52 | ||
66 | expect(licences[1]).to.not.exist | 53 | expect(licences[1]).to.not.exist |
67 | expect(licences[7]).to.not.exist | 54 | expect(licences[7]).to.not.exist |
@@ -71,8 +58,7 @@ describe('Test plugin altering video constants', function () { | |||
71 | }) | 58 | }) |
72 | 59 | ||
73 | it('Should have updated video privacies', async function () { | 60 | it('Should have updated video privacies', async function () { |
74 | const res = await getVideoPrivacies(server.url) | 61 | const privacies = await server.videos.getPrivacies() |
75 | const privacies = res.body | ||
76 | 62 | ||
77 | expect(privacies[1]).to.exist | 63 | expect(privacies[1]).to.exist |
78 | expect(privacies[2]).to.not.exist | 64 | expect(privacies[2]).to.not.exist |
@@ -81,8 +67,7 @@ describe('Test plugin altering video constants', function () { | |||
81 | }) | 67 | }) |
82 | 68 | ||
83 | it('Should have updated playlist privacies', async function () { | 69 | it('Should have updated playlist privacies', async function () { |
84 | const res = await getVideoPlaylistPrivacies(server.url) | 70 | const playlistPrivacies = await server.playlists.getPrivacies() |
85 | const playlistPrivacies = res.body | ||
86 | 71 | ||
87 | expect(playlistPrivacies[1]).to.exist | 72 | expect(playlistPrivacies[1]).to.exist |
88 | expect(playlistPrivacies[2]).to.exist | 73 | expect(playlistPrivacies[2]).to.exist |
@@ -90,38 +75,30 @@ describe('Test plugin altering video constants', function () { | |||
90 | }) | 75 | }) |
91 | 76 | ||
92 | it('Should not be able to create a video with this privacy', async function () { | 77 | it('Should not be able to create a video with this privacy', async function () { |
93 | const attrs = { name: 'video', privacy: 2 } | 78 | const attributes = { name: 'video', privacy: 2 } |
94 | await uploadVideo(server.url, server.accessToken, attrs, HttpStatusCode.BAD_REQUEST_400) | 79 | await server.videos.upload({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
95 | }) | 80 | }) |
96 | 81 | ||
97 | it('Should not be able to create a video with this privacy', async function () { | 82 | it('Should not be able to create a video with this privacy', async function () { |
98 | const attrs = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } | 83 | const attributes = { displayName: 'video playlist', privacy: VideoPlaylistPrivacy.PRIVATE } |
99 | await createVideoPlaylist({ | 84 | await server.playlists.create({ attributes, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) |
100 | url: server.url, | ||
101 | token: server.accessToken, | ||
102 | playlistAttrs: attrs, | ||
103 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
104 | }) | ||
105 | }) | 85 | }) |
106 | 86 | ||
107 | it('Should be able to upload a video with these values', async function () { | 87 | 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' } | 88 | const attributes = { name: 'video', category: 42, licence: 42, language: 'al_bhed2' } |
109 | const resUpload = await uploadVideo(server.url, server.accessToken, attrs) | 89 | const { uuid } = await server.videos.upload({ attributes }) |
110 | 90 | ||
111 | const res = await getVideo(server.url, resUpload.body.video.uuid) | 91 | const video = await server.videos.get({ id: uuid }) |
112 | |||
113 | const video: VideoDetails = res.body | ||
114 | expect(video.language.label).to.equal('Al Bhed 2') | 92 | expect(video.language.label).to.equal('Al Bhed 2') |
115 | expect(video.licence.label).to.equal('Best licence') | 93 | expect(video.licence.label).to.equal('Best licence') |
116 | expect(video.category.label).to.equal('Best category') | 94 | expect(video.category.label).to.equal('Best category') |
117 | }) | 95 | }) |
118 | 96 | ||
119 | it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { | 97 | it('Should uninstall the plugin and reset languages, categories, licences and privacies', async function () { |
120 | await uninstallPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-test-video-constants' }) | 98 | await server.plugins.uninstall({ npmName: 'peertube-plugin-test-video-constants' }) |
121 | 99 | ||
122 | { | 100 | { |
123 | const res = await getVideoLanguages(server.url) | 101 | const languages = await server.videos.getLanguages() |
124 | const languages = res.body | ||
125 | 102 | ||
126 | expect(languages['en']).to.equal('English') | 103 | expect(languages['en']).to.equal('English') |
127 | expect(languages['fr']).to.equal('French') | 104 | expect(languages['fr']).to.equal('French') |
@@ -132,8 +109,7 @@ describe('Test plugin altering video constants', function () { | |||
132 | } | 109 | } |
133 | 110 | ||
134 | { | 111 | { |
135 | const res = await getVideoCategories(server.url) | 112 | const categories = await server.videos.getCategories() |
136 | const categories = res.body | ||
137 | 113 | ||
138 | expect(categories[1]).to.equal('Music') | 114 | expect(categories[1]).to.equal('Music') |
139 | expect(categories[2]).to.equal('Films') | 115 | expect(categories[2]).to.equal('Films') |
@@ -143,8 +119,7 @@ describe('Test plugin altering video constants', function () { | |||
143 | } | 119 | } |
144 | 120 | ||
145 | { | 121 | { |
146 | const res = await getVideoLicences(server.url) | 122 | const licences = await server.videos.getLicences() |
147 | const licences = res.body | ||
148 | 123 | ||
149 | expect(licences[1]).to.equal('Attribution') | 124 | expect(licences[1]).to.equal('Attribution') |
150 | expect(licences[7]).to.equal('Public Domain Dedication') | 125 | expect(licences[7]).to.equal('Public Domain Dedication') |
@@ -154,8 +129,7 @@ describe('Test plugin altering video constants', function () { | |||
154 | } | 129 | } |
155 | 130 | ||
156 | { | 131 | { |
157 | const res = await getVideoPrivacies(server.url) | 132 | const privacies = await server.videos.getPrivacies() |
158 | const privacies = res.body | ||
159 | 133 | ||
160 | expect(privacies[1]).to.exist | 134 | expect(privacies[1]).to.exist |
161 | expect(privacies[2]).to.exist | 135 | expect(privacies[2]).to.exist |
@@ -164,8 +138,7 @@ describe('Test plugin altering video constants', function () { | |||
164 | } | 138 | } |
165 | 139 | ||
166 | { | 140 | { |
167 | const res = await getVideoPlaylistPrivacies(server.url) | 141 | const playlistPrivacies = await server.playlists.getPrivacies() |
168 | const playlistPrivacies = res.body | ||
169 | 142 | ||
170 | expect(playlistPrivacies[1]).to.exist | 143 | expect(playlistPrivacies[1]).to.exist |
171 | expect(playlistPrivacies[2]).to.exist | 144 | expect(playlistPrivacies[2]).to.exist |
@@ -173,6 +146,37 @@ describe('Test plugin altering video constants', function () { | |||
173 | } | 146 | } |
174 | }) | 147 | }) |
175 | 148 | ||
149 | it('Should be able to reset categories', async function () { | ||
150 | await server.plugins.install({ path: PluginsCommand.getPluginTestPath('-video-constants') }) | ||
151 | |||
152 | { | ||
153 | const categories = await server.videos.getCategories() | ||
154 | |||
155 | expect(categories[1]).to.not.exist | ||
156 | expect(categories[2]).to.not.exist | ||
157 | |||
158 | expect(categories[42]).to.exist | ||
159 | expect(categories[43]).to.exist | ||
160 | } | ||
161 | |||
162 | await makeGetRequest({ | ||
163 | url: server.url, | ||
164 | token: server.accessToken, | ||
165 | path: '/plugins/test-video-constants/router/reset-categories', | ||
166 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
167 | }) | ||
168 | |||
169 | { | ||
170 | const categories = await server.videos.getCategories() | ||
171 | |||
172 | expect(categories[1]).to.exist | ||
173 | expect(categories[2]).to.exist | ||
174 | |||
175 | expect(categories[42]).to.not.exist | ||
176 | expect(categories[43]).to.not.exist | ||
177 | } | ||
178 | }) | ||
179 | |||
176 | after(async function () { | 180 | after(async function () { |
177 | await cleanupTests([ server ]) | 181 | await cleanupTests([ server ]) |
178 | }) | 182 | }) |