]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/videos-history.ts
Add search target check params
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos-history.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
6e46de09 2
6e46de09
C
3import 'mocha'
4import {
8b9a525a
C
5 checkBadCountPagination,
6 checkBadStartPagination,
7c3b7976
C
7 cleanupTests,
8 flushAndRunServer,
8b9a525a 9 makeGetRequest,
6e46de09
C
10 makePostBodyRequest,
11 makePutBodyRequest,
6e46de09
C
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo
94565d52 15} from '../../../../shared/extra-utils'
6e46de09 16
6e46de09 17describe('Test videos history API validator', function () {
a1587156
C
18 const myHistoryPath = '/api/v1/users/me/history/videos'
19 const myHistoryRemove = myHistoryPath + '/remove'
8b9a525a 20 let watchingPath: string
6e46de09
C
21 let server: ServerInfo
22
23 // ---------------------------------------------------------------
24
25 before(async function () {
26 this.timeout(30000)
27
210feb6c 28 server = await flushAndRunServer(1)
6e46de09
C
29
30 await setAccessTokensToServers([ server ])
31
32 const res = await uploadVideo(server.url, server.accessToken, {})
33 const videoUUID = res.body.video.uuid
34
8b9a525a 35 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
6e46de09
C
36 })
37
38 describe('When notifying a user is watching a video', function () {
39
40 it('Should fail with an unauthenticated user', async function () {
41 const fields = { currentTime: 5 }
8b9a525a 42 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 })
6e46de09
C
43 })
44
45 it('Should fail with an incorrect video id', async function () {
46 const fields = { currentTime: 5 }
47 const path = '/api/v1/videos/blabla/watching'
48 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 })
49 })
50
51 it('Should fail with an unknown video', async function () {
52 const fields = { currentTime: 5 }
53 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
54
55 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 })
56 })
57
58 it('Should fail with a bad current time', async function () {
59 const fields = { currentTime: 'hello' }
8b9a525a 60 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 })
6e46de09
C
61 })
62
63 it('Should succeed with the correct parameters', async function () {
64 const fields = { currentTime: 5 }
65
8b9a525a
C
66 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 })
67 })
68 })
69
70 describe('When listing user videos history', function () {
71 it('Should fail with a bad start pagination', async function () {
72 await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
73 })
74
75 it('Should fail with a bad count pagination', async function () {
76 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
77 })
78
79 it('Should fail with an unauthenticated user', async function () {
80 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 })
81 })
82
83 it('Should succeed with the correct params', async function () {
84 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 })
85 })
86 })
87
88 describe('When removing user videos history', function () {
89 it('Should fail with an unauthenticated user', async function () {
90 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 })
91 })
92
93 it('Should fail with a bad beforeDate parameter', async function () {
94 const body = { beforeDate: '15' }
95 await makePostBodyRequest({
96 url: server.url,
97 token: server.accessToken,
98 path: myHistoryRemove,
99 fields: body,
100 statusCodeExpected: 400
101 })
102 })
103
104 it('Should succeed with a valid beforeDate param', async function () {
105 const body = { beforeDate: new Date().toISOString() }
106 await makePostBodyRequest({
107 url: server.url,
108 token: server.accessToken,
109 path: myHistoryRemove,
110 fields: body,
111 statusCodeExpected: 204
112 })
113 })
114
115 it('Should succeed without body', async function () {
116 await makePostBodyRequest({
117 url: server.url,
118 token: server.accessToken,
119 path: myHistoryRemove,
120 statusCodeExpected: 204
121 })
6e46de09
C
122 })
123 })
124
7c3b7976
C
125 after(async function () {
126 await cleanupTests([ server ])
6e46de09
C
127 })
128})