]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/videos-history.ts
Fix server run
[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 3import 'mocha'
d23dd9fb 4import { HttpStatusCode } from '@shared/core-utils'
6e46de09 5import {
8b9a525a
C
6 checkBadCountPagination,
7 checkBadStartPagination,
7c3b7976 8 cleanupTests,
254d3579 9 createSingleServer,
8b9a525a 10 makeGetRequest,
6e46de09
C
11 makePostBodyRequest,
12 makePutBodyRequest,
254d3579 13 PeerTubeServer,
d23dd9fb
C
14 setAccessTokensToServers
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
254d3579 21 let server: PeerTubeServer
6e46de09
C
22
23 // ---------------------------------------------------------------
24
25 before(async function () {
26 this.timeout(30000)
27
254d3579 28 server = await createSingleServer(1)
6e46de09
C
29
30 await setAccessTokensToServers([ server ])
31
89d241a7 32 const { uuid } = await server.videos.upload()
d23dd9fb 33 watchingPath = '/api/v1/videos/' + uuid + '/watching'
6e46de09
C
34 })
35
36 describe('When notifying a user is watching a video', function () {
37
38 it('Should fail with an unauthenticated user', async function () {
39 const fields = { currentTime: 5 }
2d53be02 40 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
6e46de09
C
41 })
42
43 it('Should fail with an incorrect video id', async function () {
44 const fields = { currentTime: 5 }
45 const path = '/api/v1/videos/blabla/watching'
2d53be02
RK
46 await makePutBodyRequest({
47 url: server.url,
48 path,
49 fields,
50 token: server.accessToken,
51 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
52 })
6e46de09
C
53 })
54
55 it('Should fail with an unknown video', async function () {
56 const fields = { currentTime: 5 }
57 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
58
2d53be02
RK
59 await makePutBodyRequest({
60 url: server.url,
61 path,
62 fields,
63 token: server.accessToken,
64 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
65 })
6e46de09
C
66 })
67
68 it('Should fail with a bad current time', async function () {
69 const fields = { currentTime: 'hello' }
2d53be02
RK
70 await makePutBodyRequest({
71 url: server.url,
72 path: watchingPath,
73 fields,
74 token: server.accessToken,
75 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
76 })
6e46de09
C
77 })
78
79 it('Should succeed with the correct parameters', async function () {
80 const fields = { currentTime: 5 }
81
2d53be02
RK
82 await makePutBodyRequest({
83 url: server.url,
84 path: watchingPath,
85 fields,
86 token: server.accessToken,
87 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
88 })
8b9a525a
C
89 })
90 })
91
92 describe('When listing user videos history', function () {
93 it('Should fail with a bad start pagination', async function () {
94 await checkBadStartPagination(server.url, myHistoryPath, server.accessToken)
95 })
96
97 it('Should fail with a bad count pagination', async function () {
98 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
99 })
100
101 it('Should fail with an unauthenticated user', async function () {
2d53be02 102 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
8b9a525a
C
103 })
104
105 it('Should succeed with the correct params', async function () {
2d53be02 106 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 })
8b9a525a
C
107 })
108 })
109
110 describe('When removing user videos history', function () {
111 it('Should fail with an unauthenticated user', async function () {
2d53be02 112 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
8b9a525a
C
113 })
114
115 it('Should fail with a bad beforeDate parameter', async function () {
116 const body = { beforeDate: '15' }
117 await makePostBodyRequest({
118 url: server.url,
119 token: server.accessToken,
120 path: myHistoryRemove,
121 fields: body,
2d53be02 122 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
8b9a525a
C
123 })
124 })
125
126 it('Should succeed with a valid beforeDate param', async function () {
127 const body = { beforeDate: new Date().toISOString() }
128 await makePostBodyRequest({
129 url: server.url,
130 token: server.accessToken,
131 path: myHistoryRemove,
132 fields: body,
2d53be02 133 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
8b9a525a
C
134 })
135 })
136
137 it('Should succeed without body', async function () {
138 await makePostBodyRequest({
139 url: server.url,
140 token: server.accessToken,
141 path: myHistoryRemove,
2d53be02 142 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
8b9a525a 143 })
6e46de09
C
144 })
145 })
146
7c3b7976
C
147 after(async function () {
148 await cleanupTests([ server ])
6e46de09
C
149 })
150})