diff options
-rw-r--r-- | server/tests/api/videos/videos-history.ts | 59 | ||||
-rw-r--r-- | shared/extra-utils/server/servers.ts | 4 | ||||
-rw-r--r-- | shared/extra-utils/videos/history-command.ts | 59 | ||||
-rw-r--r-- | shared/extra-utils/videos/index.ts | 2 | ||||
-rw-r--r-- | shared/extra-utils/videos/video-history.ts | 49 |
5 files changed, 92 insertions, 81 deletions
diff --git a/server/tests/api/videos/videos-history.ts b/server/tests/api/videos/videos-history.ts index 209b93014..731447135 100644 --- a/server/tests/api/videos/videos-history.ts +++ b/server/tests/api/videos/videos-history.ts | |||
@@ -9,6 +9,7 @@ import { | |||
9 | flushAndRunServer, | 9 | flushAndRunServer, |
10 | getVideosListWithToken, | 10 | getVideosListWithToken, |
11 | getVideoWithToken, | 11 | getVideoWithToken, |
12 | HistoryCommand, | ||
12 | killallServers, | 13 | killallServers, |
13 | reRunServer, | 14 | reRunServer, |
14 | ServerInfo, | 15 | ServerInfo, |
@@ -18,7 +19,6 @@ import { | |||
18 | userLogin, | 19 | userLogin, |
19 | wait | 20 | wait |
20 | } from '@shared/extra-utils' | 21 | } from '@shared/extra-utils' |
21 | import { listMyVideosHistory, removeMyVideosHistory, userWatchVideo } from '@shared/extra-utils/videos/video-history' | ||
22 | import { Video, VideoDetails } from '@shared/models' | 22 | import { Video, VideoDetails } from '@shared/models' |
23 | 23 | ||
24 | const expect = chai.expect | 24 | const expect = chai.expect |
@@ -30,6 +30,7 @@ describe('Test videos history', function () { | |||
30 | let video3UUID: string | 30 | let video3UUID: string |
31 | let video3WatchedDate: Date | 31 | let video3WatchedDate: Date |
32 | let userAccessToken: string | 32 | let userAccessToken: string |
33 | let command: HistoryCommand | ||
33 | 34 | ||
34 | before(async function () { | 35 | before(async function () { |
35 | this.timeout(30000) | 36 | this.timeout(30000) |
@@ -38,6 +39,8 @@ describe('Test videos history', function () { | |||
38 | 39 | ||
39 | await setAccessTokensToServers([ server ]) | 40 | await setAccessTokensToServers([ server ]) |
40 | 41 | ||
42 | command = server.historyCommand | ||
43 | |||
41 | { | 44 | { |
42 | const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) | 45 | const res = await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) |
43 | video1UUID = res.body.video.uuid | 46 | video1UUID = res.body.video.uuid |
@@ -75,8 +78,8 @@ describe('Test videos history', function () { | |||
75 | }) | 78 | }) |
76 | 79 | ||
77 | it('Should watch the first and second video', async function () { | 80 | it('Should watch the first and second video', async function () { |
78 | await userWatchVideo(server.url, server.accessToken, video2UUID, 8) | 81 | await command.wathVideo({ videoId: video2UUID, currentTime: 8 }) |
79 | await userWatchVideo(server.url, server.accessToken, video1UUID, 3) | 82 | await command.wathVideo({ videoId: video1UUID, currentTime: 3 }) |
80 | }) | 83 | }) |
81 | 84 | ||
82 | it('Should return the correct history when listing, searching and getting videos', async function () { | 85 | it('Should return the correct history when listing, searching and getting videos', async function () { |
@@ -132,44 +135,42 @@ describe('Test videos history', function () { | |||
132 | 135 | ||
133 | it('Should have these videos when listing my history', async function () { | 136 | it('Should have these videos when listing my history', async function () { |
134 | video3WatchedDate = new Date() | 137 | video3WatchedDate = new Date() |
135 | await userWatchVideo(server.url, server.accessToken, video3UUID, 2) | 138 | await command.wathVideo({ videoId: video3UUID, currentTime: 2 }) |
136 | 139 | ||
137 | const res = await listMyVideosHistory(server.url, server.accessToken) | 140 | const body = await command.list() |
138 | 141 | ||
139 | expect(res.body.total).to.equal(3) | 142 | expect(body.total).to.equal(3) |
140 | 143 | ||
141 | const videos: Video[] = res.body.data | 144 | const videos = body.data |
142 | expect(videos[0].name).to.equal('video 3') | 145 | expect(videos[0].name).to.equal('video 3') |
143 | expect(videos[1].name).to.equal('video 1') | 146 | expect(videos[1].name).to.equal('video 1') |
144 | expect(videos[2].name).to.equal('video 2') | 147 | expect(videos[2].name).to.equal('video 2') |
145 | }) | 148 | }) |
146 | 149 | ||
147 | it('Should not have videos history on another user', async function () { | 150 | it('Should not have videos history on another user', async function () { |
148 | const res = await listMyVideosHistory(server.url, userAccessToken) | 151 | const body = await command.list({ token: userAccessToken }) |
149 | 152 | ||
150 | expect(res.body.total).to.equal(0) | 153 | expect(body.total).to.equal(0) |
151 | expect(res.body.data).to.have.lengthOf(0) | 154 | expect(body.data).to.have.lengthOf(0) |
152 | }) | 155 | }) |
153 | 156 | ||
154 | it('Should be able to search through videos in my history', async function () { | 157 | it('Should be able to search through videos in my history', async function () { |
155 | const res = await listMyVideosHistory(server.url, server.accessToken, '2') | 158 | const body = await command.list({ search: '2' }) |
156 | 159 | expect(body.total).to.equal(1) | |
157 | expect(res.body.total).to.equal(1) | ||
158 | 160 | ||
159 | const videos: Video[] = res.body.data | 161 | const videos = body.data |
160 | expect(videos[0].name).to.equal('video 2') | 162 | expect(videos[0].name).to.equal('video 2') |
161 | }) | 163 | }) |
162 | 164 | ||
163 | it('Should clear my history', async function () { | 165 | it('Should clear my history', async function () { |
164 | await removeMyVideosHistory(server.url, server.accessToken, video3WatchedDate.toISOString()) | 166 | await command.remove({ beforeDate: video3WatchedDate.toISOString() }) |
165 | }) | 167 | }) |
166 | 168 | ||
167 | it('Should have my history cleared', async function () { | 169 | it('Should have my history cleared', async function () { |
168 | const res = await listMyVideosHistory(server.url, server.accessToken) | 170 | const body = await command.list() |
169 | 171 | expect(body.total).to.equal(1) | |
170 | expect(res.body.total).to.equal(1) | ||
171 | 172 | ||
172 | const videos: Video[] = res.body.data | 173 | const videos = body.data |
173 | expect(videos[0].name).to.equal('video 3') | 174 | expect(videos[0].name).to.equal('video 3') |
174 | }) | 175 | }) |
175 | 176 | ||
@@ -180,7 +181,7 @@ describe('Test videos history', function () { | |||
180 | videosHistoryEnabled: false | 181 | videosHistoryEnabled: false |
181 | }) | 182 | }) |
182 | 183 | ||
183 | await userWatchVideo(server.url, server.accessToken, video2UUID, 8, HttpStatusCode.CONFLICT_409) | 184 | await command.wathVideo({ videoId: video2UUID, currentTime: 8, expectedStatus: HttpStatusCode.CONFLICT_409 }) |
184 | }) | 185 | }) |
185 | 186 | ||
186 | it('Should re-enable videos history', async function () { | 187 | it('Should re-enable videos history', async function () { |
@@ -190,13 +191,12 @@ describe('Test videos history', function () { | |||
190 | videosHistoryEnabled: true | 191 | videosHistoryEnabled: true |
191 | }) | 192 | }) |
192 | 193 | ||
193 | await userWatchVideo(server.url, server.accessToken, video1UUID, 8) | 194 | await command.wathVideo({ videoId: video1UUID, currentTime: 8 }) |
194 | |||
195 | const res = await listMyVideosHistory(server.url, server.accessToken) | ||
196 | 195 | ||
197 | expect(res.body.total).to.equal(2) | 196 | const body = await command.list() |
197 | expect(body.total).to.equal(2) | ||
198 | 198 | ||
199 | const videos: Video[] = res.body.data | 199 | const videos = body.data |
200 | expect(videos[0].name).to.equal('video 1') | 200 | expect(videos[0].name).to.equal('video 1') |
201 | expect(videos[1].name).to.equal('video 3') | 201 | expect(videos[1].name).to.equal('video 3') |
202 | }) | 202 | }) |
@@ -212,9 +212,8 @@ describe('Test videos history', function () { | |||
212 | 212 | ||
213 | // Should still have history | 213 | // Should still have history |
214 | 214 | ||
215 | const res = await listMyVideosHistory(server.url, server.accessToken) | 215 | const body = await command.list() |
216 | 216 | expect(body.total).to.equal(2) | |
217 | expect(res.body.total).to.equal(2) | ||
218 | }) | 217 | }) |
219 | 218 | ||
220 | it('Should clean old history', async function () { | 219 | it('Should clean old history', async function () { |
@@ -226,8 +225,8 @@ describe('Test videos history', function () { | |||
226 | 225 | ||
227 | await wait(6000) | 226 | await wait(6000) |
228 | 227 | ||
229 | const res = await listMyVideosHistory(server.url, server.accessToken) | 228 | const body = await command.list() |
230 | expect(res.body.total).to.equal(0) | 229 | expect(body.total).to.equal(0) |
231 | }) | 230 | }) |
232 | 231 | ||
233 | after(async function () { | 232 | after(async function () { |
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts index 78b3be9c7..bd5c29e51 100644 --- a/shared/extra-utils/server/servers.ts +++ b/shared/extra-utils/server/servers.ts | |||
@@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests' | |||
18 | import { SearchCommand } from '../search' | 18 | import { SearchCommand } from '../search' |
19 | import { SocketIOCommand } from '../socket' | 19 | import { SocketIOCommand } from '../socket' |
20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' | 20 | import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' |
21 | import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' | 21 | import { BlacklistCommand, CaptionsCommand, ChangeOwnershipCommand, HistoryCommand, LiveCommand, PlaylistsCommand, ServicesCommand } from '../videos' |
22 | import { ConfigCommand } from './config-command' | 22 | import { ConfigCommand } from './config-command' |
23 | import { ContactFormCommand } from './contact-form-command' | 23 | import { ContactFormCommand } from './contact-form-command' |
24 | import { DebugCommand } from './debug-command' | 24 | import { DebugCommand } from './debug-command' |
@@ -106,6 +106,7 @@ interface ServerInfo { | |||
106 | captionsCommand?: CaptionsCommand | 106 | captionsCommand?: CaptionsCommand |
107 | changeOwnershipCommand?: ChangeOwnershipCommand | 107 | changeOwnershipCommand?: ChangeOwnershipCommand |
108 | playlistsCommand?: PlaylistsCommand | 108 | playlistsCommand?: PlaylistsCommand |
109 | historyCommand?: HistoryCommand | ||
109 | } | 110 | } |
110 | 111 | ||
111 | function parallelTests () { | 112 | function parallelTests () { |
@@ -337,6 +338,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = [] | |||
337 | server.captionsCommand = new CaptionsCommand(server) | 338 | server.captionsCommand = new CaptionsCommand(server) |
338 | server.changeOwnershipCommand = new ChangeOwnershipCommand(server) | 339 | server.changeOwnershipCommand = new ChangeOwnershipCommand(server) |
339 | server.playlistsCommand = new PlaylistsCommand(server) | 340 | server.playlistsCommand = new PlaylistsCommand(server) |
341 | server.historyCommand = new HistoryCommand(server) | ||
340 | 342 | ||
341 | res(server) | 343 | res(server) |
342 | }) | 344 | }) |
diff --git a/shared/extra-utils/videos/history-command.ts b/shared/extra-utils/videos/history-command.ts new file mode 100644 index 000000000..8a144a312 --- /dev/null +++ b/shared/extra-utils/videos/history-command.ts | |||
@@ -0,0 +1,59 @@ | |||
1 | import { ResultList, Video } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class HistoryCommand extends AbstractCommand { | ||
6 | |||
7 | wathVideo (options: OverrideCommandOptions & { | ||
8 | videoId: number | string | ||
9 | currentTime: number | ||
10 | }) { | ||
11 | const { videoId, currentTime } = options | ||
12 | |||
13 | const path = '/api/v1/videos/' + videoId + '/watching' | ||
14 | const fields = { currentTime } | ||
15 | |||
16 | return this.putBodyRequest({ | ||
17 | ...options, | ||
18 | |||
19 | path, | ||
20 | fields, | ||
21 | implicitToken: true, | ||
22 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
23 | }) | ||
24 | } | ||
25 | |||
26 | list (options: OverrideCommandOptions & { | ||
27 | search?: string | ||
28 | } = {}) { | ||
29 | const { search } = options | ||
30 | const path = '/api/v1/users/me/history/videos' | ||
31 | |||
32 | return this.getRequestBody<ResultList<Video>>({ | ||
33 | ...options, | ||
34 | |||
35 | path, | ||
36 | query: { | ||
37 | search | ||
38 | }, | ||
39 | implicitToken: true, | ||
40 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
41 | }) | ||
42 | } | ||
43 | |||
44 | remove (options: OverrideCommandOptions & { | ||
45 | beforeDate?: string | ||
46 | } = {}) { | ||
47 | const { beforeDate } = options | ||
48 | const path = '/api/v1/users/me/history/videos/remove' | ||
49 | |||
50 | return this.postBodyRequest({ | ||
51 | ...options, | ||
52 | |||
53 | path, | ||
54 | fields: { beforeDate }, | ||
55 | implicitToken: true, | ||
56 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
57 | }) | ||
58 | } | ||
59 | } | ||
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts index 1f6241d7e..74667fc06 100644 --- a/shared/extra-utils/videos/index.ts +++ b/shared/extra-utils/videos/index.ts | |||
@@ -2,6 +2,7 @@ export * from './blacklist-command' | |||
2 | export * from './captions' | 2 | export * from './captions' |
3 | export * from './captions-command' | 3 | export * from './captions-command' |
4 | export * from './change-ownership-command' | 4 | export * from './change-ownership-command' |
5 | export * from './history-command' | ||
5 | export * from './live-command' | 6 | export * from './live-command' |
6 | export * from './live' | 7 | export * from './live' |
7 | export * from './playlists-command' | 8 | export * from './playlists-command' |
@@ -9,7 +10,6 @@ export * from './playlists' | |||
9 | export * from './services-command' | 10 | export * from './services-command' |
10 | export * from './video-channels' | 11 | export * from './video-channels' |
11 | export * from './video-comments' | 12 | export * from './video-comments' |
12 | export * from './video-history' | ||
13 | export * from './video-imports' | 13 | export * from './video-imports' |
14 | export * from './video-streaming-playlists' | 14 | export * from './video-streaming-playlists' |
15 | export * from './videos' | 15 | export * from './videos' |
diff --git a/shared/extra-utils/videos/video-history.ts b/shared/extra-utils/videos/video-history.ts deleted file mode 100644 index b989e14dc..000000000 --- a/shared/extra-utils/videos/video-history.ts +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
1 | import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests' | ||
2 | import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes' | ||
3 | |||
4 | function userWatchVideo ( | ||
5 | url: string, | ||
6 | token: string, | ||
7 | videoId: number | string, | ||
8 | currentTime: number, | ||
9 | statusCodeExpected = HttpStatusCode.NO_CONTENT_204 | ||
10 | ) { | ||
11 | const path = '/api/v1/videos/' + videoId + '/watching' | ||
12 | const fields = { currentTime } | ||
13 | |||
14 | return makePutBodyRequest({ url, path, token, fields, statusCodeExpected }) | ||
15 | } | ||
16 | |||
17 | function listMyVideosHistory (url: string, token: string, search?: string) { | ||
18 | const path = '/api/v1/users/me/history/videos' | ||
19 | |||
20 | return makeGetRequest({ | ||
21 | url, | ||
22 | path, | ||
23 | token, | ||
24 | query: { | ||
25 | search | ||
26 | }, | ||
27 | statusCodeExpected: HttpStatusCode.OK_200 | ||
28 | }) | ||
29 | } | ||
30 | |||
31 | function removeMyVideosHistory (url: string, token: string, beforeDate?: string) { | ||
32 | const path = '/api/v1/users/me/history/videos/remove' | ||
33 | |||
34 | return makePostBodyRequest({ | ||
35 | url, | ||
36 | path, | ||
37 | token, | ||
38 | fields: beforeDate ? { beforeDate } : {}, | ||
39 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | ||
40 | }) | ||
41 | } | ||
42 | |||
43 | // --------------------------------------------------------------------------- | ||
44 | |||
45 | export { | ||
46 | userWatchVideo, | ||
47 | listMyVideosHistory, | ||
48 | removeMyVideosHistory | ||
49 | } | ||