]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/miscs/miscs.ts
Hide schedule privacy if private does not exist
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / miscs / miscs.ts
index aea9563cf4799792458704018c55a438a024fc63..462b914d41735ebc139defb4e34d288ba1ff49a8 100644 (file)
@@ -6,6 +6,7 @@ import { ensureDir, pathExists, readFile, stat } from 'fs-extra'
 import { basename, dirname, isAbsolute, join, resolve } from 'path'
 import * as request from 'supertest'
 import * as WebTorrent from 'webtorrent'
+import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
 
 const expect = chai.expect
 let webtorrent: WebTorrent.Instance
@@ -51,7 +52,7 @@ function buildServerDirectory (server: { internalServerNumber: number }, directo
 async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') {
   const res = await request(url)
     .get(imagePath)
-    .expect(200)
+    .expect(HttpStatusCode.OK_200)
 
   const body = res.body
 
@@ -59,8 +60,18 @@ async function testImage (url: string, imageName: string, imagePath: string, ext
   const minLength = body.length - ((30 * body.length) / 100)
   const maxLength = body.length + ((30 * body.length) / 100)
 
-  expect(data.length).to.be.above(minLength, "the generated image is way smaller than the recorded fixture")
-  expect(data.length).to.be.below(maxLength, "the generated image is way larger than the recorded fixture")
+  expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture')
+  expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture')
+}
+
+async function testFileExistsOrNot (server: { internalServerNumber: number }, directory: string, filePath: string, exist: boolean) {
+  const base = buildServerDirectory(server, directory)
+
+  expect(await pathExists(join(base, filePath))).to.equal(exist)
+}
+
+function isGithubCI () {
+  return !!process.env.GITHUB_WORKSPACE
 }
 
 function buildAbsoluteFixturePath (path: string, customCIPath = false) {
@@ -150,7 +161,9 @@ export {
   getFileSize,
   immutableAssign,
   testImage,
+  isGithubCI,
   buildAbsoluteFixturePath,
+  testFileExistsOrNot,
   root,
   generateHighBitrateVideo,
   generateVideoWithFramerate