]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
6e46de09 | 2 | |
6e46de09 C |
3 | import 'mocha' |
4 | import { | |
8b9a525a C |
5 | checkBadCountPagination, |
6 | checkBadStartPagination, | |
7c3b7976 | 7 | cleanupTests, |
254d3579 | 8 | createSingleServer, |
8b9a525a | 9 | makeGetRequest, |
6e46de09 C |
10 | makePostBodyRequest, |
11 | makePutBodyRequest, | |
254d3579 | 12 | PeerTubeServer, |
d23dd9fb C |
13 | setAccessTokensToServers |
14 | } from '@shared/extra-utils' | |
4c7e60bc | 15 | import { HttpStatusCode } from '@shared/models' |
6e46de09 | 16 | |
6e46de09 | 17 | describe('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 } | |
c0e8b12e | 40 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: 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, | |
c0e8b12e | 51 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
2d53be02 | 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, | |
c0e8b12e | 64 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
2d53be02 | 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, | |
c0e8b12e | 75 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
2d53be02 | 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, | |
c0e8b12e | 87 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
2d53be02 | 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 () { | |
c0e8b12e | 102 | await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
8b9a525a C |
103 | }) |
104 | ||
105 | it('Should succeed with the correct params', async function () { | |
c0e8b12e | 106 | await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: 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 () { | |
c0e8b12e | 112 | await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: 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, | |
c0e8b12e | 122 | expectedStatus: 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, | |
c0e8b12e | 133 | expectedStatus: 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, | |
c0e8b12e | 142 | expectedStatus: 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 | }) |