aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-09-13 09:48:34 +0200
committerChocobozzz <me@florianbigard.com>2018-09-13 09:48:34 +0200
commit662fb3ab5e3aafa49c96809a61239c9046a5c485 (patch)
treef79b116292d7c6a514a9d1cbdf5491766ec6ad39 /server
parent4035d2b6e937e13cd10cf88ed0e89cb579dd86ee (diff)
downloadPeerTube-662fb3ab5e3aafa49c96809a61239c9046a5c485.tar.gz
PeerTube-662fb3ab5e3aafa49c96809a61239c9046a5c485.tar.zst
PeerTube-662fb3ab5e3aafa49c96809a61239c9046a5c485.zip
Fix feeds with channel filter
Diffstat (limited to 'server')
-rw-r--r--server/middlewares/validators/feeds.ts2
-rw-r--r--server/tests/feeds/feeds.ts121
-rw-r--r--server/tests/utils/feeds/feeds.ts3
3 files changed, 113 insertions, 13 deletions
diff --git a/server/middlewares/validators/feeds.ts b/server/middlewares/validators/feeds.ts
index c1054ad9b..969ce2526 100644
--- a/server/middlewares/validators/feeds.ts
+++ b/server/middlewares/validators/feeds.ts
@@ -23,7 +23,7 @@ const videoFeedsValidator = [
23 if (areValidationErrors(req, res)) return 23 if (areValidationErrors(req, res)) return
24 24
25 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return 25 if (req.query.accountId && !await isAccountIdExist(req.query.accountId, res)) return
26 if (req.query.videoChannelName && !await isVideoChannelIdExist(req.query.videoChannelName, res)) return 26 if (req.query.videoChannelId && !await isVideoChannelIdExist(req.query.videoChannelId, res)) return
27 if (req.query.accountName && !await isAccountNameWithHostExist(req.query.accountName, res)) return 27 if (req.query.accountName && !await isAccountNameWithHostExist(req.query.accountName, res)) return
28 if (req.query.videoChannelName && !await isVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return 28 if (req.query.videoChannelName && !await isVideoChannelNameWithHostExist(req.query.videoChannelName, res)) return
29 29
diff --git a/server/tests/feeds/feeds.ts b/server/tests/feeds/feeds.ts
index 72c9bf9a0..28fe3493b 100644
--- a/server/tests/feeds/feeds.ts
+++ b/server/tests/feeds/feeds.ts
@@ -3,19 +3,21 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 createUser,
6 doubleFollow, 7 doubleFollow,
7 flushAndRunMultipleServers, 8 flushAndRunMultipleServers,
8 flushTests, 9 flushTests,
9 getJSONfeed, 10 getJSONfeed, getMyUserInformation,
10 getXMLfeed, 11 getXMLfeed,
11 killallServers, 12 killallServers,
12 ServerInfo, 13 ServerInfo,
13 setAccessTokensToServers, 14 setAccessTokensToServers,
14 uploadVideo 15 uploadVideo, userLogin
15} from '../utils' 16} from '../utils'
16import * as libxmljs from 'libxmljs' 17import * as libxmljs from 'libxmljs'
17import { addVideoCommentThread } from '../utils/videos/video-comments' 18import { addVideoCommentThread } from '../utils/videos/video-comments'
18import { waitJobs } from '../utils/server/jobs' 19import { waitJobs } from '../utils/server/jobs'
20import { User } from '../../../shared/models/users'
19 21
20chai.use(require('chai-xml')) 22chai.use(require('chai-xml'))
21chai.use(require('chai-json-schema')) 23chai.use(require('chai-json-schema'))
@@ -24,6 +26,11 @@ const expect = chai.expect
24 26
25describe('Test syndication feeds', () => { 27describe('Test syndication feeds', () => {
26 let servers: ServerInfo[] = [] 28 let servers: ServerInfo[] = []
29 let userAccessToken: string
30 let rootAccountUUID: string
31 let rootChannelUUID: string
32 let userAccountUUID: string
33 let userChannelUUID: string
27 34
28 before(async function () { 35 before(async function () {
29 this.timeout(120000) 36 this.timeout(120000)
@@ -34,16 +41,40 @@ describe('Test syndication feeds', () => {
34 await setAccessTokensToServers(servers) 41 await setAccessTokensToServers(servers)
35 await doubleFollow(servers[0], servers[1]) 42 await doubleFollow(servers[0], servers[1])
36 43
37 const videoAttributes = { 44 {
38 name: 'my super name for server 1', 45 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
39 description: 'my super description for server 1', 46 const user: User = res.body
40 fixture: 'video_short.webm' 47 rootAccountUUID = user.account.uuid
48 rootChannelUUID = user.videoChannels[0].uuid
41 } 49 }
42 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
43 const videoId = res.body.video.id
44 50
45 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1') 51 {
46 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2') 52 const attr = { username: 'john', password: 'password' }
53 await createUser(servers[0].url, servers[0].accessToken, attr.username, attr.password)
54 userAccessToken = await userLogin(servers[0], attr)
55
56 const res = await getMyUserInformation(servers[0].url, userAccessToken)
57 const user: User = res.body
58 userAccountUUID = user.account.uuid
59 userChannelUUID = user.videoChannels[0].uuid
60 }
61
62 {
63 await uploadVideo(servers[ 0 ].url, userAccessToken, { name: 'user video' })
64 }
65
66 {
67 const videoAttributes = {
68 name: 'my super name for server 1',
69 description: 'my super description for server 1',
70 fixture: 'video_short.webm'
71 }
72 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, videoAttributes)
73 const videoId = res.body.video.id
74
75 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 1')
76 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoId, 'super comment 2')
77 }
47 78
48 await waitJobs(servers) 79 await waitJobs(servers)
49 }) 80 })
@@ -85,7 +116,7 @@ describe('Test syndication feeds', () => {
85 for (const server of servers) { 116 for (const server of servers) {
86 const json = await getJSONfeed(server.url, 'videos') 117 const json = await getJSONfeed(server.url, 'videos')
87 const jsonObj = JSON.parse(json.text) 118 const jsonObj = JSON.parse(json.text)
88 expect(jsonObj.items.length).to.be.equal(1) 119 expect(jsonObj.items.length).to.be.equal(2)
89 expect(jsonObj.items[ 0 ].attachments).to.exist 120 expect(jsonObj.items[ 0 ].attachments).to.exist
90 expect(jsonObj.items[ 0 ].attachments.length).to.be.eq(1) 121 expect(jsonObj.items[ 0 ].attachments.length).to.be.eq(1)
91 expect(jsonObj.items[ 0 ].attachments[ 0 ].mime_type).to.be.eq('application/x-bittorrent') 122 expect(jsonObj.items[ 0 ].attachments[ 0 ].mime_type).to.be.eq('application/x-bittorrent')
@@ -93,6 +124,74 @@ describe('Test syndication feeds', () => {
93 expect(jsonObj.items[ 0 ].attachments[ 0 ].url).to.contain('720.torrent') 124 expect(jsonObj.items[ 0 ].attachments[ 0 ].url).to.contain('720.torrent')
94 } 125 }
95 }) 126 })
127
128 it('Should filter by account', async function () {
129 for (const server of servers) {
130 {
131 const json = await getJSONfeed(server.url, 'videos', { accountId: rootAccountUUID })
132 const jsonObj = JSON.parse(json.text)
133 expect(jsonObj.items.length).to.be.equal(1)
134 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
135 expect(jsonObj.items[ 0 ].author.name).to.equal('root')
136 }
137
138 {
139 const json = await getJSONfeed(server.url, 'videos', { accountId: userAccountUUID })
140 const jsonObj = JSON.parse(json.text)
141 expect(jsonObj.items.length).to.be.equal(1)
142 expect(jsonObj.items[ 0 ].title).to.equal('user video')
143 expect(jsonObj.items[ 0 ].author.name).to.equal('john')
144 }
145 }
146
147 {
148 const json = await getJSONfeed(servers[0].url, 'videos', { accountName: 'root' })
149 const jsonObj = JSON.parse(json.text)
150 expect(jsonObj.items.length).to.be.equal(1)
151 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
152 }
153
154 {
155 const json = await getJSONfeed(servers[0].url, 'videos', { accountName: 'john' })
156 const jsonObj = JSON.parse(json.text)
157 expect(jsonObj.items.length).to.be.equal(1)
158 expect(jsonObj.items[ 0 ].title).to.equal('user video')
159 }
160 })
161
162 it('Should filter by video channel', async function () {
163 for (const server of servers) {
164 {
165 const json = await getJSONfeed(server.url, 'videos', { videoChannelId: rootChannelUUID })
166 const jsonObj = JSON.parse(json.text)
167 expect(jsonObj.items.length).to.be.equal(1)
168 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
169 expect(jsonObj.items[ 0 ].author.name).to.equal('root')
170 }
171
172 {
173 const json = await getJSONfeed(server.url, 'videos', { videoChannelId: userChannelUUID })
174 const jsonObj = JSON.parse(json.text)
175 expect(jsonObj.items.length).to.be.equal(1)
176 expect(jsonObj.items[ 0 ].title).to.equal('user video')
177 expect(jsonObj.items[ 0 ].author.name).to.equal('john')
178 }
179 }
180
181 {
182 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelName: 'root_channel' })
183 const jsonObj = JSON.parse(json.text)
184 expect(jsonObj.items.length).to.be.equal(1)
185 expect(jsonObj.items[ 0 ].title).to.equal('my super name for server 1')
186 }
187
188 {
189 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelName: 'john_channel' })
190 const jsonObj = JSON.parse(json.text)
191 expect(jsonObj.items.length).to.be.equal(1)
192 expect(jsonObj.items[ 0 ].title).to.equal('user video')
193 }
194 })
96 }) 195 })
97 196
98 describe('Video comments feed', function () { 197 describe('Video comments feed', function () {
diff --git a/server/tests/utils/feeds/feeds.ts b/server/tests/utils/feeds/feeds.ts
index fb480b704..af6df2b20 100644
--- a/server/tests/utils/feeds/feeds.ts
+++ b/server/tests/utils/feeds/feeds.ts
@@ -13,11 +13,12 @@ function getXMLfeed (url: string, feed: FeedType, format?: string) {
13 .expect('Content-Type', /xml/) 13 .expect('Content-Type', /xml/)
14} 14}
15 15
16function getJSONfeed (url: string, feed: FeedType) { 16function getJSONfeed (url: string, feed: FeedType, query: any = {}) {
17 const path = '/feeds/' + feed + '.json' 17 const path = '/feeds/' + feed + '.json'
18 18
19 return request(url) 19 return request(url)
20 .get(path) 20 .get(path)
21 .query(query)
21 .set('Accept', 'application/json') 22 .set('Accept', 'application/json')
22 .expect(200) 23 .expect(200)
23 .expect('Content-Type', /json/) 24 .expect('Content-Type', /json/)