]>
Commit | Line | Data |
---|---|---|
3cf68b86 C |
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
c55e3d72 | 5 | import { FIXTURE_URLS } from '@server/tests/shared' |
3cf68b86 | 6 | import { VideoDetails, VideoPrivacy } from '@shared/models' |
c55e3d72 | 7 | import { cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel } from '@shared/server-commands' |
3cf68b86 C |
8 | |
9 | const expect = chai.expect | |
10 | ||
11 | describe('Test config defaults', function () { | |
12 | let server: PeerTubeServer | |
13 | let channelId: number | |
14 | ||
15 | before(async function () { | |
16 | this.timeout(30000) | |
17 | ||
a9bfa85d | 18 | server = await createSingleServer(1) |
3cf68b86 C |
19 | await setAccessTokensToServers([ server ]) |
20 | await setDefaultVideoChannel([ server ]) | |
21 | ||
22 | channelId = server.store.channel.id | |
23 | }) | |
24 | ||
25 | describe('Default publish values', function () { | |
a9bfa85d C |
26 | |
27 | before(async function () { | |
28 | const overrideConfig = { | |
29 | defaults: { | |
30 | publish: { | |
31 | comments_enabled: false, | |
32 | download_enabled: false, | |
33 | privacy: VideoPrivacy.INTERNAL, | |
34 | licence: 4 | |
35 | } | |
36 | } | |
37 | } | |
38 | ||
39 | await server.kill() | |
40 | await server.run(overrideConfig) | |
41 | }) | |
42 | ||
3cf68b86 C |
43 | const attributes = { |
44 | name: 'video', | |
45 | downloadEnabled: undefined, | |
46 | commentsEnabled: undefined, | |
47 | licence: undefined, | |
48 | privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server | |
49 | } | |
50 | ||
51 | function checkVideo (video: VideoDetails) { | |
52 | expect(video.downloadEnabled).to.be.false | |
53 | expect(video.commentsEnabled).to.be.false | |
54 | expect(video.licence.id).to.equal(4) | |
55 | } | |
56 | ||
57 | before(async function () { | |
58 | await server.config.disableTranscoding() | |
59 | await server.config.enableImports() | |
60 | await server.config.enableLive({ allowReplay: false, transcoding: false }) | |
61 | }) | |
62 | ||
63 | it('Should have the correct server configuration', async function () { | |
64 | const config = await server.config.getConfig() | |
65 | ||
66 | expect(config.defaults.publish.commentsEnabled).to.be.false | |
67 | expect(config.defaults.publish.downloadEnabled).to.be.false | |
68 | expect(config.defaults.publish.licence).to.equal(4) | |
69 | expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL) | |
70 | }) | |
71 | ||
72 | it('Should respect default values when uploading a video', async function () { | |
73 | for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) { | |
74 | const { id } = await server.videos.upload({ attributes, mode }) | |
75 | ||
76 | const video = await server.videos.get({ id }) | |
77 | checkVideo(video) | |
78 | } | |
79 | }) | |
80 | ||
81 | it('Should respect default values when importing a video using URL', async function () { | |
82 | const { video: { id } } = await server.imports.importVideo({ | |
83 | attributes: { | |
84 | ...attributes, | |
85 | channelId, | |
86 | targetUrl: FIXTURE_URLS.goodVideo | |
87 | } | |
88 | }) | |
89 | ||
90 | const video = await server.videos.get({ id }) | |
91 | checkVideo(video) | |
92 | }) | |
93 | ||
94 | it('Should respect default values when importing a video using magnet URI', async function () { | |
95 | const { video: { id } } = await server.imports.importVideo({ | |
96 | attributes: { | |
97 | ...attributes, | |
98 | channelId, | |
99 | magnetUri: FIXTURE_URLS.magnet | |
100 | } | |
101 | }) | |
102 | ||
103 | const video = await server.videos.get({ id }) | |
104 | checkVideo(video) | |
105 | }) | |
106 | ||
107 | it('Should respect default values when creating a live', async function () { | |
108 | const { id } = await server.live.create({ | |
109 | fields: { | |
110 | ...attributes, | |
111 | channelId | |
112 | } | |
113 | }) | |
114 | ||
115 | const video = await server.videos.get({ id }) | |
116 | checkVideo(video) | |
117 | }) | |
118 | }) | |
119 | ||
a9bfa85d C |
120 | describe('Default P2P values', function () { |
121 | ||
b65de1be C |
122 | describe('Webapp default value', function () { |
123 | ||
124 | before(async function () { | |
125 | const overrideConfig = { | |
126 | defaults: { | |
127 | p2p: { | |
128 | webapp: { | |
129 | enabled: false | |
130 | } | |
131 | } | |
a9bfa85d C |
132 | } |
133 | } | |
a9bfa85d | 134 | |
b65de1be C |
135 | await server.kill() |
136 | await server.run(overrideConfig) | |
137 | }) | |
a9bfa85d | 138 | |
b65de1be C |
139 | it('Should have appropriate P2P config', async function () { |
140 | const config = await server.config.getConfig() | |
a9bfa85d | 141 | |
b65de1be C |
142 | expect(config.defaults.p2p.webapp.enabled).to.be.false |
143 | expect(config.defaults.p2p.embed.enabled).to.be.true | |
144 | }) | |
145 | ||
146 | it('Should create a user with this default setting', async function () { | |
147 | await server.users.create({ username: 'user_p2p_1' }) | |
148 | const userToken = await server.login.getAccessToken('user_p2p_1') | |
149 | ||
150 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | |
151 | expect(p2pEnabled).to.be.false | |
152 | }) | |
a9bfa85d | 153 | |
b65de1be C |
154 | it('Should register a user with this default setting', async function () { |
155 | await server.users.register({ username: 'user_p2p_2' }) | |
a9bfa85d | 156 | |
b65de1be C |
157 | const userToken = await server.login.getAccessToken('user_p2p_2') |
158 | ||
159 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | |
160 | expect(p2pEnabled).to.be.false | |
161 | }) | |
a9bfa85d C |
162 | }) |
163 | ||
b65de1be C |
164 | describe('Embed default value', function () { |
165 | ||
166 | before(async function () { | |
167 | const overrideConfig = { | |
168 | defaults: { | |
169 | p2p: { | |
170 | embed: { | |
171 | enabled: false | |
172 | } | |
173 | } | |
174 | }, | |
175 | signup: { | |
176 | limit: 15 | |
177 | } | |
178 | } | |
179 | ||
180 | await server.kill() | |
181 | await server.run(overrideConfig) | |
182 | }) | |
183 | ||
184 | it('Should have appropriate P2P config', async function () { | |
185 | const config = await server.config.getConfig() | |
a9bfa85d | 186 | |
b65de1be C |
187 | expect(config.defaults.p2p.webapp.enabled).to.be.true |
188 | expect(config.defaults.p2p.embed.enabled).to.be.false | |
189 | }) | |
190 | ||
191 | it('Should create a user with this default setting', async function () { | |
192 | await server.users.create({ username: 'user_p2p_3' }) | |
193 | const userToken = await server.login.getAccessToken('user_p2p_3') | |
194 | ||
195 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | |
196 | expect(p2pEnabled).to.be.true | |
197 | }) | |
a9bfa85d | 198 | |
b65de1be C |
199 | it('Should register a user with this default setting', async function () { |
200 | await server.users.register({ username: 'user_p2p_4' }) | |
201 | ||
202 | const userToken = await server.login.getAccessToken('user_p2p_4') | |
203 | ||
204 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | |
205 | expect(p2pEnabled).to.be.true | |
206 | }) | |
a9bfa85d C |
207 | }) |
208 | }) | |
209 | ||
3cf68b86 C |
210 | after(async function () { |
211 | await cleanupTests([ server ]) | |
212 | }) | |
213 | }) |