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