X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Fproxy.ts;h=c40a4f9b8ff75d8bfbb431469ef98975b91b1770;hb=fb3c9e2bf5b45d6d283cea4d55cc0d49eb58e3cb;hp=d5042ef27bd656abf8efc6824364b1b200a63e99;hpb=8729a87024fc837f7dd6f13afeec90cf6dda1c06;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/proxy.ts b/server/tests/api/server/proxy.ts index d5042ef27..c40a4f9b8 100644 --- a/server/tests/api/server/proxy.ts +++ b/server/tests/api/server/proxy.ts @@ -2,8 +2,17 @@ import 'mocha' import * as chai from 'chai' -import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils' -import { MockProxy } from '@shared/extra-utils/mock-servers/mock-proxy' +import { FIXTURE_URLS, MockProxy } from '@server/tests/shared' +import { HttpStatusCode, VideoPrivacy } from '@shared/models' +import { + cleanupTests, + createMultipleServers, + doubleFollow, + PeerTubeServer, + setAccessTokensToServers, + setDefaultVideoChannel, + waitJobs +} from '@shared/server-commands' const expect = chai.expect @@ -25,47 +34,94 @@ describe('Test proxy', function () { goodEnv.HTTP_PROXY = 'http://localhost:' + proxyPort await setAccessTokensToServers(servers) + await setDefaultVideoChannel(servers) await doubleFollow(servers[0], servers[1]) }) - it('Should succeed federation with the appropriate proxy config', async function () { - await servers[0].kill() - await servers[0].run({}, { env: goodEnv }) + describe('Federation', function () { - await servers[0].videos.quickUpload({ name: 'video 1' }) + it('Should succeed federation with the appropriate proxy config', async function () { + this.timeout(40000) - await waitJobs(servers) + await servers[0].kill() + await servers[0].run({}, { env: goodEnv }) - for (const server of servers) { - const { total, data } = await server.videos.list() - expect(total).to.equal(1) - expect(data).to.have.lengthOf(1) - } + await servers[0].videos.quickUpload({ name: 'video 1' }) + + await waitJobs(servers) + + for (const server of servers) { + const { total, data } = await server.videos.list() + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + } + }) + + it('Should fail federation with a wrong proxy config', async function () { + this.timeout(40000) + + await servers[0].kill() + await servers[0].run({}, { env: badEnv }) + + await servers[0].videos.quickUpload({ name: 'video 2' }) + + await waitJobs(servers) + + { + const { total, data } = await servers[0].videos.list() + expect(total).to.equal(2) + expect(data).to.have.lengthOf(2) + } + + { + const { total, data } = await servers[1].videos.list() + expect(total).to.equal(1) + expect(data).to.have.lengthOf(1) + } + }) }) - it('Should fail federation with a wrong proxy config', async function () { - await servers[0].kill() - await servers[0].run({}, { env: badEnv }) + describe('Videos import', async function () { + + function quickImport (expectedStatus: HttpStatusCode = HttpStatusCode.OK_200) { + return servers[0].imports.importVideo({ + attributes: { + name: 'video import', + channelId: servers[0].store.channel.id, + privacy: VideoPrivacy.PUBLIC, + targetUrl: FIXTURE_URLS.peertube_long + }, + expectedStatus + }) + } + + it('Should succeed import with the appropriate proxy config', async function () { + this.timeout(40000) + + await servers[0].kill() + await servers[0].run({}, { env: goodEnv }) - await servers[0].videos.quickUpload({ name: 'video 2' }) + await quickImport() - await waitJobs(servers) + await waitJobs(servers) - { const { total, data } = await servers[0].videos.list() - expect(total).to.equal(2) - expect(data).to.have.lengthOf(2) - } + expect(total).to.equal(3) + expect(data).to.have.lengthOf(3) + }) - { - const { total, data } = await servers[1].videos.list() - expect(total).to.equal(1) - expect(data).to.have.lengthOf(1) - } + it('Should fail import with a wrong proxy config', async function () { + this.timeout(40000) + + await servers[0].kill() + await servers[0].run({}, { env: badEnv }) + + await quickImport(HttpStatusCode.BAD_REQUEST_400) + }) }) after(async function () { - proxy.terminate() + await proxy.terminate() await cleanupTests(servers) })