diff options
author | Wicklow <123956049+wickloww@users.noreply.github.com> | 2023-03-02 13:50:55 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-02 14:50:55 +0100 |
commit | 692ae8c31caa5a404142c9f46e03fdc8dc5b233f (patch) | |
tree | 17d12edb5cfbfeddff2fd6f0d85b11c8954da89e /server/tests/api/videos | |
parent | c0a4982ebe27c89f296a0bbd518e938f09d1f054 (diff) | |
download | PeerTube-692ae8c31caa5a404142c9f46e03fdc8dc5b233f.tar.gz PeerTube-692ae8c31caa5a404142c9f46e03fdc8dc5b233f.tar.zst PeerTube-692ae8c31caa5a404142c9f46e03fdc8dc5b233f.zip |
Hotfix/filter subscription videos (#5665)
* Fix filters on subscription videos
* Add tests to common video filters
* Improve reliability when skipping subscrition path
* Better parameters for skipping subscription videos
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r-- | server/tests/api/videos/videos-common-filters.ts | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts index 160091861..1ab78ac49 100644 --- a/server/tests/api/videos/videos-common-filters.ts +++ b/server/tests/api/videos/videos-common-filters.ts | |||
@@ -20,6 +20,8 @@ describe('Test videos filter', function () { | |||
20 | let paths: string[] | 20 | let paths: string[] |
21 | let remotePaths: string[] | 21 | let remotePaths: string[] |
22 | 22 | ||
23 | const subscriptionVideosPath = '/api/v1/users/me/subscriptions/videos' | ||
24 | |||
23 | // --------------------------------------------------------------- | 25 | // --------------------------------------------------------------- |
24 | 26 | ||
25 | before(async function () { | 27 | before(async function () { |
@@ -49,6 +51,9 @@ describe('Test videos filter', function () { | |||
49 | const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } | 51 | const attributes = { name: 'private ' + server.serverNumber, privacy: VideoPrivacy.PRIVATE } |
50 | await server.videos.upload({ attributes }) | 52 | await server.videos.upload({ attributes }) |
51 | } | 53 | } |
54 | |||
55 | // Subscribing to itself | ||
56 | await server.subscriptions.add({ targetUri: 'root_channel@' + server.host }) | ||
52 | } | 57 | } |
53 | 58 | ||
54 | await doubleFollow(servers[0], servers[1]) | 59 | await doubleFollow(servers[0], servers[1]) |
@@ -57,7 +62,8 @@ describe('Test videos filter', function () { | |||
57 | `/api/v1/video-channels/root_channel/videos`, | 62 | `/api/v1/video-channels/root_channel/videos`, |
58 | `/api/v1/accounts/root/videos`, | 63 | `/api/v1/accounts/root/videos`, |
59 | '/api/v1/videos', | 64 | '/api/v1/videos', |
60 | '/api/v1/search/videos' | 65 | '/api/v1/search/videos', |
66 | subscriptionVideosPath | ||
61 | ] | 67 | ] |
62 | 68 | ||
63 | remotePaths = [ | 69 | remotePaths = [ |
@@ -70,10 +76,20 @@ describe('Test videos filter', function () { | |||
70 | 76 | ||
71 | describe('Check deprecated videos filter', function () { | 77 | describe('Check deprecated videos filter', function () { |
72 | 78 | ||
73 | async function getVideosNames (server: PeerTubeServer, token: string, filter: string, expectedStatus = HttpStatusCode.OK_200) { | 79 | async function getVideosNames (options: { |
80 | server: PeerTubeServer | ||
81 | token: string | ||
82 | filter: string | ||
83 | skipSubscription?: boolean | ||
84 | expectedStatus?: HttpStatusCode | ||
85 | }) { | ||
86 | const { server, token, filter, skipSubscription = false, expectedStatus = HttpStatusCode.OK_200 } = options | ||
87 | |||
74 | const videosResults: Video[][] = [] | 88 | const videosResults: Video[][] = [] |
75 | 89 | ||
76 | for (const path of paths) { | 90 | for (const path of paths) { |
91 | if (skipSubscription && path === subscriptionVideosPath) continue | ||
92 | |||
77 | const res = await makeGetRequest({ | 93 | const res = await makeGetRequest({ |
78 | url: server.url, | 94 | url: server.url, |
79 | path, | 95 | path, |
@@ -93,7 +109,7 @@ describe('Test videos filter', function () { | |||
93 | 109 | ||
94 | it('Should display local videos', async function () { | 110 | it('Should display local videos', async function () { |
95 | for (const server of servers) { | 111 | for (const server of servers) { |
96 | const namesResults = await getVideosNames(server, server.accessToken, 'local') | 112 | const namesResults = await getVideosNames({ server, token: server.accessToken, filter: 'local' }) |
97 | for (const names of namesResults) { | 113 | for (const names of namesResults) { |
98 | expect(names).to.have.lengthOf(1) | 114 | expect(names).to.have.lengthOf(1) |
99 | expect(names[0]).to.equal('public ' + server.serverNumber) | 115 | expect(names[0]).to.equal('public ' + server.serverNumber) |
@@ -105,7 +121,7 @@ describe('Test videos filter', function () { | |||
105 | for (const server of servers) { | 121 | for (const server of servers) { |
106 | for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { | 122 | for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { |
107 | 123 | ||
108 | const namesResults = await getVideosNames(server, token, 'all-local') | 124 | const namesResults = await getVideosNames({ server, token, filter: 'all-local', skipSubscription: true }) |
109 | for (const names of namesResults) { | 125 | for (const names of namesResults) { |
110 | expect(names).to.have.lengthOf(3) | 126 | expect(names).to.have.lengthOf(3) |
111 | 127 | ||
@@ -121,7 +137,7 @@ describe('Test videos filter', function () { | |||
121 | for (const server of servers) { | 137 | for (const server of servers) { |
122 | for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { | 138 | for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { |
123 | 139 | ||
124 | const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames(server, token, 'all') | 140 | const [ channelVideos, accountVideos, videos, searchVideos ] = await getVideosNames({ server, token, filter: 'all' }) |
125 | expect(channelVideos).to.have.lengthOf(3) | 141 | expect(channelVideos).to.have.lengthOf(3) |
126 | expect(accountVideos).to.have.lengthOf(3) | 142 | expect(accountVideos).to.have.lengthOf(3) |
127 | 143 | ||
@@ -162,17 +178,23 @@ describe('Test videos filter', function () { | |||
162 | return res.body.data as Video[] | 178 | return res.body.data as Video[] |
163 | } | 179 | } |
164 | 180 | ||
165 | async function getVideosNames (options: { | 181 | async function getVideosNames ( |
166 | server: PeerTubeServer | 182 | options: { |
167 | isLocal?: boolean | 183 | server: PeerTubeServer |
168 | include?: VideoInclude | 184 | isLocal?: boolean |
169 | privacyOneOf?: VideoPrivacy[] | 185 | include?: VideoInclude |
170 | token?: string | 186 | privacyOneOf?: VideoPrivacy[] |
171 | expectedStatus?: HttpStatusCode | 187 | token?: string |
172 | }) { | 188 | expectedStatus?: HttpStatusCode |
189 | skipSubscription?: boolean | ||
190 | } | ||
191 | ) { | ||
192 | const { skipSubscription = false } = options | ||
173 | const videosResults: string[][] = [] | 193 | const videosResults: string[][] = [] |
174 | 194 | ||
175 | for (const path of paths) { | 195 | for (const path of paths) { |
196 | if (skipSubscription && path === subscriptionVideosPath) continue | ||
197 | |||
176 | const videos = await listVideos({ ...options, path }) | 198 | const videos = await listVideos({ ...options, path }) |
177 | 199 | ||
178 | videosResults.push(videos.map(v => v.name)) | 200 | videosResults.push(videos.map(v => v.name)) |
@@ -196,12 +218,15 @@ describe('Test videos filter', function () { | |||
196 | for (const server of servers) { | 218 | for (const server of servers) { |
197 | for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { | 219 | for (const token of [ server.accessToken, server['moderatorAccessToken'] ]) { |
198 | 220 | ||
199 | const namesResults = await getVideosNames({ | 221 | const namesResults = await getVideosNames( |
200 | server, | 222 | { |
201 | token, | 223 | server, |
202 | isLocal: true, | 224 | token, |
203 | privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ] | 225 | isLocal: true, |
204 | }) | 226 | privacyOneOf: [ VideoPrivacy.UNLISTED, VideoPrivacy.PUBLIC, VideoPrivacy.PRIVATE ], |
227 | skipSubscription: true | ||
228 | } | ||
229 | ) | ||
205 | 230 | ||
206 | for (const names of namesResults) { | 231 | for (const names of namesResults) { |
207 | expect(names).to.have.lengthOf(3) | 232 | expect(names).to.have.lengthOf(3) |