]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/feeds/feeds.ts
esModuleInterop to true
[github/Chocobozzz/PeerTube.git] / server / tests / feeds / feeds.ts
index 7735299d32c87673c64e21bb96e3cb4ef2cf1824..a1c976fd30d013ed3d3f0c5ef66c354efd6121cb 100644 (file)
@@ -2,18 +2,18 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import * as xmlParser from 'fast-xml-parser'
-import { HttpStatusCode } from '@shared/core-utils'
+import { parse, validate } from 'fast-xml-parser'
 import {
   cleanupTests,
-  doubleFollow,
   createMultipleServers,
   createSingleServer,
+  doubleFollow,
+  makeGetRequest,
   PeerTubeServer,
   setAccessTokensToServers,
   waitJobs
 } from '@shared/extra-utils'
-import { VideoPrivacy } from '@shared/models'
+import { HttpStatusCode, VideoPrivacy } from '@shared/models'
 
 chai.use(require('chai-xml'))
 chai.use(require('chai-json-schema'))
@@ -53,9 +53,7 @@ describe('Test syndication feeds', () => {
     }
 
     {
-      const attr = { username: 'john', password: 'password' }
-      await servers[0].users.create({ username: attr.username, password: attr.password })
-      userAccessToken = await servers[0].login.getAccessToken(attr)
+      userAccessToken = await servers[0].users.generateUserAndToken('john')
 
       const user = await servers[0].users.getMyInfo({ token: userAccessToken })
       userAccountId = user.account.id
@@ -109,6 +107,41 @@ describe('Test syndication feeds', () => {
         expect(JSON.parse(jsonText)).to.be.jsonSchema({ type: 'object' })
       }
     })
+
+    it('Should serve the endpoint with a classic request', async function () {
+      await makeGetRequest({
+        url: servers[0].url,
+        path: '/feeds/videos.xml',
+        accept: 'application/xml',
+        expectedStatus: HttpStatusCode.OK_200
+      })
+    })
+
+    it('Should serve the endpoint as a cached request', async function () {
+      const res = await makeGetRequest({
+        url: servers[0].url,
+        path: '/feeds/videos.xml',
+        accept: 'application/xml',
+        expectedStatus: HttpStatusCode.OK_200
+      })
+
+      expect(res.headers['x-api-cache-cached']).to.equal('true')
+    })
+
+    it('Should not serve the endpoint as a cached request', async function () {
+      const res = await makeGetRequest({
+        url: servers[0].url,
+        path: '/feeds/videos.xml?v=186',
+        accept: 'application/xml',
+        expectedStatus: HttpStatusCode.OK_200
+      })
+
+      expect(res.headers['x-api-cache-cached']).to.not.exist
+    })
+
+    it('Should refuse to serve the endpoint without accept header', async function () {
+      await makeGetRequest({ url: servers[0].url, path: '/feeds/videos.xml', expectedStatus: HttpStatusCode.NOT_ACCEPTABLE_406 })
+    })
   })
 
   describe('Videos feed', function () {
@@ -116,9 +149,9 @@ describe('Test syndication feeds', () => {
     it('Should contain a valid enclosure (covers RSS 2.0 endpoint)', async function () {
       for (const server of servers) {
         const rss = await server.feed.getXML({ feed: 'videos' })
-        expect(xmlParser.validate(rss)).to.be.true
+        expect(validate(rss)).to.be.true
 
-        const xmlDoc = xmlParser.parse(rss, { parseAttributeValue: true, ignoreAttributes: false })
+        const xmlDoc = parse(rss, { parseAttributeValue: true, ignoreAttributes: false })
 
         const enclosure = xmlDoc.rss.channel.item[0].enclosure
         expect(enclosure).to.exist