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