X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Factivitypub%2Fclient.ts;h=572a358a04b300e6eb790cb049e8fb7c4fe1e51b;hb=cffef25313bdf7a6c435f56ac6715fdd91acf7b3;hp=0190df04c22e79c7cd4e3a80b070a119f0013ea1;hpb=d23dd9fbfc4d26026352c10f81d2795ceaf2908a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/activitypub/client.ts b/server/tests/api/activitypub/client.ts index 0190df04c..572a358a0 100644 --- a/server/tests/api/activitypub/client.ts +++ b/server/tests/api/activitypub/client.ts @@ -1,23 +1,20 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { expect } from 'chai' +import { processViewersStats } from '@server/tests/shared' +import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models' import { cleanupTests, + createMultipleServers, doubleFollow, - flushAndRunMultipleServers, makeActivityPubGetRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, setDefaultVideoChannel -} from '@shared/extra-utils' -import { VideoPlaylistPrivacy } from '@shared/models' - -const expect = chai.expect +} from '@shared/server-commands' describe('Test activitypub', function () { - let servers: ServerInfo[] = [] + let servers: PeerTubeServer[] = [] let video: { id: number, uuid: string, shortUUID: string } let playlist: { id: number, uuid: string, shortUUID: string } @@ -26,7 +23,7 @@ describe('Test activitypub', function () { const object = res.body expect(object.type).to.equal('Person') - expect(object.id).to.equal('http://localhost:' + servers[0].port + '/accounts/root') + expect(object.id).to.equal(servers[0].url + '/accounts/root') expect(object.name).to.equal('root') expect(object.preferredUsername).to.equal('root') } @@ -36,7 +33,7 @@ describe('Test activitypub', function () { 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.id).to.equal(servers[0].url + '/video-channels/root_channel') expect(object.name).to.equal('Main root channel') expect(object.preferredUsername).to.equal('root_channel') } @@ -46,7 +43,7 @@ describe('Test activitypub', function () { 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.id).to.equal(servers[0].url + '/videos/watch/' + video.uuid) expect(object.name).to.equal('video') } @@ -55,25 +52,25 @@ describe('Test activitypub', function () { 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.id).to.equal(servers[0].url + '/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].videosCommand.quickUpload({ name: 'video' }) + video = await servers[0].videos.quickUpload({ name: 'video' }) } { - const attributes = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id } - playlist = await servers[0].playlistsCommand.create({ attributes }) + 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]) @@ -113,7 +110,24 @@ describe('Test activitypub', function () { it('Should redirect to the origin video object', async function () { 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/' + video.uuid) + expect(res.header.location).to.equal(servers[0].url + '/videos/watch/' + video.uuid) + }) + + it('Should return the watch action', async function () { + this.timeout(50000) + + await servers[0].views.simulateViewer({ id: video.uuid, currentTimes: [ 0, 2 ] }) + await processViewersStats(servers) + + const res = await makeActivityPubGetRequest(servers[0].url, '/videos/local-viewer/1', HttpStatusCode.OK_200) + + const object: WatchActionObject = res.body + expect(object.type).to.equal('WatchAction') + expect(object.duration).to.equal('PT2S') + expect(object.actionStatus).to.equal('CompletedActionStatus') + expect(object.watchSections).to.have.lengthOf(1) + expect(object.watchSections[0].startTimestamp).to.equal(0) + expect(object.watchSections[0].endTimestamp).to.equal(2) }) after(async function () {