diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/cli/peertube.ts | 116 |
1 files changed, 103 insertions, 13 deletions
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index 80bbc98d5..6e7bf0843 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts | |||
@@ -1,28 +1,44 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | ||
2 | |||
1 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | ||
2 | import { | 5 | import { |
3 | expect | 6 | addVideoChannel, |
4 | } from 'chai' | 7 | buildAbsoluteFixturePath, |
5 | import { | 8 | cleanupTests, |
6 | createUser, | 9 | createUser, |
7 | execCLI, | 10 | execCLI, |
8 | flushTests, | ||
9 | getEnvCli, | ||
10 | killallServers, | ||
11 | flushAndRunServer, | 11 | flushAndRunServer, |
12 | getEnvCli, | ||
13 | getMyUserInformation, | ||
14 | getVideosList, | ||
12 | ServerInfo, | 15 | ServerInfo, |
13 | setAccessTokensToServers, cleanupTests | 16 | setAccessTokensToServers, |
17 | userLogin, waitJobs | ||
14 | } from '../../../shared/extra-utils' | 18 | } from '../../../shared/extra-utils' |
19 | import { User, Video } from '../../../shared' | ||
20 | import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports' | ||
15 | 21 | ||
16 | describe('Test CLI wrapper', function () { | 22 | describe('Test CLI wrapper', function () { |
17 | let server: ServerInfo | 23 | let server: ServerInfo |
24 | let channelId: number | ||
25 | |||
18 | const cmd = 'node ./dist/server/tools/peertube.js' | 26 | const cmd = 'node ./dist/server/tools/peertube.js' |
19 | 27 | ||
20 | before(async function () { | 28 | before(async function () { |
21 | this.timeout(30000) | 29 | this.timeout(30000) |
30 | |||
22 | server = await flushAndRunServer(1) | 31 | server = await flushAndRunServer(1) |
23 | await setAccessTokensToServers([ server ]) | 32 | await setAccessTokensToServers([ server ]) |
24 | 33 | ||
25 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' }) | 34 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' }) |
35 | |||
36 | const userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' }) | ||
37 | |||
38 | { | ||
39 | const res = await addVideoChannel(server.url, userAccessToken, { name: 'user_channel', displayName: 'User channel' }) | ||
40 | channelId = res.body.videoChannel.id | ||
41 | } | ||
26 | }) | 42 | }) |
27 | 43 | ||
28 | it('Should display no selected instance', async function () { | 44 | it('Should display no selected instance', async function () { |
@@ -31,21 +47,95 @@ describe('Test CLI wrapper', function () { | |||
31 | const env = getEnvCli(server) | 47 | const env = getEnvCli(server) |
32 | const stdout = await execCLI(`${env} ${cmd} --help`) | 48 | const stdout = await execCLI(`${env} ${cmd} --help`) |
33 | 49 | ||
34 | expect(stdout).to.contain('selected') | 50 | expect(stdout).to.contain('no instance selected') |
51 | }) | ||
52 | |||
53 | it('Should add a user', async function () { | ||
54 | this.timeout(60000) | ||
55 | |||
56 | const env = getEnvCli(server) | ||
57 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) | ||
58 | }) | ||
59 | |||
60 | it('Should default to this user', async function () { | ||
61 | this.timeout(60000) | ||
62 | |||
63 | const env = getEnvCli(server) | ||
64 | const stdout = await execCLI(`${env} ${cmd} --help`) | ||
65 | |||
66 | expect(stdout).to.contain(`instance ${server.url} selected`) | ||
67 | }) | ||
68 | |||
69 | it('Should remember the user', async function () { | ||
70 | this.timeout(60000) | ||
71 | |||
72 | const env = getEnvCli(server) | ||
73 | const stdout = await execCLI(`${env} ${cmd} auth list`) | ||
74 | |||
75 | expect(stdout).to.contain(server.url) | ||
76 | }) | ||
77 | |||
78 | it('Should upload a video', async function () { | ||
79 | this.timeout(60000) | ||
80 | |||
81 | const env = getEnvCli(server) | ||
82 | |||
83 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') | ||
84 | |||
85 | const params = `-f ${fixture} --video-name 'test upload' --channel-id ${channelId}` | ||
86 | |||
87 | await execCLI(`${env} ${cmd} upload ${params}`) | ||
88 | }) | ||
89 | |||
90 | it('Should have the video uploaded', async function () { | ||
91 | const res = await getVideosList(server.url) | ||
92 | |||
93 | expect(res.body.total).to.equal(1) | ||
94 | |||
95 | const videos: Video[] = res.body.data | ||
96 | expect(videos[0].name).to.equal('test upload') | ||
97 | expect(videos[0].channel.name).to.equal('user_channel') | ||
98 | }) | ||
99 | |||
100 | it('Should import a video', async function () { | ||
101 | this.timeout(60000) | ||
102 | |||
103 | const env = getEnvCli(server) | ||
104 | |||
105 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-id ${channelId}` | ||
106 | |||
107 | await execCLI(`${env} ${cmd} import ${params}`) | ||
35 | }) | 108 | }) |
36 | 109 | ||
37 | it('Should remember the authentifying material of the user', async function () { | 110 | it('Should have imported the video', async function () { |
38 | this.timeout(60000) | 111 | this.timeout(60000) |
39 | 112 | ||
113 | await waitJobs([ server ]) | ||
114 | |||
115 | const res = await getVideosList(server.url) | ||
116 | |||
117 | expect(res.body.total).to.equal(2) | ||
118 | |||
119 | const videos: Video[] = res.body.data | ||
120 | const video = videos.find(v => v.name === 'small video - youtube') | ||
121 | |||
122 | expect(video).to.not.be.undefined | ||
123 | expect(video.channel.name).to.equal('user_channel') | ||
124 | }) | ||
125 | |||
126 | it('Should remove the auth user', async function () { | ||
40 | const env = getEnvCli(server) | 127 | const env = getEnvCli(server) |
41 | await execCLI(`${env} ` + cmd + ` auth add --url ${server.url} -U user_1 -p "super password"`) | 128 | |
129 | await execCLI(`${env} ${cmd} auth del ${server.url}`) | ||
130 | |||
131 | const stdout = await execCLI(`${env} ${cmd} --help`) | ||
132 | |||
133 | expect(stdout).to.contain('no instance selected') | ||
42 | }) | 134 | }) |
43 | 135 | ||
44 | after(async function () { | 136 | after(async function () { |
45 | this.timeout(10000) | 137 | this.timeout(10000) |
46 | 138 | ||
47 | await execCLI(cmd + ` auth del ${server.url}`) | ||
48 | |||
49 | await cleanupTests([ server ]) | 139 | await cleanupTests([ server ]) |
50 | }) | 140 | }) |
51 | }) | 141 | }) |