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