]>
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' | |
854f533c C |
5 | import { |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | FIXTURE_URLS, | |
9 | PeerTubeServer, | |
10 | setAccessTokensToServers, | |
11 | setDefaultVideoChannel | |
12 | } from '@shared/extra-utils' | |
3cf68b86 C |
13 | import { VideoDetails, VideoPrivacy } from '@shared/models' |
14 | ||
15 | const expect = chai.expect | |
16 | ||
17 | describe('Test config defaults', function () { | |
18 | let server: PeerTubeServer | |
19 | let channelId: number | |
20 | ||
21 | before(async function () { | |
22 | this.timeout(30000) | |
23 | ||
a9bfa85d | 24 | server = await createSingleServer(1) |
3cf68b86 C |
25 | await setAccessTokensToServers([ server ]) |
26 | await setDefaultVideoChannel([ server ]) | |
27 | ||
28 | channelId = server.store.channel.id | |
29 | }) | |
30 | ||
31 | describe('Default publish values', function () { | |
a9bfa85d C |
32 | |
33 | before(async function () { | |
34 | const overrideConfig = { | |
35 | defaults: { | |
36 | publish: { | |
37 | comments_enabled: false, | |
38 | download_enabled: false, | |
39 | privacy: VideoPrivacy.INTERNAL, | |
40 | licence: 4 | |
41 | } | |
42 | } | |
43 | } | |
44 | ||
45 | await server.kill() | |
46 | await server.run(overrideConfig) | |
47 | }) | |
48 | ||
3cf68b86 C |
49 | const attributes = { |
50 | name: 'video', | |
51 | downloadEnabled: undefined, | |
52 | commentsEnabled: undefined, | |
53 | licence: undefined, | |
54 | privacy: VideoPrivacy.PUBLIC // Privacy is mandatory for server | |
55 | } | |
56 | ||
57 | function checkVideo (video: VideoDetails) { | |
58 | expect(video.downloadEnabled).to.be.false | |
59 | expect(video.commentsEnabled).to.be.false | |
60 | expect(video.licence.id).to.equal(4) | |
61 | } | |
62 | ||
63 | before(async function () { | |
64 | await server.config.disableTranscoding() | |
65 | await server.config.enableImports() | |
66 | await server.config.enableLive({ allowReplay: false, transcoding: false }) | |
67 | }) | |
68 | ||
69 | it('Should have the correct server configuration', async function () { | |
70 | const config = await server.config.getConfig() | |
71 | ||
72 | expect(config.defaults.publish.commentsEnabled).to.be.false | |
73 | expect(config.defaults.publish.downloadEnabled).to.be.false | |
74 | expect(config.defaults.publish.licence).to.equal(4) | |
75 | expect(config.defaults.publish.privacy).to.equal(VideoPrivacy.INTERNAL) | |
76 | }) | |
77 | ||
78 | it('Should respect default values when uploading a video', async function () { | |
79 | for (const mode of [ 'legacy' as 'legacy', 'resumable' as 'resumable' ]) { | |
80 | const { id } = await server.videos.upload({ attributes, mode }) | |
81 | ||
82 | const video = await server.videos.get({ id }) | |
83 | checkVideo(video) | |
84 | } | |
85 | }) | |
86 | ||
87 | it('Should respect default values when importing a video using URL', async function () { | |
88 | const { video: { id } } = await server.imports.importVideo({ | |
89 | attributes: { | |
90 | ...attributes, | |
91 | channelId, | |
92 | targetUrl: FIXTURE_URLS.goodVideo | |
93 | } | |
94 | }) | |
95 | ||
96 | const video = await server.videos.get({ id }) | |
97 | checkVideo(video) | |
98 | }) | |
99 | ||
100 | it('Should respect default values when importing a video using magnet URI', async function () { | |
101 | const { video: { id } } = await server.imports.importVideo({ | |
102 | attributes: { | |
103 | ...attributes, | |
104 | channelId, | |
105 | magnetUri: FIXTURE_URLS.magnet | |
106 | } | |
107 | }) | |
108 | ||
109 | const video = await server.videos.get({ id }) | |
110 | checkVideo(video) | |
111 | }) | |
112 | ||
113 | it('Should respect default values when creating a live', async function () { | |
114 | const { id } = await server.live.create({ | |
115 | fields: { | |
116 | ...attributes, | |
117 | channelId | |
118 | } | |
119 | }) | |
120 | ||
121 | const video = await server.videos.get({ id }) | |
122 | checkVideo(video) | |
123 | }) | |
124 | }) | |
125 | ||
a9bfa85d C |
126 | describe('Default P2P values', function () { |
127 | ||
128 | before(async function () { | |
129 | const overrideConfig = { | |
130 | defaults: { | |
131 | p2p: { | |
132 | enabled: false | |
133 | } | |
134 | } | |
135 | } | |
136 | ||
137 | await server.kill() | |
138 | await server.run(overrideConfig) | |
139 | }) | |
140 | ||
141 | it('Should not have P2P enabled', async function () { | |
142 | const config = await server.config.getConfig() | |
143 | ||
144 | expect(config.defaults.p2p.enabled).to.be.false | |
145 | }) | |
146 | ||
147 | it('Should create a user with this default setting', async function () { | |
148 | await server.users.create({ username: 'user_p2p_1' }) | |
149 | const userToken = await server.login.getAccessToken('user_p2p_1') | |
150 | ||
151 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | |
152 | expect(p2pEnabled).to.be.false | |
153 | }) | |
154 | ||
155 | it('Should register a user with this default setting', async function () { | |
156 | await server.users.register({ username: 'user_p2p_2' }) | |
157 | ||
158 | const userToken = await server.login.getAccessToken('user_p2p_2') | |
159 | ||
160 | const { p2pEnabled } = await server.users.getMyInfo({ token: userToken }) | |
161 | expect(p2pEnabled).to.be.false | |
162 | }) | |
163 | }) | |
164 | ||
3cf68b86 C |
165 | after(async function () { |
166 | await cleanupTests([ server ]) | |
167 | }) | |
168 | }) |