import 'mocha'
import * as chai from 'chai'
-import { VideoPlaylistPrivacy } from '@shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+import { processViewersStats } from '@server/tests/shared'
+import { HttpStatusCode, VideoPlaylistPrivacy, WatchActionObject } from '@shared/models'
import {
cleanupTests,
- createVideoPlaylist,
+ createMultipleServers,
doubleFollow,
- flushAndRunMultipleServers,
makeActivityPubGetRequest,
- ServerInfo,
+ PeerTubeServer,
setAccessTokensToServers,
- setDefaultVideoChannel,
- uploadVideoAndGetId
-} from '../../../../shared/extra-utils'
+ setDefaultVideoChannel
+} from '@shared/server-commands'
const expect = chai.expect
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 }
before(async function () {
this.timeout(30000)
- servers = await flushAndRunMultipleServers(2)
+ servers = await createMultipleServers(2)
await setAccessTokensToServers(servers)
await setDefaultVideoChannel(servers)
{
- video = await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })
+ video = await servers[0].videos.quickUpload({ name: 'video' })
}
{
- const playlistAttrs = { displayName: 'playlist', privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: servers[0].videoChannel.id }
- const resCreate = await createVideoPlaylist({ url: servers[0].url, token: servers[0].accessToken, playlistAttrs })
- playlist = resCreate.body.videoPlaylist
+ 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])
expect(res.header.location).to.equal('http://localhost:' + servers[0].port + '/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 () {
await cleanupTests(servers)
})