diff options
author | Chocobozzz <me@florianbigard.com> | 2021-12-17 11:58:15 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-12-17 12:24:03 +0100 |
commit | c55e3d7227fe1453869e309025996b9d75256d5d (patch) | |
tree | 08e9b0ca210d75c82c8606fef0852eca020e8e0e /shared/server-commands/miscs/checks.ts | |
parent | bf54587a3e2ad9c2c186828f2a5682b91ee2cc00 (diff) | |
download | PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.gz PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.tar.zst PeerTube-c55e3d7227fe1453869e309025996b9d75256d5d.zip |
Move test functions outside extra-utils
Diffstat (limited to 'shared/server-commands/miscs/checks.ts')
-rw-r--r-- | shared/server-commands/miscs/checks.ts | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/shared/server-commands/miscs/checks.ts b/shared/server-commands/miscs/checks.ts deleted file mode 100644 index 589928997..000000000 --- a/shared/server-commands/miscs/checks.ts +++ /dev/null | |||
@@ -1,58 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/no-floating-promises */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { pathExists, readFile } from 'fs-extra' | ||
5 | import { join } from 'path' | ||
6 | import { root } from '@shared/core-utils' | ||
7 | import { HttpStatusCode } from '@shared/models' | ||
8 | import { makeGetRequest } from '../requests' | ||
9 | import { PeerTubeServer } from '../server' | ||
10 | |||
11 | // Default interval -> 5 minutes | ||
12 | function dateIsValid (dateString: string, interval = 300000) { | ||
13 | const dateToCheck = new Date(dateString) | ||
14 | const now = new Date() | ||
15 | |||
16 | return Math.abs(now.getTime() - dateToCheck.getTime()) <= interval | ||
17 | } | ||
18 | |||
19 | function expectStartWith (str: string, start: string) { | ||
20 | expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.true | ||
21 | } | ||
22 | |||
23 | async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { | ||
24 | const content = await server.servers.getLogContent() | ||
25 | |||
26 | expect(content.toString()).to.not.contain(str) | ||
27 | } | ||
28 | |||
29 | async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { | ||
30 | const res = await makeGetRequest({ | ||
31 | url, | ||
32 | path: imagePath, | ||
33 | expectedStatus: HttpStatusCode.OK_200 | ||
34 | }) | ||
35 | |||
36 | const body = res.body | ||
37 | |||
38 | const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) | ||
39 | const minLength = body.length - ((30 * body.length) / 100) | ||
40 | const maxLength = body.length + ((30 * body.length) / 100) | ||
41 | |||
42 | expect(data.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') | ||
43 | expect(data.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') | ||
44 | } | ||
45 | |||
46 | async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { | ||
47 | const base = server.servers.buildDirectory(directory) | ||
48 | |||
49 | expect(await pathExists(join(base, filePath))).to.equal(exist) | ||
50 | } | ||
51 | |||
52 | export { | ||
53 | dateIsValid, | ||
54 | testImage, | ||
55 | expectLogDoesNotContain, | ||
56 | testFileExistsOrNot, | ||
57 | expectStartWith | ||
58 | } | ||