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