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