feeds.ts 8.0 KB

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