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