aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/feeds
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/feeds')
-rw-r--r--server/tests/feeds/feeds.ts275
1 files changed, 141 insertions, 134 deletions
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 7bad81751..55b434846 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -4,34 +4,16 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import * as xmlParser from 'fast-xml-parser' 5import * as xmlParser from 'fast-xml-parser'
6import { 6import {
7 addAccountToAccountBlocklist,
8 addAccountToServerBlocklist,
9 removeAccountFromServerBlocklist
10} from '@shared/extra-utils/users/blocklist'
11import { addUserSubscription, listUserSubscriptionVideos } from '@shared/extra-utils/users/user-subscriptions'
12import { VideoPrivacy } from '@shared/models'
13import { ScopedToken } from '@shared/models/users/user-scoped-token'
14import {
15 cleanupTests, 7 cleanupTests,
16 createUser, 8 createMultipleServers,
9 createSingleServer,
17 doubleFollow, 10 doubleFollow,
18 flushAndRunMultipleServers, 11 makeGetRequest,
19 flushAndRunServer, 12 PeerTubeServer,
20 getJSONfeed,
21 getMyUserInformation,
22 getUserScopedTokens,
23 getXMLfeed,
24 renewUserScopedTokens,
25 ServerInfo,
26 setAccessTokensToServers, 13 setAccessTokensToServers,
27 uploadVideo, 14 waitJobs
28 uploadVideoAndGetId, 15} from '@shared/extra-utils'
29 userLogin 16import { HttpStatusCode, VideoPrivacy } from '@shared/models'
30} from '../../../shared/extra-utils'
31import { waitJobs } from '../../../shared/extra-utils/server/jobs'
32import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
33import { User } from '../../../shared/models/users'
34import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
35 17
36chai.use(require('chai-xml')) 18chai.use(require('chai-xml'))
37chai.use(require('chai-json-schema')) 19chai.use(require('chai-json-schema'))
@@ -39,8 +21,8 @@ chai.config.includeStack = true
39const expect = chai.expect 21const expect = chai.expect
40 22
41describe('Test syndication feeds', () => { 23describe('Test syndication feeds', () => {
42 let servers: ServerInfo[] = [] 24 let servers: PeerTubeServer[] = []
43 let serverHLSOnly: ServerInfo 25 let serverHLSOnly: PeerTubeServer
44 let userAccessToken: string 26 let userAccessToken: string
45 let rootAccountId: number 27 let rootAccountId: number
46 let rootChannelId: number 28 let rootChannelId: number
@@ -52,8 +34,8 @@ describe('Test syndication feeds', () => {
52 this.timeout(120000) 34 this.timeout(120000)
53 35
54 // Run servers 36 // Run servers
55 servers = await flushAndRunMultipleServers(2) 37 servers = await createMultipleServers(2)
56 serverHLSOnly = await flushAndRunServer(3, { 38 serverHLSOnly = await createSingleServer(3, {
57 transcoding: { 39 transcoding: {
58 enabled: true, 40 enabled: true,
59 webtorrent: { enabled: false }, 41 webtorrent: { enabled: false },
@@ -65,50 +47,43 @@ describe('Test syndication feeds', () => {
65 await doubleFollow(servers[0], servers[1]) 47 await doubleFollow(servers[0], servers[1])
66 48
67 { 49 {
68 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken) 50 const user = await servers[0].users.getMyInfo()
69 const user: User = res.body
70 rootAccountId = user.account.id 51 rootAccountId = user.account.id
71 rootChannelId = user.videoChannels[0].id 52 rootChannelId = user.videoChannels[0].id
72 } 53 }
73 54
74 { 55 {
75 const attr = { username: 'john', password: 'password' } 56 userAccessToken = await servers[0].users.generateUserAndToken('john')
76 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
77 userAccessToken = await userLogin(servers[0], attr)
78 57
79 const res = await getMyUserInformation(servers[0].url, userAccessToken) 58 const user = await servers[0].users.getMyInfo({ token: userAccessToken })
80 const user: User = res.body
81 userAccountId = user.account.id 59 userAccountId = user.account.id
82 userChannelId = user.videoChannels[0].id 60 userChannelId = user.videoChannels[0].id
83 61
84 const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) 62 const token = await servers[0].users.getMyScopedTokens({ token: userAccessToken })
85 const token: ScopedToken = res2.body
86 userFeedToken = token.feedToken 63 userFeedToken = token.feedToken
87 } 64 }
88 65
89 { 66 {
90 await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' }) 67 await servers[0].videos.upload({ token: userAccessToken, attributes: { name: 'user video' } })
91 } 68 }
92 69
93 { 70 {
94 const videoAttributes = { 71 const attributes = {
95 name: 'my super name for server 1', 72 name: 'my super name for server 1',
96 description: 'my super description for server 1', 73 description: 'my super description for server 1',
97 fixture: 'video_short.webm' 74 fixture: 'video_short.webm'
98 } 75 }
99 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 76 const { id } = await servers[0].videos.upload({ attributes })
100 const videoId = res.body.video.id
101 77
102 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') 78 await servers[0].comments.createThread({ videoId: id, text: 'super comment 1' })
103 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2') 79 await servers[0].comments.createThread({ videoId: id, text: 'super comment 2' })
104 } 80 }
105 81
106 { 82 {
107 const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED } 83 const attributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
108 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 84 const { id } = await servers[0].videos.upload({ attributes })
109 const videoId = res.body.video.id
110 85
111 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video') 86 await servers[0].comments.createThread({ videoId: id, text: 'comment on unlisted video' })
112 } 87 }
113 88
114 await waitJobs(servers) 89 await waitJobs(servers)
@@ -118,30 +93,65 @@ describe('Test syndication feeds', () => {
118 93
119 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () { 94 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
120 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { 95 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
121 const rss = await getXMLfeed(servers[0].url, feed) 96 const rss = await servers[0].feed.getXML({ feed })
122 expect(rss.text).xml.to.be.valid() 97 expect(rss).xml.to.be.valid()
123 98
124 const atom = await getXMLfeed(servers[0].url, feed, 'atom') 99 const atom = await servers[0].feed.getXML({ feed, format: 'atom' })
125 expect(atom.text).xml.to.be.valid() 100 expect(atom).xml.to.be.valid()
126 } 101 }
127 }) 102 })
128 103
129 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () { 104 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
130 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) { 105 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
131 const json = await getJSONfeed(servers[0].url, feed) 106 const jsonText = await servers[0].feed.getJSON({ feed })
132 expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' }) 107 expect(JSON.parse(jsonText)).to.be.jsonSchema({ type: 'object' })
133 } 108 }
134 }) 109 })
110
111 it('Should serve the endpoint with a classic request', async function () {
112 await makeGetRequest({
113 url: servers[0].url,
114 path: '/feeds/videos.xml',
115 accept: 'application/xml',
116 expectedStatus: HttpStatusCode.OK_200
117 })
118 })
119
120 it('Should serve the endpoint as a cached request', async function () {
121 const res = await makeGetRequest({
122 url: servers[0].url,
123 path: '/feeds/videos.xml',
124 accept: 'application/xml',
125 expectedStatus: HttpStatusCode.OK_200
126 })
127
128 expect(res.headers['x-api-cache-cached']).to.equal('true')
129 })
130
131 it('Should not serve the endpoint as a cached request', async function () {
132 const res = await makeGetRequest({
133 url: servers[0].url,
134 path: '/feeds/videos.xml?v=186',
135 accept: 'application/xml',
136 expectedStatus: HttpStatusCode.OK_200
137 })
138
139 expect(res.headers['x-api-cache-cached']).to.not.exist
140 })
141
142 it('Should refuse to serve the endpoint without accept header', async function () {
143 await makeGetRequest({ url: servers[0].url, path: '/feeds/videos.xml', expectedStatus: HttpStatusCode.NOT_ACCEPTABLE_406 })
144 })
135 }) 145 })
136 146
137 describe('Videos feed', function () { 147 describe('Videos feed', function () {
138 148
139 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () { 149 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
140 for (const server of servers) { 150 for (const server of servers) {
141 const rss = await getXMLfeed(server.url, 'videos') 151 const rss = await server.feed.getXML({ feed: 'videos' })
142 expect(xmlParser.validate(rss.text)).to.be.true 152 expect(xmlParser.validate(rss)).to.be.true
143 153
144 const xmlDoc = xmlParser.parse(rss.text, { parseAttributeValue: true, ignoreAttributes: false }) 154 const xmlDoc = xmlParser.parse(rss, { parseAttributeValue: true, ignoreAttributes: false })
145 155
146 const enclosure = xmlDoc.rss.channel.item[0].enclosure 156 const enclosure = xmlDoc.rss.channel.item[0].enclosure
147 expect(enclosure).to.exist 157 expect(enclosure).to.exist
@@ -153,8 +163,8 @@ describe('Test syndication feeds', () => {
153 163
154 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () { 164 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
155 for (const server of servers) { 165 for (const server of servers) {
156 const json = await getJSONfeed(server.url, 'videos') 166 const json = await server.feed.getJSON({ feed: 'videos' })
157 const jsonObj = JSON.parse(json.text) 167 const jsonObj = JSON.parse(json)
158 expect(jsonObj.items.length).to.be.equal(2) 168 expect(jsonObj.items.length).to.be.equal(2)
159 expect(jsonObj.items[0].attachments).to.exist 169 expect(jsonObj.items[0].attachments).to.exist
160 expect(jsonObj.items[0].attachments.length).to.be.eq(1) 170 expect(jsonObj.items[0].attachments.length).to.be.eq(1)
@@ -166,16 +176,16 @@ describe('Test syndication feeds', () => {
166 176
167 it('Should filter by account', async function () { 177 it('Should filter by account', async function () {
168 { 178 {
169 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId }) 179 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: rootAccountId } })
170 const jsonObj = JSON.parse(json.text) 180 const jsonObj = JSON.parse(json)
171 expect(jsonObj.items.length).to.be.equal(1) 181 expect(jsonObj.items.length).to.be.equal(1)
172 expect(jsonObj.items[0].title).to.equal('my super name for server 1') 182 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
173 expect(jsonObj.items[0].author.name).to.equal('root') 183 expect(jsonObj.items[0].author.name).to.equal('root')
174 } 184 }
175 185
176 { 186 {
177 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId }) 187 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { accountId: userAccountId } })
178 const jsonObj = JSON.parse(json.text) 188 const jsonObj = JSON.parse(json)
179 expect(jsonObj.items.length).to.be.equal(1) 189 expect(jsonObj.items.length).to.be.equal(1)
180 expect(jsonObj.items[0].title).to.equal('user video') 190 expect(jsonObj.items[0].title).to.equal('user video')
181 expect(jsonObj.items[0].author.name).to.equal('john') 191 expect(jsonObj.items[0].author.name).to.equal('john')
@@ -183,15 +193,15 @@ describe('Test syndication feeds', () => {
183 193
184 for (const server of servers) { 194 for (const server of servers) {
185 { 195 {
186 const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port }) 196 const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'root@localhost:' + servers[0].port } })
187 const jsonObj = JSON.parse(json.text) 197 const jsonObj = JSON.parse(json)
188 expect(jsonObj.items.length).to.be.equal(1) 198 expect(jsonObj.items.length).to.be.equal(1)
189 expect(jsonObj.items[0].title).to.equal('my super name for server 1') 199 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
190 } 200 }
191 201
192 { 202 {
193 const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port }) 203 const json = await server.feed.getJSON({ feed: 'videos', query: { accountName: 'john@localhost:' + servers[0].port } })
194 const jsonObj = JSON.parse(json.text) 204 const jsonObj = JSON.parse(json)
195 expect(jsonObj.items.length).to.be.equal(1) 205 expect(jsonObj.items.length).to.be.equal(1)
196 expect(jsonObj.items[0].title).to.equal('user video') 206 expect(jsonObj.items[0].title).to.equal('user video')
197 } 207 }
@@ -200,16 +210,16 @@ describe('Test syndication feeds', () => {
200 210
201 it('Should filter by video channel', async function () { 211 it('Should filter by video channel', async function () {
202 { 212 {
203 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId }) 213 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: rootChannelId } })
204 const jsonObj = JSON.parse(json.text) 214 const jsonObj = JSON.parse(json)
205 expect(jsonObj.items.length).to.be.equal(1) 215 expect(jsonObj.items.length).to.be.equal(1)
206 expect(jsonObj.items[0].title).to.equal('my super name for server 1') 216 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
207 expect(jsonObj.items[0].author.name).to.equal('root') 217 expect(jsonObj.items[0].author.name).to.equal('root')
208 } 218 }
209 219
210 { 220 {
211 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId }) 221 const json = await servers[0].feed.getJSON({ feed: 'videos', query: { videoChannelId: userChannelId } })
212 const jsonObj = JSON.parse(json.text) 222 const jsonObj = JSON.parse(json)
213 expect(jsonObj.items.length).to.be.equal(1) 223 expect(jsonObj.items.length).to.be.equal(1)
214 expect(jsonObj.items[0].title).to.equal('user video') 224 expect(jsonObj.items[0].title).to.equal('user video')
215 expect(jsonObj.items[0].author.name).to.equal('john') 225 expect(jsonObj.items[0].author.name).to.equal('john')
@@ -217,15 +227,17 @@ describe('Test syndication feeds', () => {
217 227
218 for (const server of servers) { 228 for (const server of servers) {
219 { 229 {
220 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port }) 230 const query = { videoChannelName: 'root_channel@localhost:' + servers[0].port }
221 const jsonObj = JSON.parse(json.text) 231 const json = await server.feed.getJSON({ feed: 'videos', query })
232 const jsonObj = JSON.parse(json)
222 expect(jsonObj.items.length).to.be.equal(1) 233 expect(jsonObj.items.length).to.be.equal(1)
223 expect(jsonObj.items[0].title).to.equal('my super name for server 1') 234 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
224 } 235 }
225 236
226 { 237 {
227 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port }) 238 const query = { videoChannelName: 'john_channel@localhost:' + servers[0].port }
228 const jsonObj = JSON.parse(json.text) 239 const json = await server.feed.getJSON({ feed: 'videos', query })
240 const jsonObj = JSON.parse(json)
229 expect(jsonObj.items.length).to.be.equal(1) 241 expect(jsonObj.items.length).to.be.equal(1)
230 expect(jsonObj.items[0].title).to.equal('user video') 242 expect(jsonObj.items[0].title).to.equal('user video')
231 } 243 }
@@ -235,12 +247,12 @@ describe('Test syndication feeds', () => {
235 it('Should correctly have videos feed with HLS only', async function () { 247 it('Should correctly have videos feed with HLS only', async function () {
236 this.timeout(120000) 248 this.timeout(120000)
237 249
238 await uploadVideo(serverHLSOnly.url, serverHLSOnly.accessToken, { name: 'hls only video' }) 250 await serverHLSOnly.videos.upload({ attributes: { name: 'hls only video' } })
239 251
240 await waitJobs([ serverHLSOnly ]) 252 await waitJobs([ serverHLSOnly ])
241 253
242 const json = await getJSONfeed(serverHLSOnly.url, 'videos') 254 const json = await serverHLSOnly.feed.getJSON({ feed: 'videos' })
243 const jsonObj = JSON.parse(json.text) 255 const jsonObj = JSON.parse(json)
244 expect(jsonObj.items.length).to.be.equal(1) 256 expect(jsonObj.items.length).to.be.equal(1)
245 expect(jsonObj.items[0].attachments).to.exist 257 expect(jsonObj.items[0].attachments).to.exist
246 expect(jsonObj.items[0].attachments.length).to.be.eq(4) 258 expect(jsonObj.items[0].attachments.length).to.be.eq(4)
@@ -257,9 +269,9 @@ describe('Test syndication feeds', () => {
257 269
258 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () { 270 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
259 for (const server of servers) { 271 for (const server of servers) {
260 const json = await getJSONfeed(server.url, 'video-comments') 272 const json = await server.feed.getJSON({ feed: 'video-comments' })
261 273
262 const jsonObj = JSON.parse(json.text) 274 const jsonObj = JSON.parse(json)
263 expect(jsonObj.items.length).to.be.equal(2) 275 expect(jsonObj.items.length).to.be.equal(2)
264 expect(jsonObj.items[0].html_content).to.equal('super comment 2') 276 expect(jsonObj.items[0].html_content).to.equal('super comment 2')
265 expect(jsonObj.items[1].html_content).to.equal('super comment 1') 277 expect(jsonObj.items[1].html_content).to.equal('super comment 1')
@@ -271,32 +283,32 @@ describe('Test syndication feeds', () => {
271 283
272 const remoteHandle = 'root@localhost:' + servers[0].port 284 const remoteHandle = 'root@localhost:' + servers[0].port
273 285
274 await addAccountToServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle) 286 await servers[1].blocklist.addToServerBlocklist({ account: remoteHandle })
275 287
276 { 288 {
277 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 2 }) 289 const json = await servers[1].feed.getJSON({ feed: 'video-comments', query: { version: 2 } })
278 const jsonObj = JSON.parse(json.text) 290 const jsonObj = JSON.parse(json)
279 expect(jsonObj.items.length).to.be.equal(0) 291 expect(jsonObj.items.length).to.be.equal(0)
280 } 292 }
281 293
282 await removeAccountFromServerBlocklist(servers[1].url, servers[1].accessToken, remoteHandle) 294 await servers[1].blocklist.removeFromServerBlocklist({ account: remoteHandle })
283 295
284 { 296 {
285 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'server 2' })).uuid 297 const videoUUID = (await servers[1].videos.quickUpload({ name: 'server 2' })).uuid
286 await waitJobs(servers) 298 await waitJobs(servers)
287 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'super comment') 299 await servers[0].comments.createThread({ videoId: videoUUID, text: 'super comment' })
288 await waitJobs(servers) 300 await waitJobs(servers)
289 301
290 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 3 }) 302 const json = await servers[1].feed.getJSON({ feed: 'video-comments', query: { version: 3 } })
291 const jsonObj = JSON.parse(json.text) 303 const jsonObj = JSON.parse(json)
292 expect(jsonObj.items.length).to.be.equal(3) 304 expect(jsonObj.items.length).to.be.equal(3)
293 } 305 }
294 306
295 await addAccountToAccountBlocklist(servers[1].url, servers[1].accessToken, remoteHandle) 307 await servers[1].blocklist.addToMyBlocklist({ account: remoteHandle })
296 308
297 { 309 {
298 const json = await getJSONfeed(servers[1].url, 'video-comments', { version: 4 }) 310 const json = await servers[1].feed.getJSON({ feed: 'video-comments', query: { version: 4 } })
299 const jsonObj = JSON.parse(json.text) 311 const jsonObj = JSON.parse(json)
300 expect(jsonObj.items.length).to.be.equal(2) 312 expect(jsonObj.items.length).to.be.equal(2)
301 } 313 }
302 }) 314 })
@@ -308,66 +320,64 @@ describe('Test syndication feeds', () => {
308 320
309 it('Should list no videos for a user with no videos and no subscriptions', async function () { 321 it('Should list no videos for a user with no videos and no subscriptions', async function () {
310 const attr = { username: 'feeduser', password: 'password' } 322 const attr = { username: 'feeduser', password: 'password' }
311 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password }) 323 await servers[0].users.create({ username: attr.username, password: attr.password })
312 const feeduserAccessToken = await userLogin(servers[0], attr) 324 const feeduserAccessToken = await servers[0].login.getAccessToken(attr)
313 325
314 { 326 {
315 const res = await getMyUserInformation(servers[0].url, feeduserAccessToken) 327 const user = await servers[0].users.getMyInfo({ token: feeduserAccessToken })
316 const user: User = res.body
317 feeduserAccountId = user.account.id 328 feeduserAccountId = user.account.id
318 } 329 }
319 330
320 { 331 {
321 const res = await getUserScopedTokens(servers[0].url, feeduserAccessToken) 332 const token = await servers[0].users.getMyScopedTokens({ token: feeduserAccessToken })
322 const token: ScopedToken = res.body
323 feeduserFeedToken = token.feedToken 333 feeduserFeedToken = token.feedToken
324 } 334 }
325 335
326 { 336 {
327 const res = await listUserSubscriptionVideos(servers[0].url, feeduserAccessToken) 337 const body = await servers[0].subscriptions.listVideos({ token: feeduserAccessToken })
328 expect(res.body.total).to.equal(0) 338 expect(body.total).to.equal(0)
329 339
330 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: feeduserAccountId, token: feeduserFeedToken }) 340 const query = { accountId: feeduserAccountId, token: feeduserFeedToken }
331 const jsonObj = JSON.parse(json.text) 341 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query })
342 const jsonObj = JSON.parse(json)
332 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos 343 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
333 } 344 }
334 }) 345 })
335 346
336 it('Should fail with an invalid token', async function () { 347 it('Should fail with an invalid token', async function () {
337 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: feeduserAccountId, token: 'toto' }, HttpStatusCode.FORBIDDEN_403) 348 const query = { accountId: feeduserAccountId, token: 'toto' }
349 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
338 }) 350 })
339 351
340 it('Should fail with a token of another user', async function () { 352 it('Should fail with a token of another user', async function () {
341 await getJSONfeed( 353 const query = { accountId: feeduserAccountId, token: userFeedToken }
342 servers[0].url, 354 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
343 'subscriptions',
344 { accountId: feeduserAccountId, token: userFeedToken },
345 HttpStatusCode.FORBIDDEN_403
346 )
347 }) 355 })
348 356
349 it('Should list no videos for a user with videos but no subscriptions', async function () { 357 it('Should list no videos for a user with videos but no subscriptions', async function () {
350 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 358 const body = await servers[0].subscriptions.listVideos({ token: userAccessToken })
351 expect(res.body.total).to.equal(0) 359 expect(body.total).to.equal(0)
352 360
353 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken }) 361 const query = { accountId: userAccountId, token: userFeedToken }
354 const jsonObj = JSON.parse(json.text) 362 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query })
363 const jsonObj = JSON.parse(json)
355 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos 364 expect(jsonObj.items.length).to.be.equal(0) // no subscription, it should not list the instance's videos but list 0 videos
356 }) 365 })
357 366
358 it('Should list self videos for a user with a subscription to themselves', async function () { 367 it('Should list self videos for a user with a subscription to themselves', async function () {
359 this.timeout(30000) 368 this.timeout(30000)
360 369
361 await addUserSubscription(servers[0].url, userAccessToken, 'john_channel@localhost:' + servers[0].port) 370 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'john_channel@localhost:' + servers[0].port })
362 await waitJobs(servers) 371 await waitJobs(servers)
363 372
364 { 373 {
365 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 374 const body = await servers[0].subscriptions.listVideos({ token: userAccessToken })
366 expect(res.body.total).to.equal(1) 375 expect(body.total).to.equal(1)
367 expect(res.body.data[0].name).to.equal('user video') 376 expect(body.data[0].name).to.equal('user video')
368 377
369 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken, version: 1 }) 378 const query = { accountId: userAccountId, token: userFeedToken, version: 1 }
370 const jsonObj = JSON.parse(json.text) 379 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query })
380 const jsonObj = JSON.parse(json)
371 expect(jsonObj.items.length).to.be.equal(1) // subscribed to self, it should not list the instance's videos but list john's 381 expect(jsonObj.items.length).to.be.equal(1) // subscribed to self, it should not list the instance's videos but list john's
372 } 382 }
373 }) 383 })
@@ -375,36 +385,33 @@ describe('Test syndication feeds', () => {
375 it('Should list videos of a user\'s subscription', async function () { 385 it('Should list videos of a user\'s subscription', async function () {
376 this.timeout(30000) 386 this.timeout(30000)
377 387
378 await addUserSubscription(servers[0].url, userAccessToken, 'root_channel@localhost:' + servers[0].port) 388 await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@localhost:' + servers[0].port })
379 await waitJobs(servers) 389 await waitJobs(servers)
380 390
381 { 391 {
382 const res = await listUserSubscriptionVideos(servers[0].url, userAccessToken) 392 const body = await servers[0].subscriptions.listVideos({ token: userAccessToken })
383 expect(res.body.total).to.equal(2, "there should be 2 videos part of the subscription") 393 expect(body.total).to.equal(2, "there should be 2 videos part of the subscription")
384 394
385 const json = await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken, version: 2 }) 395 const query = { accountId: userAccountId, token: userFeedToken, version: 2 }
386 const jsonObj = JSON.parse(json.text) 396 const json = await servers[0].feed.getJSON({ feed: 'subscriptions', query })
397 const jsonObj = JSON.parse(json)
387 expect(jsonObj.items.length).to.be.equal(2) // subscribed to root, it should not list the instance's videos but list root/john's 398 expect(jsonObj.items.length).to.be.equal(2) // subscribed to root, it should not list the instance's videos but list root/john's
388 } 399 }
389 }) 400 })
390 401
391 it('Should renew the token, and so have an invalid old token', async function () { 402 it('Should renew the token, and so have an invalid old token', async function () {
392 await renewUserScopedTokens(servers[0].url, userAccessToken) 403 await servers[0].users.renewMyScopedTokens({ token: userAccessToken })
393 404
394 await getJSONfeed( 405 const query = { accountId: userAccountId, token: userFeedToken, version: 3 }
395 servers[0].url, 406 await servers[0].feed.getJSON({ feed: 'subscriptions', query, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
396 'subscriptions',
397 { accountId: userAccountId, token: userFeedToken, version: 3 },
398 HttpStatusCode.FORBIDDEN_403
399 )
400 }) 407 })
401 408
402 it('Should succeed with the new token', async function () { 409 it('Should succeed with the new token', async function () {
403 const res2 = await getUserScopedTokens(servers[0].url, userAccessToken) 410 const token = await servers[0].users.getMyScopedTokens({ token: userAccessToken })
404 const token: ScopedToken = res2.body
405 userFeedToken = token.feedToken 411 userFeedToken = token.feedToken
406 412
407 await getJSONfeed(servers[0].url, 'subscriptions', { accountId: userAccountId, token: userFeedToken, version: 4 }) 413 const query = { accountId: userAccountId, token: userFeedToken, version: 4 }
414 await servers[0].feed.getJSON({ feed: 'subscriptions', query })
408 }) 415 })
409 416
410 }) 417 })