X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fshared%2Fchecks.ts;h=55ebc6c3e18569b93436d42c24ebf46a6daa22b7;hb=91a4893063402d7beabb3104f9b989b8f88b6038;hp=9ecc84b5d8d8ac602e9523ea50aad275ed8370b8;hpb=3318147300b4f998adf728eb0a5a14a4c1829c51;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/shared/checks.ts b/server/tests/shared/checks.ts index 9ecc84b5d..55ebc6c3e 100644 --- a/server/tests/shared/checks.ts +++ b/server/tests/shared/checks.ts @@ -19,27 +19,37 @@ function expectStartWith (str: string, start: string) { expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.true } +function expectNotStartWith (str: string, start: string) { + expect(str.startsWith(start), `${str} does not start with ${start}`).to.be.false +} + async function expectLogDoesNotContain (server: PeerTubeServer, str: string) { const content = await server.servers.getLogContent() expect(content.toString()).to.not.contain(str) } -async function testImage (url: string, imageName: string, imagePath: string, extension = '.jpg') { +async function expectLogContain (server: PeerTubeServer, str: string) { + const content = await server.servers.getLogContent() + + expect(content.toString()).to.contain(str) +} + +async function testImage (url: string, imageName: string, imageHTTPPath: string, extension = '.jpg') { const res = await makeGetRequest({ url, - path: imagePath, + path: imageHTTPPath, expectedStatus: HttpStatusCode.OK_200 }) const body = res.body const data = await readFile(join(root(), 'server', 'tests', 'fixtures', imageName + extension)) - const minLength = body.length - ((30 * body.length) / 100) - const maxLength = body.length + ((30 * body.length) / 100) + const minLength = data.length - ((40 * data.length) / 100) + const maxLength = data.length + ((40 * data.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(body.length).to.be.above(minLength, 'the generated image is way smaller than the recorded fixture') + expect(body.length).to.be.below(maxLength, 'the generated image is way larger than the recorded fixture') } async function testFileExistsOrNot (server: PeerTubeServer, directory: string, filePath: string, exist: boolean) { @@ -92,7 +102,9 @@ export { expectLogDoesNotContain, testFileExistsOrNot, expectStartWith, + expectNotStartWith, checkBadStartPagination, checkBadCountPagination, - checkBadSortPagination + checkBadSortPagination, + expectLogContain }