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