X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=inline;f=server%2Ftests%2Fapi%2Factivitypub%2Fclient.ts;h=720231f025a24674c209d922c25f5125cbe322d7;hb=254d3579f5338f5fd775c17d15cdfc37078bcfb4;hp=b6c538e19781a2f1cd445f1cf8cb40056f1ed1cd;hpb=f2eb23cd87cf32b8fe545178143b5f49e06a58da;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index b6c538e19..720231f02 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -1,62 +1,119 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import * as chai from 'chai' import 'mocha' +import * as chai from 'chai' +import { HttpStatusCode } from '@shared/core-utils' import { cleanupTests, doubleFollow, - flushAndRunMultipleServers, + createMultipleServers, makeActivityPubGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - uploadVideo -} from '../../../../shared/extra-utils' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' + setDefaultVideoChannel +} from '@shared/extra-utils' +import { VideoPlaylistPrivacy } from '@shared/models' const expect = chai.expect describe('Test activitypub', function () { - let servers: ServerInfo[] = [] - let videoUUID: string + let servers: PeerTubeServer[] = [] + let video: { id: number, uuid: string, shortUUID: string } + let playlist: { id: number, uuid: string, shortUUID: string } + + async function testAccount (path: string) { + const res = await makeActivityPubGetRequest(servers[0].url, path) + const object = res.body + + expect(object.type).to.equal('Person') + expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root') + expect(object.name).to.equal('root') + expect(object.preferredUsername).to.equal('root') + } + + async function testChannel (path: string) { + const res = await makeActivityPubGetRequest(servers[0].url, path) + const object = res.body + + expect(object.type).to.equal('Group') + expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-channels/root_channel') + expect(object.name).to.equal('Main root channel') + expect(object.preferredUsername).to.equal('root_channel') + } + + async function testVideo (path: string) { + const res = await makeActivityPubGetRequest(servers[0].url, path) + const object = res.body + + expect(object.type).to.equal('Video') + expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) + expect(object.name).to.equal('video') + } + + async function testPlaylist (path: string) { + const res = await makeActivityPubGetRequest(servers[0].url, path) + const object = res.body + + expect(object.type).to.equal('Playlist') + expect(object.id).to.equal('http://localhost:' + servers[0].port + '/video-playlists/' + playlist.uuid) + expect(object.name).to.equal('playlist') + } before(async function () { this.timeout(30000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) + await setDefaultVideoChannel(servers) + + { + video = await await servers[0].videos.quickUpload({ name: 'video' }) + } { - const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) - videoUUID = res.body.video.uuid + const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].store.channel.id } + playlist = await servers[0].playlists.create({ attributes }) } await doubleFollow(servers[0], servers[1]) }) it('Should return the account object', async function () { - const res = await makeActivityPubGetRequest(servers[0].url, '/accounts/root') - const object = res.body + await testAccount('/accounts/root') + await testAccount('/a/root') + }) - expect(object.type).to.equal('Person') - expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root') - expect(object.name).to.equal('root') - expect(object.preferredUsername).to.equal('root') + it('Should return the channel object', async function () { + await testChannel('/video-channels/root_channel') + await testChannel('/c/root_channel') }) it('Should return the video object', async function () { - const res = await makeActivityPubGetRequest(servers[0].url, '/videos/watch/' + videoUUID) - const object = res.body + await testVideo('/videos/watch/' + video.id) + await testVideo('/videos/watch/' + video.uuid) + await testVideo('/videos/watch/' + video.shortUUID) + await testVideo('/w/' + video.id) + await testVideo('/w/' + video.uuid) + await testVideo('/w/' + video.shortUUID) + }) - expect(object.type).to.equal('Video') - expect(object.id).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) - expect(object.name).to.equal('video') + it('Should return the playlist object', async function () { + await testPlaylist('/video-playlists/' + playlist.id) + await testPlaylist('/video-playlists/' + playlist.uuid) + await testPlaylist('/video-playlists/' + playlist.shortUUID) + await testPlaylist('/w/p/' + playlist.id) + await testPlaylist('/w/p/' + playlist.uuid) + await testPlaylist('/w/p/' + playlist.shortUUID) + await testPlaylist('/videos/watch/playlist/' + playlist.id) + await testPlaylist('/videos/watch/playlist/' + playlist.uuid) + await testPlaylist('/videos/watch/playlist/' + playlist.shortUUID) }) it('Should redirect to the origin video object', async function () { - const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, HttpStatusCode.FOUND_302) + const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + video.uuid, HttpStatusCode.FOUND_302) - expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + videoUUID) + expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/videos/watch/' + video.uuid) }) after(async function () {