+ describe('Cache', function () {
+ const uuids: string[] = []
+
+ function doPodcastRequest () {
+ return makeGetRequest({
+ url: servers[0].url,
+ path: '/feeds/podcast/videos.xml',
+ query: { videoChannelId: servers[0].store.channel.id },
+ accept: 'application/xml',
+ expectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ function doVideosRequest (query: { [id: string]: string } = {}) {
+ return makeGetRequest({
+ url: servers[0].url,
+ path: '/feeds/videos.xml',
+ query,
+ accept: 'application/xml',
+ expectedStatus: HttpStatusCode.OK_200
+ })
+ }
+
+ before(async function () {
+ {
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'cache 1' })
+ uuids.push(uuid)
+ }
+
+ {
+ const { uuid } = await servers[0].videos.quickUpload({ name: 'cache 2' })
+ uuids.push(uuid)
+ }
+ })
+
+ it('Should serve the videos endpoint as a cached request', async function () {
+ await doVideosRequest()
+
+ const res = await doVideosRequest()
+
+ expect(res.headers['x-api-cache-cached']).to.equal('true')
+ })
+
+ it('Should not serve the videos endpoint as a cached request', async function () {
+ const res = await doVideosRequest({ v: '186' })
+
+ expect(res.headers['x-api-cache-cached']).to.not.exist
+ })
+
+ it('Should invalidate the podcast feed cache after video deletion', async function () {
+ await doPodcastRequest()
+
+ {
+ const res = await doPodcastRequest()
+ expect(res.headers['x-api-cache-cached']).to.exist
+ }
+
+ await servers[0].videos.remove({ id: uuids[0] })
+
+ {
+ const res = await doPodcastRequest()
+ expect(res.headers['x-api-cache-cached']).to.not.exist
+ }
+ })
+
+ it('Should invalidate the podcast feed cache after video deletion, even after server restart', async function () {
+ this.timeout(120000)
+
+ await doPodcastRequest()
+
+ {
+ const res = await doPodcastRequest()
+ expect(res.headers['x-api-cache-cached']).to.exist
+ }
+
+ await servers[0].kill()
+ await servers[0].run()
+
+ await servers[0].videos.remove({ id: uuids[1] })
+
+ const res = await doPodcastRequest()
+ expect(res.headers['x-api-cache-cached']).to.not.exist
+ })
+
+ })
+