]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/logs.ts
Add ability for instances to follow any actor
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / logs.ts
index bc398ea731ac04bd8479fa1114703edb62c11a91..bcd94dda30618e6310d31c774e372b16d51c4fd3 100644 (file)
@@ -4,27 +4,27 @@ import 'mocha'
 import * as chai from 'chai'
 import {
   cleanupTests,
-  flushAndRunServer,
+  createSingleServer,
   killallServers,
-  makePingRequest,
-  reRunServer,
-  ServerInfo,
-  setAccessTokensToServers
-} from '../../../../shared/extra-utils/index'
-import { getAuditLogs, getLogs } from '../../../../shared/extra-utils/logs/logs'
-import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
-import { uploadVideo } from '../../../../shared/extra-utils/videos/videos'
+  LogsCommand,
+  PeerTubeServer,
+  setAccessTokensToServers,
+  waitJobs
+} from '@shared/extra-utils'
 
 const expect = chai.expect
 
 describe('Test logs', function () {
-  let server: ServerInfo
+  let server: PeerTubeServer
+  let logsCommand: LogsCommand
 
   before(async function () {
     this.timeout(30000)
 
-    server = await flushAndRunServer(1)
+    server = await createSingleServer(1)
     await setAccessTokensToServers([ server ])
+
+    logsCommand = server.logs
   })
 
   describe('With the standard log file', function () {
@@ -32,16 +32,16 @@ describe('Test logs', function () {
     it('Should get logs with a start date', async function () {
       this.timeout(20000)
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 1' })
+      await server.videos.upload({ attributes: { name: 'video 1' } })
       await waitJobs([ server ])
 
       const now = new Date()
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 2' })
+      await server.videos.upload({ attributes: { name: 'video 2' } })
       await waitJobs([ server ])
 
-      const res = await getLogs(server.url, server.accessToken, now)
-      const logsString = JSON.stringify(res.body)
+      const body = await logsCommand.getLogs({ startDate: now })
+      const logsString = JSON.stringify(body)
 
       expect(logsString.includes('video 1')).to.be.false
       expect(logsString.includes('video 2')).to.be.true
@@ -50,21 +50,21 @@ describe('Test logs', function () {
     it('Should get logs with an end date', async function () {
       this.timeout(30000)
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 3' })
+      await server.videos.upload({ attributes: { name: 'video 3' } })
       await waitJobs([ server ])
 
       const now1 = new Date()
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 4' })
+      await server.videos.upload({ attributes: { name: 'video 4' } })
       await waitJobs([ server ])
 
       const now2 = new Date()
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 5' })
+      await server.videos.upload({ attributes: { name: 'video 5' } })
       await waitJobs([ server ])
 
-      const res = await getLogs(server.url, server.accessToken, now1, now2)
-      const logsString = JSON.stringify(res.body)
+      const body = await logsCommand.getLogs({ startDate: now1, endDate: now2 })
+      const logsString = JSON.stringify(body)
 
       expect(logsString.includes('video 3')).to.be.false
       expect(logsString.includes('video 4')).to.be.true
@@ -76,19 +76,19 @@ describe('Test logs', function () {
 
       const now = new Date()
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 6' })
+      await server.videos.upload({ attributes: { name: 'video 6' } })
       await waitJobs([ server ])
 
       {
-        const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
-        const logsString = JSON.stringify(res.body)
+        const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
+        const logsString = JSON.stringify(body)
 
         expect(logsString.includes('video 6')).to.be.true
       }
 
       {
-        const res = await getLogs(server.url, server.accessToken, now, undefined, 'warn')
-        const logsString = JSON.stringify(res.body)
+        const body = await logsCommand.getLogs({ startDate: now, level: 'warn' })
+        const logsString = JSON.stringify(body)
 
         expect(logsString.includes('video 6')).to.be.false
       }
@@ -99,10 +99,10 @@ describe('Test logs', function () {
 
       const now = new Date()
 
-      await makePingRequest(server)
+      await server.servers.ping()
 
-      const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
-      const logsString = JSON.stringify(res.body)
+      const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
+      const logsString = JSON.stringify(body)
 
       expect(logsString.includes('/api/v1/ping')).to.be.true
     })
@@ -110,16 +110,16 @@ describe('Test logs', function () {
     it('Should not log ping requests', async function () {
       this.timeout(30000)
 
-      killallServers([ server ])
+      await killallServers([ server ])
 
-      await reRunServer(server, { log: { log_ping_requests: false } })
+      await server.run({ log: { log_ping_requests: false } })
 
       const now = new Date()
 
-      await makePingRequest(server)
+      await server.servers.ping()
 
-      const res = await getLogs(server.url, server.accessToken, now, undefined, 'info')
-      const logsString = JSON.stringify(res.body)
+      const body = await logsCommand.getLogs({ startDate: now, level: 'info' })
+      const logsString = JSON.stringify(body)
 
       expect(logsString.includes('/api/v1/ping')).to.be.false
     })
@@ -129,23 +129,23 @@ describe('Test logs', function () {
     it('Should get logs with a start date', async function () {
       this.timeout(20000)
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 7' })
+      await server.videos.upload({ attributes: { name: 'video 7' } })
       await waitJobs([ server ])
 
       const now = new Date()
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 8' })
+      await server.videos.upload({ attributes: { name: 'video 8' } })
       await waitJobs([ server ])
 
-      const res = await getAuditLogs(server.url, server.accessToken, now)
-      const logsString = JSON.stringify(res.body)
+      const body = await logsCommand.getAuditLogs({ startDate: now })
+      const logsString = JSON.stringify(body)
 
       expect(logsString.includes('video 7')).to.be.false
       expect(logsString.includes('video 8')).to.be.true
 
-      expect(res.body).to.have.lengthOf(1)
+      expect(body).to.have.lengthOf(1)
 
-      const item = res.body[0]
+      const item = body[0]
 
       const message = JSON.parse(item.message)
       expect(message.domain).to.equal('videos')
@@ -155,21 +155,21 @@ describe('Test logs', function () {
     it('Should get logs with an end date', async function () {
       this.timeout(30000)
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 9' })
+      await server.videos.upload({ attributes: { name: 'video 9' } })
       await waitJobs([ server ])
 
       const now1 = new Date()
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 10' })
+      await server.videos.upload({ attributes: { name: 'video 10' } })
       await waitJobs([ server ])
 
       const now2 = new Date()
 
-      await uploadVideo(server.url, server.accessToken, { name: 'video 11' })
+      await server.videos.upload({ attributes: { name: 'video 11' } })
       await waitJobs([ server ])
 
-      const res = await getAuditLogs(server.url, server.accessToken, now1, now2)
-      const logsString = JSON.stringify(res.body)
+      const body = await logsCommand.getAuditLogs({ startDate: now1, endDate: now2 })
+      const logsString = JSON.stringify(body)
 
       expect(logsString.includes('video 9')).to.be.false
       expect(logsString.includes('video 10')).to.be.true