]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as chai from 'chai' | |
4 | import 'mocha' | |
5 | import { | |
6 | cleanupTests, | |
7 | flushAndRunMultipleServers, | |
8 | killallServers, | |
9 | reRunServer, | |
10 | ServerInfo, | |
11 | waitUntilLog | |
12 | } from '../../../shared/extra-utils/server/servers' | |
13 | import { | |
14 | addVideoCommentReply, | |
15 | addVideoCommentThread, | |
16 | blockUser, | |
17 | createUser, | |
18 | deleteVideoComment, | |
19 | getPluginTestPath, | |
20 | installPlugin, login, | |
21 | registerUser, removeUser, | |
22 | setAccessTokensToServers, | |
23 | unblockUser, updateUser, | |
24 | updateVideo, | |
25 | uploadVideo, | |
26 | viewVideo, | |
27 | userLogin | |
28 | } from '../../../shared/extra-utils' | |
29 | ||
30 | const expect = chai.expect | |
31 | ||
32 | describe('Test plugin action hooks', function () { | |
33 | let servers: ServerInfo[] | |
34 | let videoUUID: string | |
35 | let threadId: number | |
36 | ||
37 | function checkHook (hook: string) { | |
38 | return waitUntilLog(servers[0], 'Run hook ' + hook) | |
39 | } | |
40 | ||
41 | before(async function () { | |
42 | this.timeout(30000) | |
43 | ||
44 | servers = await flushAndRunMultipleServers(2) | |
45 | await setAccessTokensToServers(servers) | |
46 | ||
47 | await installPlugin({ | |
48 | url: servers[0].url, | |
49 | accessToken: servers[0].accessToken, | |
50 | path: getPluginTestPath() | |
51 | }) | |
52 | ||
53 | killallServers([ servers[0] ]) | |
54 | ||
55 | await reRunServer(servers[0]) | |
56 | }) | |
57 | ||
58 | describe('Application hooks', function () { | |
59 | it('Should run action:application.listening', async function () { | |
60 | await checkHook('action:application.listening') | |
61 | }) | |
62 | }) | |
63 | ||
64 | describe('Videos hooks', function () { | |
65 | it('Should run action:api.video.uploaded', async function () { | |
66 | const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' }) | |
67 | videoUUID = res.body.video.uuid | |
68 | ||
69 | await checkHook('action:api.video.uploaded') | |
70 | }) | |
71 | ||
72 | it('Should run action:api.video.updated', async function () { | |
73 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, { name: 'video updated' }) | |
74 | ||
75 | await checkHook('action:api.video.updated') | |
76 | }) | |
77 | ||
78 | it('Should run action:api.video.viewed', async function () { | |
79 | await viewVideo(servers[0].url, videoUUID) | |
80 | ||
81 | await checkHook('action:api.video.viewed') | |
82 | }) | |
83 | }) | |
84 | ||
85 | describe('Comments hooks', function () { | |
86 | it('Should run action:api.video-thread.created', async function () { | |
87 | const res = await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, 'thread') | |
88 | threadId = res.body.comment.id | |
89 | ||
90 | await checkHook('action:api.video-thread.created') | |
91 | }) | |
92 | ||
93 | it('Should run action:api.video-comment-reply.created', async function () { | |
94 | await addVideoCommentReply(servers[0].url, servers[0].accessToken, videoUUID, threadId, 'reply') | |
95 | ||
96 | await checkHook('action:api.video-comment-reply.created') | |
97 | }) | |
98 | ||
99 | it('Should run action:api.video-comment.deleted', async function () { | |
100 | await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) | |
101 | ||
102 | await checkHook('action:api.video-comment.deleted') | |
103 | }) | |
104 | }) | |
105 | ||
106 | describe('Users hooks', function () { | |
107 | let userId: number | |
108 | ||
109 | it('Should run action:api.user.registered', async function () { | |
110 | await registerUser(servers[0].url, 'registered_user', 'super_password') | |
111 | ||
112 | await checkHook('action:api.user.registered') | |
113 | }) | |
114 | ||
115 | it('Should run action:api.user.created', async function () { | |
116 | const res = await createUser({ | |
117 | url: servers[0].url, | |
118 | accessToken: servers[0].accessToken, | |
119 | username: 'created_user', | |
120 | password: 'super_password' | |
121 | }) | |
122 | userId = res.body.user.id | |
123 | ||
124 | await checkHook('action:api.user.created') | |
125 | }) | |
126 | ||
127 | it('Should run action:api.user.oauth2-got-token', async function () { | |
128 | await userLogin(servers[0], { username: 'created_user', password: 'super_password' }) | |
129 | ||
130 | await checkHook('action:api.user.oauth2-got-token') | |
131 | }) | |
132 | ||
133 | it('Should run action:api.user.blocked', async function () { | |
134 | await blockUser(servers[0].url, userId, servers[0].accessToken) | |
135 | ||
136 | await checkHook('action:api.user.blocked') | |
137 | }) | |
138 | ||
139 | it('Should run action:api.user.unblocked', async function () { | |
140 | await unblockUser(servers[0].url, userId, servers[0].accessToken) | |
141 | ||
142 | await checkHook('action:api.user.unblocked') | |
143 | }) | |
144 | ||
145 | it('Should run action:api.user.updated', async function () { | |
146 | await updateUser({ url: servers[0].url, accessToken: servers[0].accessToken, userId, videoQuota: 50 }) | |
147 | ||
148 | await checkHook('action:api.user.updated') | |
149 | }) | |
150 | ||
151 | it('Should run action:api.user.deleted', async function () { | |
152 | await removeUser(servers[0].url, userId, servers[0].accessToken) | |
153 | ||
154 | await checkHook('action:api.user.deleted') | |
155 | }) | |
156 | }) | |
157 | ||
158 | after(async function () { | |
159 | await cleanupTests(servers) | |
160 | }) | |
161 | }) |