diff options
Diffstat (limited to 'server/tests/api/search/search-activitypub-video-playlists.ts')
-rw-r--r-- | server/tests/api/search/search-activitypub-video-playlists.ts | 150 |
1 files changed, 67 insertions, 83 deletions
diff --git a/server/tests/api/search/search-activitypub-video-playlists.ts b/server/tests/api/search/search-activitypub-video-playlists.ts index 4c08e9548..33ca7be12 100644 --- a/server/tests/api/search/search-activitypub-video-playlists.ts +++ b/server/tests/api/search/search-activitypub-video-playlists.ts | |||
@@ -3,113 +3,102 @@ | |||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { | 5 | import { |
6 | addVideoInPlaylist, | ||
7 | cleanupTests, | 6 | cleanupTests, |
8 | createVideoPlaylist, | 7 | createMultipleServers, |
9 | deleteVideoPlaylist, | 8 | PeerTubeServer, |
10 | flushAndRunMultipleServers, | 9 | SearchCommand, |
11 | getVideoPlaylistsList, | ||
12 | searchVideoPlaylists, | ||
13 | ServerInfo, | ||
14 | setAccessTokensToServers, | 10 | setAccessTokensToServers, |
15 | setDefaultVideoChannel, | 11 | setDefaultVideoChannel, |
16 | uploadVideoAndGetId, | 12 | wait, |
17 | wait | 13 | waitJobs |
18 | } from '../../../../shared/extra-utils' | 14 | } from '@shared/extra-utils' |
19 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 15 | import { VideoPlaylistPrivacy } from '@shared/models' |
20 | import { VideoPlaylist, VideoPlaylistPrivacy } from '../../../../shared/models/videos' | ||
21 | 16 | ||
22 | const expect = chai.expect | 17 | const expect = chai.expect |
23 | 18 | ||
24 | describe('Test ActivityPub playlists search', function () { | 19 | describe('Test ActivityPub playlists search', function () { |
25 | let servers: ServerInfo[] | 20 | let servers: PeerTubeServer[] |
26 | let playlistServer1UUID: string | 21 | let playlistServer1UUID: string |
27 | let playlistServer2UUID: string | 22 | let playlistServer2UUID: string |
28 | let video2Server2: string | 23 | let video2Server2: string |
29 | 24 | ||
25 | let command: SearchCommand | ||
26 | |||
30 | before(async function () { | 27 | before(async function () { |
31 | this.timeout(120000) | 28 | this.timeout(120000) |
32 | 29 | ||
33 | servers = await flushAndRunMultipleServers(2) | 30 | servers = await createMultipleServers(2) |
34 | 31 | ||
35 | await setAccessTokensToServers(servers) | 32 | await setAccessTokensToServers(servers) |
36 | await setDefaultVideoChannel(servers) | 33 | await setDefaultVideoChannel(servers) |
37 | 34 | ||
38 | { | 35 | { |
39 | const video1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid | 36 | const video1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid |
40 | const video2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid | 37 | const video2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid |
41 | 38 | ||
42 | const attributes = { | 39 | const attributes = { |
43 | displayName: 'playlist 1 on server 1', | 40 | displayName: 'playlist 1 on server 1', |
44 | privacy: VideoPlaylistPrivacy.PUBLIC, | 41 | privacy: VideoPlaylistPrivacy.PUBLIC, |
45 | videoChannelId: servers[0].videoChannel.id | 42 | videoChannelId: servers[0].store.channel.id |
46 | } | 43 | } |
47 | const res = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs: attributes }) | 44 | const created = await servers[0].playlists.create({ attributes }) |
48 | playlistServer1UUID = res.body.videoPlaylist.uuid | 45 | playlistServer1UUID = created.uuid |
49 | 46 | ||
50 | for (const videoId of [ video1, video2 ]) { | 47 | for (const videoId of [ video1, video2 ]) { |
51 | await addVideoInPlaylist({ | 48 | await servers[0].playlists.addElement({ playlistId: playlistServer1UUID, attributes: { videoId } }) |
52 | url: servers[0].url, | ||
53 | token: servers[0].accessToken, | ||
54 | playlistId: playlistServer1UUID, | ||
55 | elementAttrs: { videoId } | ||
56 | }) | ||
57 | } | 49 | } |
58 | } | 50 | } |
59 | 51 | ||
60 | { | 52 | { |
61 | const videoId = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 1' })).uuid | 53 | const videoId = (await servers[1].videos.quickUpload({ name: 'video 1' })).uuid |
62 | video2Server2 = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 2' })).uuid | 54 | video2Server2 = (await servers[1].videos.quickUpload({ name: 'video 2' })).uuid |
63 | 55 | ||
64 | const attributes = { | 56 | const attributes = { |
65 | displayName: 'playlist 1 on server 2', | 57 | displayName: 'playlist 1 on server 2', |
66 | privacy: VideoPlaylistPrivacy.PUBLIC, | 58 | privacy: VideoPlaylistPrivacy.PUBLIC, |
67 | videoChannelId: servers[1].videoChannel.id | 59 | videoChannelId: servers[1].store.channel.id |
68 | } | 60 | } |
69 | const res = await createVideoPlaylist({ url: servers[1].url, token: servers[1].accessToken, playlistAttrs: attributes }) | 61 | const created = await servers[1].playlists.create({ attributes }) |
70 | playlistServer2UUID = res.body.videoPlaylist.uuid | 62 | playlistServer2UUID = created.uuid |
71 | 63 | ||
72 | await addVideoInPlaylist({ | 64 | await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId } }) |
73 | url: servers[1].url, | ||
74 | token: servers[1].accessToken, | ||
75 | playlistId: playlistServer2UUID, | ||
76 | elementAttrs: { videoId } | ||
77 | }) | ||
78 | } | 65 | } |
79 | 66 | ||
80 | await waitJobs(servers) | 67 | await waitJobs(servers) |
68 | |||
69 | command = servers[0].search | ||
81 | }) | 70 | }) |
82 | 71 | ||
83 | it('Should not find a remote playlist', async function () { | 72 | it('Should not find a remote playlist', async function () { |
84 | { | 73 | { |
85 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/43' | 74 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/43' |
86 | const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) | 75 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
87 | 76 | ||
88 | expect(res.body.total).to.equal(0) | 77 | expect(body.total).to.equal(0) |
89 | expect(res.body.data).to.be.an('array') | 78 | expect(body.data).to.be.an('array') |
90 | expect(res.body.data).to.have.lengthOf(0) | 79 | expect(body.data).to.have.lengthOf(0) |
91 | } | 80 | } |
92 | 81 | ||
93 | { | 82 | { |
94 | // Without token | 83 | // Without token |
95 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID | 84 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID |
96 | const res = await searchVideoPlaylists(servers[0].url, search) | 85 | const body = await command.searchPlaylists({ search }) |
97 | 86 | ||
98 | expect(res.body.total).to.equal(0) | 87 | expect(body.total).to.equal(0) |
99 | expect(res.body.data).to.be.an('array') | 88 | expect(body.data).to.be.an('array') |
100 | expect(res.body.data).to.have.lengthOf(0) | 89 | expect(body.data).to.have.lengthOf(0) |
101 | } | 90 | } |
102 | }) | 91 | }) |
103 | 92 | ||
104 | it('Should search a local playlist', async function () { | 93 | it('Should search a local playlist', async function () { |
105 | const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID | 94 | const search = 'http://localhost:' + servers[0].port + '/video-playlists/' + playlistServer1UUID |
106 | const res = await searchVideoPlaylists(servers[0].url, search) | 95 | const body = await command.searchPlaylists({ search }) |
107 | 96 | ||
108 | expect(res.body.total).to.equal(1) | 97 | expect(body.total).to.equal(1) |
109 | expect(res.body.data).to.be.an('array') | 98 | expect(body.data).to.be.an('array') |
110 | expect(res.body.data).to.have.lengthOf(1) | 99 | expect(body.data).to.have.lengthOf(1) |
111 | expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') | 100 | expect(body.data[0].displayName).to.equal('playlist 1 on server 1') |
112 | expect(res.body.data[0].videosLength).to.equal(2) | 101 | expect(body.data[0].videosLength).to.equal(2) |
113 | }) | 102 | }) |
114 | 103 | ||
115 | it('Should search a local playlist with an alternative URL', async function () { | 104 | it('Should search a local playlist with an alternative URL', async function () { |
@@ -120,13 +109,13 @@ describe('Test ActivityPub playlists search', function () { | |||
120 | 109 | ||
121 | for (const search of searches) { | 110 | for (const search of searches) { |
122 | for (const token of [ undefined, servers[0].accessToken ]) { | 111 | for (const token of [ undefined, servers[0].accessToken ]) { |
123 | const res = await searchVideoPlaylists(servers[0].url, search, token) | 112 | const body = await command.searchPlaylists({ search, token }) |
124 | 113 | ||
125 | expect(res.body.total).to.equal(1) | 114 | expect(body.total).to.equal(1) |
126 | expect(res.body.data).to.be.an('array') | 115 | expect(body.data).to.be.an('array') |
127 | expect(res.body.data).to.have.lengthOf(1) | 116 | expect(body.data).to.have.lengthOf(1) |
128 | expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') | 117 | expect(body.data[0].displayName).to.equal('playlist 1 on server 1') |
129 | expect(res.body.data[0].videosLength).to.equal(2) | 118 | expect(body.data[0].videosLength).to.equal(2) |
130 | } | 119 | } |
131 | } | 120 | } |
132 | }) | 121 | }) |
@@ -139,32 +128,27 @@ describe('Test ActivityPub playlists search', function () { | |||
139 | ] | 128 | ] |
140 | 129 | ||
141 | for (const search of searches) { | 130 | for (const search of searches) { |
142 | const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) | 131 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
143 | 132 | ||
144 | expect(res.body.total).to.equal(1) | 133 | expect(body.total).to.equal(1) |
145 | expect(res.body.data).to.be.an('array') | 134 | expect(body.data).to.be.an('array') |
146 | expect(res.body.data).to.have.lengthOf(1) | 135 | expect(body.data).to.have.lengthOf(1) |
147 | expect(res.body.data[0].displayName).to.equal('playlist 1 on server 2') | 136 | expect(body.data[0].displayName).to.equal('playlist 1 on server 2') |
148 | expect(res.body.data[0].videosLength).to.equal(1) | 137 | expect(body.data[0].videosLength).to.equal(1) |
149 | } | 138 | } |
150 | }) | 139 | }) |
151 | 140 | ||
152 | it('Should not list this remote playlist', async function () { | 141 | it('Should not list this remote playlist', async function () { |
153 | const res = await getVideoPlaylistsList(servers[0].url, 0, 10) | 142 | const body = await servers[0].playlists.list({ start: 0, count: 10 }) |
154 | expect(res.body.total).to.equal(1) | 143 | expect(body.total).to.equal(1) |
155 | expect(res.body.data).to.have.lengthOf(1) | 144 | expect(body.data).to.have.lengthOf(1) |
156 | expect(res.body.data[0].displayName).to.equal('playlist 1 on server 1') | 145 | expect(body.data[0].displayName).to.equal('playlist 1 on server 1') |
157 | }) | 146 | }) |
158 | 147 | ||
159 | it('Should update the playlist of server 2, and refresh it on server 1', async function () { | 148 | it('Should update the playlist of server 2, and refresh it on server 1', async function () { |
160 | this.timeout(60000) | 149 | this.timeout(60000) |
161 | 150 | ||
162 | await addVideoInPlaylist({ | 151 | await servers[1].playlists.addElement({ playlistId: playlistServer2UUID, attributes: { videoId: video2Server2 } }) |
163 | url: servers[1].url, | ||
164 | token: servers[1].accessToken, | ||
165 | playlistId: playlistServer2UUID, | ||
166 | elementAttrs: { videoId: video2Server2 } | ||
167 | }) | ||
168 | 152 | ||
169 | await waitJobs(servers) | 153 | await waitJobs(servers) |
170 | // Expire playlist | 154 | // Expire playlist |
@@ -172,23 +156,23 @@ describe('Test ActivityPub playlists search', function () { | |||
172 | 156 | ||
173 | // Will run refresh async | 157 | // Will run refresh async |
174 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID | 158 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID |
175 | await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) | 159 | await command.searchPlaylists({ search, token: servers[0].accessToken }) |
176 | 160 | ||
177 | // Wait refresh | 161 | // Wait refresh |
178 | await wait(5000) | 162 | await wait(5000) |
179 | 163 | ||
180 | const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) | 164 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
181 | expect(res.body.total).to.equal(1) | 165 | expect(body.total).to.equal(1) |
182 | expect(res.body.data).to.have.lengthOf(1) | 166 | expect(body.data).to.have.lengthOf(1) |
183 | 167 | ||
184 | const playlist: VideoPlaylist = res.body.data[0] | 168 | const playlist = body.data[0] |
185 | expect(playlist.videosLength).to.equal(2) | 169 | expect(playlist.videosLength).to.equal(2) |
186 | }) | 170 | }) |
187 | 171 | ||
188 | it('Should delete playlist of server 2, and delete it on server 1', async function () { | 172 | it('Should delete playlist of server 2, and delete it on server 1', async function () { |
189 | this.timeout(60000) | 173 | this.timeout(60000) |
190 | 174 | ||
191 | await deleteVideoPlaylist(servers[1].url, servers[1].accessToken, playlistServer2UUID) | 175 | await servers[1].playlists.delete({ playlistId: playlistServer2UUID }) |
192 | 176 | ||
193 | await waitJobs(servers) | 177 | await waitJobs(servers) |
194 | // Expiration | 178 | // Expiration |
@@ -196,14 +180,14 @@ describe('Test ActivityPub playlists search', function () { | |||
196 | 180 | ||
197 | // Will run refresh async | 181 | // Will run refresh async |
198 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID | 182 | const search = 'http://localhost:' + servers[1].port + '/video-playlists/' + playlistServer2UUID |
199 | await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) | 183 | await command.searchPlaylists({ search, token: servers[0].accessToken }) |
200 | 184 | ||
201 | // Wait refresh | 185 | // Wait refresh |
202 | await wait(5000) | 186 | await wait(5000) |
203 | 187 | ||
204 | const res = await searchVideoPlaylists(servers[0].url, search, servers[0].accessToken) | 188 | const body = await command.searchPlaylists({ search, token: servers[0].accessToken }) |
205 | expect(res.body.total).to.equal(0) | 189 | expect(body.total).to.equal(0) |
206 | expect(res.body.data).to.have.lengthOf(0) | 190 | expect(body.data).to.have.lengthOf(0) |
207 | }) | 191 | }) |
208 | 192 | ||
209 | after(async function () { | 193 | after(async function () { |