]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/videos/videos-history.ts
emit more specific status codes on video upload (#3423)
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / videos-history.ts
index f654a422bd45eff49ae18dd0fd50944df6f1b775..661d603cb9a369cc2765d44d597669bce1ecd553 100644 (file)
@@ -1,23 +1,26 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import * as chai from 'chai'
 import 'mocha'
 import {
+  cleanupTests,
   createUser,
-  flushTests,
+  flushAndRunServer,
   getVideosListWithToken,
   getVideoWithToken,
   killallServers,
-  runServer,
+  reRunServer,
   searchVideoWithToken,
   ServerInfo,
   setAccessTokensToServers,
   updateMyUser,
   uploadVideo,
-  userLogin
-} from '../../../../shared/utils'
+  userLogin,
+  wait
+} from '../../../../shared/extra-utils'
 import { Video, VideoDetails } from '../../../../shared/models/videos'
-import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/utils/videos/video-history'
+import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '../../../../shared/extra-utils/videos/video-history'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 
 const expect = chai.expect
 
@@ -32,9 +35,7 @@ describe('Test videos history', function () {
   before(async function () {
     this.timeout(30000)
 
-    await flushTests()
-
-    server = await runServer(1)
+    server = await flushAndRunServer(1)
 
     await setAccessTokensToServers([ server ])
 
@@ -57,7 +58,7 @@ describe('Test videos history', function () {
       username: 'user_1',
       password: 'super password'
     }
-    await createUser(server.url, server.accessToken, user.username, user.password)
+    await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
     userAccessToken = await userLogin(server, user)
   })
 
@@ -171,7 +172,7 @@ describe('Test videos history', function () {
       videosHistoryEnabled: false
     })
 
-    await userWatchVideo(server.url, server.accessToken, video2UUID, 8, 409)
+    await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409)
   })
 
   it('Should re-enable videos history', async function () {
@@ -192,12 +193,36 @@ describe('Test videos history', function () {
     expect(videos[1].name).to.equal('video 3')
   })
 
-  after(async function () {
+  it('Should not clean old history', async function () {
+    this.timeout(50000)
+
     killallServers([ server ])
 
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
-    }
+    await reRunServer(server, { history: { videos: { max_age: '10 days' } } })
+
+    await wait(6000)
+
+    // Should still have history
+
+    const res = await listMyVideosHistory(server.url, server.accessToken)
+
+    expect(res.body.total).to.equal(2)
+  })
+
+  it('Should clean old history', async function () {
+    this.timeout(50000)
+
+    killallServers([ server ])
+
+    await reRunServer(server, { history: { videos: { max_age: '5 seconds' } } })
+
+    await wait(6000)
+
+    const res = await listMyVideosHistory(server.url, server.accessToken)
+    expect(res.body.total).to.equal(0)
+  })
+
+  after(async function () {
+    await cleanupTests([ server ])
   })
 })