aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli/update-host.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/cli/update-host.ts')
-rw-r--r--server/tests/cli/update-host.ts79
1 files changed, 30 insertions, 49 deletions
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index 2070f16f5..fcbcb55ba 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -1,33 +1,20 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import { expect } from 'chai'
5import { VideoDetails } from '../../../shared/models/videos'
6import { waitJobs } from '../../../shared/extra-utils/server/jobs'
7import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
8import { 5import {
9 addVideoChannel,
10 cleanupTests, 6 cleanupTests,
11 createUser, 7 createSingleServer,
12 execCLI,
13 flushAndRunServer,
14 getEnvCli,
15 getVideo,
16 getVideoChannelsList,
17 getVideosList,
18 killallServers, 8 killallServers,
19 makeActivityPubGetRequest, 9 makeActivityPubGetRequest,
20 parseTorrentVideo, reRunServer, 10 parseTorrentVideo,
21 ServerInfo, 11 PeerTubeServer,
22 setAccessTokensToServers, 12 setAccessTokensToServers,
23 uploadVideo 13 waitJobs
24} from '../../../shared/extra-utils' 14} from '@shared/extra-utils'
25import { getAccountsList } from '../../../shared/extra-utils/users/accounts'
26
27const expect = chai.expect
28 15
29describe('Test update host scripts', function () { 16describe('Test update host scripts', function () {
30 let server: ServerInfo 17 let server: PeerTubeServer
31 18
32 before(async function () { 19 before(async function () {
33 this.timeout(60000) 20 this.timeout(60000)
@@ -38,17 +25,15 @@ describe('Test update host scripts', function () {
38 } 25 }
39 } 26 }
40 // Run server 2 to have transcoding enabled 27 // Run server 2 to have transcoding enabled
41 server = await flushAndRunServer(2, overrideConfig) 28 server = await createSingleServer(2, overrideConfig)
42 await setAccessTokensToServers([ server ]) 29 await setAccessTokensToServers([ server ])
43 30
44 // Upload two videos for our needs 31 // Upload two videos for our needs
45 const videoAttributes = {} 32 const { uuid: video1UUID } = await server.videos.upload()
46 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes) 33 await server.videos.upload()
47 const video1UUID = resVideo1.body.video.uuid
48 await uploadVideo(server.url, server.accessToken, videoAttributes)
49 34
50 // Create a user 35 // Create a user
51 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' }) 36 await server.users.create({ username: 'toto', password: 'coucou' })
52 37
53 // Create channel 38 // Create channel
54 const videoChannel = { 39 const videoChannel = {
@@ -56,11 +41,11 @@ describe('Test update host scripts', function () {
56 displayName: 'second video channel', 41 displayName: 'second video channel',
57 description: 'super video channel description' 42 description: 'super video channel description'
58 } 43 }
59 await addVideoChannel(server.url, server.accessToken, videoChannel) 44 await server.channels.create({ attributes: videoChannel })
60 45
61 // Create comments 46 // Create comments
62 const text = 'my super first comment' 47 const text = 'my super first comment'
63 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text) 48 await server.comments.createThread({ videoId: video1UUID, text })
64 49
65 await waitJobs(server) 50 await waitJobs(server)
66 }) 51 })
@@ -68,25 +53,23 @@ describe('Test update host scripts', function () {
68 it('Should run update host', async function () { 53 it('Should run update host', async function () {
69 this.timeout(30000) 54 this.timeout(30000)
70 55
71 killallServers([ server ]) 56 await killallServers([ server ])
72 // Run server with standard configuration 57 // Run server with standard configuration
73 await reRunServer(server) 58 await server.run()
74 59
75 const env = getEnvCli(server) 60 await server.cli.execWithEnv(`npm run update-host`)
76 await execCLI(`${env} npm run update-host`)
77 }) 61 })
78 62
79 it('Should have updated videos url', async function () { 63 it('Should have updated videos url', async function () {
80 const res = await getVideosList(server.url) 64 const { total, data } = await server.videos.list()
81 expect(res.body.total).to.equal(2) 65 expect(total).to.equal(2)
82 66
83 for (const video of res.body.data) { 67 for (const video of data) {
84 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) 68 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
85 69
86 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) 70 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
87 71
88 const res = await getVideo(server.url, video.uuid) 72 const videoDetails = await server.videos.get({ id: video.uuid })
89 const videoDetails: VideoDetails = res.body
90 73
91 expect(videoDetails.trackerUrls[0]).to.include(server.host) 74 expect(videoDetails.trackerUrls[0]).to.include(server.host)
92 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host) 75 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
@@ -95,10 +78,10 @@ describe('Test update host scripts', function () {
95 }) 78 })
96 79
97 it('Should have updated video channels url', async function () { 80 it('Should have updated video channels url', async function () {
98 const res = await getVideoChannelsList(server.url, 0, 5, '-name') 81 const { data, total } = await server.channels.list({ sort: '-name' })
99 expect(res.body.total).to.equal(3) 82 expect(total).to.equal(3)
100 83
101 for (const channel of res.body.data) { 84 for (const channel of data) {
102 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name) 85 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
103 86
104 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name) 87 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
@@ -106,10 +89,10 @@ describe('Test update host scripts', function () {
106 }) 89 })
107 90
108 it('Should have updated accounts url', async function () { 91 it('Should have updated accounts url', async function () {
109 const res = await getAccountsList(server.url) 92 const body = await server.accounts.list()
110 expect(res.body.total).to.equal(3) 93 expect(body.total).to.equal(3)
111 94
112 for (const account of res.body.data) { 95 for (const account of body.data) {
113 const usernameWithDomain = account.name 96 const usernameWithDomain = account.name
114 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) 97 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
115 98
@@ -120,13 +103,11 @@ describe('Test update host scripts', function () {
120 it('Should have updated torrent hosts', async function () { 103 it('Should have updated torrent hosts', async function () {
121 this.timeout(30000) 104 this.timeout(30000)
122 105
123 const res = await getVideosList(server.url) 106 const { data } = await server.videos.list()
124 const videos = res.body.data 107 expect(data).to.have.lengthOf(2)
125 expect(videos).to.have.lengthOf(2)
126 108
127 for (const video of videos) { 109 for (const video of data) {
128 const res2 = await getVideo(server.url, video.id) 110 const videoDetails = await server.videos.get({ id: video.id })
129 const videoDetails: VideoDetails = res2.body
130 111
131 expect(videoDetails.files).to.have.lengthOf(4) 112 expect(videoDetails.files).to.have.lengthOf(4)
132 113