]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/channel-import-videos.ts
Add ability to list imports of a channel sync
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / channel-import-videos.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { FIXTURE_URLS } from '@server/tests/shared'
5 import { areHttpImportTestsDisabled } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
7 import { ChannelsCommand, cleanupTests, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
8
9 describe('Test videos import in a channel API validator', function () {
10 let server: PeerTubeServer
11 const userInfo = {
12 accessToken: '',
13 channelName: 'fake_channel',
14 id: -1,
15 videoQuota: -1,
16 videoQuotaDaily: -1
17 }
18 let command: ChannelsCommand
19
20 // ---------------------------------------------------------------
21
22 before(async function () {
23 this.timeout(30000)
24
25 server = await createSingleServer(1)
26
27 await setAccessTokensToServers([ server ])
28
29 const userCreds = {
30 username: 'fake',
31 password: 'fake_password'
32 }
33
34 {
35 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
36 userInfo.id = user.id
37 userInfo.accessToken = await server.login.getAccessToken(userCreds)
38 }
39
40 command = server.channels
41 })
42
43 it('Should fail when HTTP upload is disabled', async function () {
44 await server.config.disableImports()
45
46 await command.importVideos({
47 channelName: 'super_channel',
48 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
49 token: server.accessToken,
50 expectedStatus: HttpStatusCode.FORBIDDEN_403
51 })
52
53 await server.config.enableImports()
54 })
55
56 it('Should fail when externalChannelUrl is not provided', async function () {
57 await command.importVideos({
58 channelName: 'super_channel',
59 externalChannelUrl: null,
60 token: server.accessToken,
61 expectedStatus: HttpStatusCode.BAD_REQUEST_400
62 })
63 })
64
65 it('Should fail when externalChannelUrl is malformed', async function () {
66 await command.importVideos({
67 channelName: 'super_channel',
68 externalChannelUrl: 'not-a-url',
69 token: server.accessToken,
70 expectedStatus: HttpStatusCode.BAD_REQUEST_400
71 })
72 })
73
74 it('Should fail with a bad sync id', async function () {
75 await command.importVideos({
76 channelName: 'super_channel',
77 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
78 videoChannelSyncId: 'toto' as any,
79 token: server.accessToken,
80 expectedStatus: HttpStatusCode.BAD_REQUEST_400
81 })
82 })
83
84 it('Should fail with a unknown sync id', async function () {
85 await command.importVideos({
86 channelName: 'super_channel',
87 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
88 videoChannelSyncId: 42,
89 token: server.accessToken,
90 expectedStatus: HttpStatusCode.NOT_FOUND_404
91 })
92 })
93
94 it('Should fail with no authentication', async function () {
95 await command.importVideos({
96 channelName: 'super_channel',
97 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
98 token: null,
99 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
100 })
101 })
102
103 it('Should fail when sync is not owned by the user', async function () {
104 await command.importVideos({
105 channelName: 'super_channel',
106 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
107 token: userInfo.accessToken,
108 expectedStatus: HttpStatusCode.FORBIDDEN_403
109 })
110 })
111
112 it('Should fail when the user has no quota', async function () {
113 await server.users.update({
114 userId: userInfo.id,
115 videoQuota: 0
116 })
117
118 await command.importVideos({
119 channelName: 'fake_channel',
120 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
121 token: userInfo.accessToken,
122 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
123 })
124
125 await server.users.update({
126 userId: userInfo.id,
127 videoQuota: userInfo.videoQuota
128 })
129 })
130
131 it('Should fail when the user has no daily quota', async function () {
132 await server.users.update({
133 userId: userInfo.id,
134 videoQuotaDaily: 0
135 })
136
137 await command.importVideos({
138 channelName: 'fake_channel',
139 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
140 token: userInfo.accessToken,
141 expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413
142 })
143
144 await server.users.update({
145 userId: userInfo.id,
146 videoQuotaDaily: userInfo.videoQuotaDaily
147 })
148 })
149
150 it('Should succeed when sync is run by its owner', async function () {
151 if (!areHttpImportTestsDisabled()) return
152
153 await command.importVideos({
154 channelName: 'fake_channel',
155 externalChannelUrl: FIXTURE_URLS.youtubeChannel,
156 token: userInfo.accessToken
157 })
158 })
159
160 it('Should succeed when sync is run with root and for another user\'s channel', async function () {
161 if (!areHttpImportTestsDisabled()) return
162
163 await command.importVideos({
164 channelName: 'fake_channel',
165 externalChannelUrl: FIXTURE_URLS.youtubeChannel
166 })
167 })
168
169 after(async function () {
170 await cleanupTests([ server ])
171 })
172 })