Cleanup tests
[oweals/peertube.git] / server / tests / api / activitypub / client.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6   doubleFollow,
7   flushAndRunMultipleServers,
8   flushTests,
9   killallServers,
10   makeActivityPubGetRequest,
11   ServerInfo,
12   setAccessTokensToServers,
13   uploadVideo
14 } from '../../../../shared/extra-utils'
15
16 const expect = chai.expect
17
18 describe('Test activitypub', function () {
19   let servers: ServerInfo[] = []
20   let videoUUID: string
21
22   before(async function () {
23     this.timeout(30000)
24
25     servers = await flushAndRunMultipleServers(2)
26
27     await setAccessTokensToServers(servers)
28
29     {
30       const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' })
31       videoUUID = res.body.video.uuid
32     }
33
34     await doubleFollow(servers[0], servers[1])
35   })
36
37   it('Should return the account object', async function () {
38     const res = await makeActivityPubGetRequest(servers[0].url, '/accounts/root')
39     const object = res.body
40
41     expect(object.type).to.equal('Person')
42     expect(object.id).to.equal('http://localhost:9001/accounts/root')
43     expect(object.name).to.equal('root')
44     expect(object.preferredUsername).to.equal('root')
45   })
46
47   it('Should return the video object', async function () {
48     const res = await makeActivityPubGetRequest(servers[0].url, '/videos/watch/' + videoUUID)
49     const object = res.body
50
51     expect(object.type).to.equal('Video')
52     expect(object.id).to.equal('http://localhost:9001/videos/watch/' + videoUUID)
53     expect(object.name).to.equal('video')
54   })
55
56   it('Should redirect to the origin video object', async function () {
57     const res = await makeActivityPubGetRequest(servers[1].url, '/videos/watch/' + videoUUID, 302)
58
59     expect(res.header.location).to.equal('http://localhost:9001/videos/watch/' + videoUUID)
60   })
61
62   after(function () {
63     killallServers(servers)
64   })
65 })