]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import { checkBadCountPagination, checkBadStartPagination } from '@server/tests/shared' | |
4 | import { HttpStatusCode } from '@shared/models' | |
5 | import { | |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | makeDeleteRequest, | |
9 | makeGetRequest, | |
10 | makePostBodyRequest, | |
11 | makePutBodyRequest, | |
12 | PeerTubeServer, | |
13 | setAccessTokensToServers | |
14 | } from '@shared/server-commands' | |
15 | ||
16 | describe('Test videos history API validator', function () { | |
17 | const myHistoryPath = '/api/v1/users/me/history/videos' | |
18 | const myHistoryRemove = myHistoryPath + '/remove' | |
19 | let viewPath: string | |
20 | let server: PeerTubeServer | |
21 | let videoId: number | |
22 | ||
23 | // --------------------------------------------------------------- | |
24 | ||
25 | before(async function () { | |
26 | this.timeout(30000) | |
27 | ||
28 | server = await createSingleServer(1) | |
29 | ||
30 | await setAccessTokensToServers([ server ]) | |
31 | ||
32 | const { id, uuid } = await server.videos.upload() | |
33 | viewPath = '/api/v1/videos/' + uuid + '/views' | |
34 | videoId = id | |
35 | }) | |
36 | ||
37 | describe('When notifying a user is watching a video', function () { | |
38 | ||
39 | it('Should fail with a bad token', async function () { | |
40 | const fields = { currentTime: 5 } | |
41 | await makePutBodyRequest({ url: server.url, path: viewPath, fields, token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
42 | }) | |
43 | ||
44 | it('Should succeed with the correct parameters', async function () { | |
45 | const fields = { currentTime: 5 } | |
46 | ||
47 | await makePutBodyRequest({ | |
48 | url: server.url, | |
49 | path: viewPath, | |
50 | fields, | |
51 | token: server.accessToken, | |
52 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
53 | }) | |
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 () { | |
67 | await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
68 | }) | |
69 | ||
70 | it('Should succeed with the correct params', async function () { | |
71 | await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: HttpStatusCode.OK_200 }) | |
72 | }) | |
73 | }) | |
74 | ||
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 () { | |
106 | it('Should fail with an unauthenticated user', async function () { | |
107 | await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
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, | |
117 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
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, | |
128 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
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, | |
137 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
138 | }) | |
139 | }) | |
140 | }) | |
141 | ||
142 | after(async function () { | |
143 | await cleanupTests([ server ]) | |
144 | }) | |
145 | }) |