]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/feeds/feeds.ts
Add external login tests
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fe3a55b0
C
2
3import * as chai from 'chai'
4import 'mocha'
5import {
7c3b7976 6 cleanupTests,
662fb3ab 7 createUser,
fe3a55b0
C
8 doubleFollow,
9 flushAndRunMultipleServers,
57cfff78
C
10 getJSONfeed,
11 getMyUserInformation,
fe3a55b0 12 getXMLfeed,
fe3a55b0
C
13 ServerInfo,
14 setAccessTokensToServers,
57cfff78
C
15 uploadVideo,
16 userLogin
94565d52 17} from '../../../shared/extra-utils'
fe3a55b0 18import * as libxmljs from 'libxmljs'
94565d52
C
19import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
20import { waitJobs } from '../../../shared/extra-utils/server/jobs'
662fb3ab 21import { User } from '../../../shared/models/users'
68b6fd21 22import { VideoPrivacy } from '@shared/models'
fe3a55b0
C
23
24chai.use(require('chai-xml'))
25chai.use(require('chai-json-schema'))
26chai.config.includeStack = true
27const expect = chai.expect
28
29describe('Test syndication feeds', () => {
30 let servers: ServerInfo[] = []
662fb3ab 31 let userAccessToken: string
57cfff78
C
32 let rootAccountId: number
33 let rootChannelId: number
34 let userAccountId: number
35 let userChannelId: number
fe3a55b0
C
36
37 before(async function () {
38 this.timeout(120000)
39
40 // Run servers
41 servers = await flushAndRunMultipleServers(2)
42
43 await setAccessTokensToServers(servers)
44 await doubleFollow(servers[0], servers[1])
45
662fb3ab
C
46 {
47 const res = await getMyUserInformation(servers[0].url, servers[0].accessToken)
48 const user: User = res.body
57cfff78
C
49 rootAccountId = user.account.id
50 rootChannelId = user.videoChannels[0].id
fe3a55b0 51 }
fe3a55b0 52
662fb3ab
C
53 {
54 const attr = { username: 'john', password: 'password' }
a1587156 55 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: attr.username, password: attr.password })
662fb3ab
C
56 userAccessToken = await userLogin(servers[0], attr)
57
58 const res = await getMyUserInformation(servers[0].url, userAccessToken)
59 const user: User = res.body
57cfff78
C
60 userAccountId = user.account.id
61 userChannelId = user.videoChannels[0].id
662fb3ab
C
62 }
63
64 {
a1587156 65 await uploadVideo(servers[0].url, userAccessToken, { name: 'user video' })
662fb3ab
C
66 }
67
68 {
69 const videoAttributes = {
70 name: 'my super name for server 1',
71 description: 'my super description for server 1',
72 fixture: 'video_short.webm'
73 }
a1587156 74 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
662fb3ab
C
75 const videoId = res.body.video.id
76
a1587156
C
77 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 1')
78 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'super comment 2')
662fb3ab 79 }
fe3a55b0 80
68b6fd21
C
81 {
82 const videoAttributes = { name: 'unlisted video', privacy: VideoPrivacy.UNLISTED }
83 const res = await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes)
84 const videoId = res.body.video.id
85
86 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoId, 'comment on unlisted video')
87 }
88
3cd0734f 89 await waitJobs(servers)
fe3a55b0
C
90 })
91
92 describe('All feed', function () {
93
94 it('Should be well formed XML (covers RSS 2.0 and ATOM 1.0 endpoints)', async function () {
95 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
a1587156 96 const rss = await getXMLfeed(servers[0].url, feed)
fe3a55b0
C
97 expect(rss.text).xml.to.be.valid()
98
a1587156 99 const atom = await getXMLfeed(servers[0].url, feed, 'atom')
fe3a55b0
C
100 expect(atom.text).xml.to.be.valid()
101 }
102 })
103
104 it('Should be well formed JSON (covers JSON feed 1.0 endpoint)', async function () {
105 for (const feed of [ 'video-comments' as 'video-comments', 'videos' as 'videos' ]) {
a1587156
C
106 const json = await getJSONfeed(servers[0].url, feed)
107 expect(JSON.parse(json.text)).to.be.jsonSchema({ type: 'object' })
fe3a55b0
C
108 }
109 })
110 })
111
112 describe('Videos feed', function () {
113 it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
114 for (const server of servers) {
115 const rss = await getXMLfeed(server.url, 'videos')
116 const xmlDoc = libxmljs.parseXmlString(rss.text)
117 const xmlEnclosure = xmlDoc.get('/rss/channel/item/enclosure')
118 expect(xmlEnclosure).to.exist
119 expect(xmlEnclosure.attr('type').value()).to.be.equal('application/x-bittorrent')
120 expect(xmlEnclosure.attr('length').value()).to.be.equal('218910')
121 expect(xmlEnclosure.attr('url').value()).to.contain('720.torrent')
122 }
123 })
124
125 it('Should contain a valid \'attachments\' object (covers JSON feed 1.0 endpoint)', async function () {
126 for (const server of servers) {
127 const json = await getJSONfeed(server.url, 'videos')
128 const jsonObj = JSON.parse(json.text)
662fb3ab 129 expect(jsonObj.items.length).to.be.equal(2)
a1587156
C
130 expect(jsonObj.items[0].attachments).to.exist
131 expect(jsonObj.items[0].attachments.length).to.be.eq(1)
132 expect(jsonObj.items[0].attachments[0].mime_type).to.be.eq('application/x-bittorrent')
133 expect(jsonObj.items[0].attachments[0].size_in_bytes).to.be.eq(218910)
134 expect(jsonObj.items[0].attachments[0].url).to.contain('720.torrent')
fe3a55b0
C
135 }
136 })
662fb3ab
C
137
138 it('Should filter by account', async function () {
57cfff78
C
139 {
140 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: rootAccountId })
141 const jsonObj = JSON.parse(json.text)
142 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
143 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
144 expect(jsonObj.items[0].author.name).to.equal('root')
57cfff78
C
145 }
146
147 {
148 const json = await getJSONfeed(servers[0].url, 'videos', { accountId: userAccountId })
149 const jsonObj = JSON.parse(json.text)
150 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
151 expect(jsonObj.items[0].title).to.equal('user video')
152 expect(jsonObj.items[0].author.name).to.equal('john')
57cfff78
C
153 }
154
662fb3ab
C
155 for (const server of servers) {
156 {
57cfff78 157 const json = await getJSONfeed(server.url, 'videos', { accountName: 'root@localhost:' + servers[0].port })
662fb3ab
C
158 const jsonObj = JSON.parse(json.text)
159 expect(jsonObj.items.length).to.be.equal(1)
a1587156 160 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
662fb3ab
C
161 }
162
163 {
57cfff78 164 const json = await getJSONfeed(server.url, 'videos', { accountName: 'john@localhost:' + servers[0].port })
662fb3ab
C
165 const jsonObj = JSON.parse(json.text)
166 expect(jsonObj.items.length).to.be.equal(1)
a1587156 167 expect(jsonObj.items[0].title).to.equal('user video')
662fb3ab
C
168 }
169 }
57cfff78 170 })
662fb3ab 171
57cfff78 172 it('Should filter by video channel', async function () {
662fb3ab 173 {
57cfff78 174 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: rootChannelId })
662fb3ab
C
175 const jsonObj = JSON.parse(json.text)
176 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
177 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
178 expect(jsonObj.items[0].author.name).to.equal('root')
662fb3ab
C
179 }
180
181 {
57cfff78 182 const json = await getJSONfeed(servers[0].url, 'videos', { videoChannelId: userChannelId })
662fb3ab
C
183 const jsonObj = JSON.parse(json.text)
184 expect(jsonObj.items.length).to.be.equal(1)
a1587156
C
185 expect(jsonObj.items[0].title).to.equal('user video')
186 expect(jsonObj.items[0].author.name).to.equal('john')
662fb3ab 187 }
662fb3ab 188
662fb3ab
C
189 for (const server of servers) {
190 {
57cfff78 191 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'root_channel@localhost:' + servers[0].port })
662fb3ab
C
192 const jsonObj = JSON.parse(json.text)
193 expect(jsonObj.items.length).to.be.equal(1)
a1587156 194 expect(jsonObj.items[0].title).to.equal('my super name for server 1')
662fb3ab
C
195 }
196
197 {
57cfff78 198 const json = await getJSONfeed(server.url, 'videos', { videoChannelName: 'john_channel@localhost:' + servers[0].port })
662fb3ab
C
199 const jsonObj = JSON.parse(json.text)
200 expect(jsonObj.items.length).to.be.equal(1)
a1587156 201 expect(jsonObj.items[0].title).to.equal('user video')
662fb3ab
C
202 }
203 }
662fb3ab 204 })
fe3a55b0
C
205 })
206
207 describe('Video comments feed', function () {
68b6fd21
C
208
209 it('Should contain valid comments (covers JSON feed 1.0 endpoint) and not from unlisted videos', async function () {
fe3a55b0
C
210 for (const server of servers) {
211 const json = await getJSONfeed(server.url, 'video-comments')
212
213 const jsonObj = JSON.parse(json.text)
214 expect(jsonObj.items.length).to.be.equal(2)
a1587156
C
215 expect(jsonObj.items[0].html_content).to.equal('super comment 2')
216 expect(jsonObj.items[1].html_content).to.equal('super comment 1')
fe3a55b0
C
217 }
218 })
219 })
220
7c3b7976
C
221 after(async function () {
222 await cleanupTests(servers)
fe3a55b0
C
223 })
224})