1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { checkBadCountPagination, checkBadStartPagination } from '@server/tests/shared'
4 import { HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers
14 } from '@shared/server-commands'
16 describe('Test videos history API validator', function () {
17 const myHistoryPath = '/api/v1/users/me/history/videos'
18 const myHistoryRemove = myHistoryPath + '/remove'
20 let server: PeerTubeServer
23 // ---------------------------------------------------------------
25 before(async function () {
28 server = await createSingleServer(1)
30 await setAccessTokensToServers([ server ])
32 const { id, uuid } = await server.videos.upload()
33 viewPath = '/api/v1/videos/' + uuid + '/views'
37 describe('When notifying a user is watching a video', function () {
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 })
44 it('Should succeed with the correct parameters', async function () {
45 const fields = { currentTime: 5 }
47 await makePutBodyRequest({
51 token: server.accessToken,
52 expectedStatus: HttpStatusCode.NO_CONTENT_204
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)
62 it('Should fail with a bad count pagination', async function () {
63 await checkBadCountPagination(server.url, myHistoryPath, server.accessToken)
66 it('Should fail with an unauthenticated user', async function () {
67 await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
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 })
75 describe('When removing a specific user video history element', function () {
79 path = myHistoryPath + '/' + videoId
82 it('Should fail with an unauthenticated user', async function () {
83 await makeDeleteRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
86 it('Should fail with a bad videoId parameter', async function () {
87 await makeDeleteRequest({
89 token: server.accessToken,
90 path: myHistoryRemove + '/hi',
91 expectedStatus: HttpStatusCode.BAD_REQUEST_400
95 it('Should succeed with the correct parameters', async function () {
96 await makeDeleteRequest({
98 token: server.accessToken,
100 expectedStatus: HttpStatusCode.NO_CONTENT_204
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 })
110 it('Should fail with a bad beforeDate parameter', async function () {
111 const body = { beforeDate: '15' }
112 await makePostBodyRequest({
114 token: server.accessToken,
115 path: myHistoryRemove,
117 expectedStatus: HttpStatusCode.BAD_REQUEST_400
121 it('Should succeed with a valid beforeDate param', async function () {
122 const body = { beforeDate: new Date().toISOString() }
123 await makePostBodyRequest({
125 token: server.accessToken,
126 path: myHistoryRemove,
128 expectedStatus: HttpStatusCode.NO_CONTENT_204
132 it('Should succeed without body', async function () {
133 await makePostBodyRequest({
135 token: server.accessToken,
136 path: myHistoryRemove,
137 expectedStatus: HttpStatusCode.NO_CONTENT_204
142 after(async function () {
143 await cleanupTests([ server ])