diff options
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r-- | server/tests/api/check-params/index.ts | 1 | ||||
-rw-r--r-- | server/tests/api/check-params/videos-history.ts | 46 | ||||
-rw-r--r-- | server/tests/api/check-params/views.ts | 157 |
3 files changed, 163 insertions, 41 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts index c9adeef4a..259d7e783 100644 --- a/server/tests/api/check-params/index.ts +++ b/server/tests/api/check-params/index.ts | |||
@@ -33,3 +33,4 @@ import './videos-common-filters' | |||
33 | import './video-files' | 33 | import './video-files' |
34 | import './videos-history' | 34 | import './videos-history' |
35 | import './videos-overviews' | 35 | import './videos-overviews' |
36 | import './views' | ||
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 82f38b7b4..c1b2d8bf3 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts | |||
@@ -17,7 +17,7 @@ import { | |||
17 | describe('Test videos history API validator', function () { | 17 | describe('Test videos history API validator', function () { |
18 | const myHistoryPath = '/api/v1/users/me/history/videos' | 18 | const myHistoryPath = '/api/v1/users/me/history/videos' |
19 | const myHistoryRemove = myHistoryPath + '/remove' | 19 | const myHistoryRemove = myHistoryPath + '/remove' |
20 | let watchingPath: string | 20 | let viewPath: string |
21 | let server: PeerTubeServer | 21 | let server: PeerTubeServer |
22 | let videoId: number | 22 | let videoId: number |
23 | 23 | ||
@@ -31,51 +31,15 @@ describe('Test videos history API validator', function () { | |||
31 | await setAccessTokensToServers([ server ]) | 31 | await setAccessTokensToServers([ server ]) |
32 | 32 | ||
33 | const { id, uuid } = await server.videos.upload() | 33 | const { id, uuid } = await server.videos.upload() |
34 | watchingPath = '/api/v1/videos/' + uuid + '/watching' | 34 | viewPath = '/api/v1/videos/' + uuid + '/views' |
35 | videoId = id | 35 | videoId = id |
36 | }) | 36 | }) |
37 | 37 | ||
38 | describe('When notifying a user is watching a video', function () { | 38 | describe('When notifying a user is watching a video', function () { |
39 | 39 | ||
40 | it('Should fail with an unauthenticated user', async function () { | 40 | it('Should fail with a bad token', async function () { |
41 | const fields = { currentTime: 5 } | ||
42 | await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | ||
43 | }) | ||
44 | |||
45 | it('Should fail with an incorrect video id', async function () { | ||
46 | const fields = { currentTime: 5 } | 41 | const fields = { currentTime: 5 } |
47 | const path = '/api/v1/videos/blabla/watching' | 42 | await makePutBodyRequest({ url: server.url, path: viewPath, fields, token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
48 | await makePutBodyRequest({ | ||
49 | url: server.url, | ||
50 | path, | ||
51 | fields, | ||
52 | token: server.accessToken, | ||
53 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
54 | }) | ||
55 | }) | ||
56 | |||
57 | it('Should fail with an unknown video', async function () { | ||
58 | const fields = { currentTime: 5 } | ||
59 | const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching' | ||
60 | |||
61 | await makePutBodyRequest({ | ||
62 | url: server.url, | ||
63 | path, | ||
64 | fields, | ||
65 | token: server.accessToken, | ||
66 | expectedStatus: HttpStatusCode.NOT_FOUND_404 | ||
67 | }) | ||
68 | }) | ||
69 | |||
70 | it('Should fail with a bad current time', async function () { | ||
71 | const fields = { currentTime: 'hello' } | ||
72 | await makePutBodyRequest({ | ||
73 | url: server.url, | ||
74 | path: watchingPath, | ||
75 | fields, | ||
76 | token: server.accessToken, | ||
77 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | ||
78 | }) | ||
79 | }) | 43 | }) |
80 | 44 | ||
81 | it('Should succeed with the correct parameters', async function () { | 45 | it('Should succeed with the correct parameters', async function () { |
@@ -83,7 +47,7 @@ describe('Test videos history API validator', function () { | |||
83 | 47 | ||
84 | await makePutBodyRequest({ | 48 | await makePutBodyRequest({ |
85 | url: server.url, | 49 | url: server.url, |
86 | path: watchingPath, | 50 | path: viewPath, |
87 | fields, | 51 | fields, |
88 | token: server.accessToken, | 52 | token: server.accessToken, |
89 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | 53 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
diff --git a/server/tests/api/check-params/views.ts b/server/tests/api/check-params/views.ts new file mode 100644 index 000000000..185b04af1 --- /dev/null +++ b/server/tests/api/check-params/views.ts | |||
@@ -0,0 +1,157 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import 'mocha' | ||
4 | import { HttpStatusCode, VideoPrivacy } from '@shared/models' | ||
5 | import { | ||
6 | cleanupTests, | ||
7 | createMultipleServers, | ||
8 | doubleFollow, | ||
9 | PeerTubeServer, | ||
10 | setAccessTokensToServers, | ||
11 | setDefaultVideoChannel | ||
12 | } from '@shared/server-commands' | ||
13 | |||
14 | describe('Test videos views', function () { | ||
15 | let servers: PeerTubeServer[] | ||
16 | let liveVideoId: string | ||
17 | let videoId: string | ||
18 | let remoteVideoId: string | ||
19 | let userAccessToken: string | ||
20 | |||
21 | before(async function () { | ||
22 | this.timeout(30000) | ||
23 | |||
24 | servers = await createMultipleServers(2) | ||
25 | await setAccessTokensToServers(servers) | ||
26 | await setDefaultVideoChannel(servers) | ||
27 | |||
28 | await servers[0].config.enableLive({ allowReplay: false, transcoding: false }); | ||
29 | |||
30 | ({ uuid: videoId } = await servers[0].videos.quickUpload({ name: 'video' })); | ||
31 | ({ uuid: remoteVideoId } = await servers[1].videos.quickUpload({ name: 'video' })); | ||
32 | ({ uuid: liveVideoId } = await servers[0].live.create({ | ||
33 | fields: { | ||
34 | name: 'live', | ||
35 | privacy: VideoPrivacy.PUBLIC, | ||
36 | channelId: servers[0].store.channel.id | ||
37 | } | ||
38 | })) | ||
39 | |||
40 | userAccessToken = await servers[0].users.generateUserAndToken('user') | ||
41 | |||
42 | await doubleFollow(servers[0], servers[1]) | ||
43 | }) | ||
44 | |||
45 | describe('When viewing a video', async function () { | ||
46 | |||
47 | // TODO: implement it when we'll remove backward compatibility in REST API | ||
48 | it('Should fail without current time') | ||
49 | |||
50 | it('Should fail with an invalid current time', async function () { | ||
51 | await servers[0].views.view({ id: videoId, currentTime: -1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
52 | await servers[0].views.view({ id: videoId, currentTime: 10, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
53 | }) | ||
54 | |||
55 | it('Should succeed with correct parameters', async function () { | ||
56 | await servers[0].views.view({ id: videoId, currentTime: 1 }) | ||
57 | }) | ||
58 | }) | ||
59 | |||
60 | describe('When getting overall stats', function () { | ||
61 | |||
62 | it('Should fail with a remote video', async function () { | ||
63 | await servers[0].videoStats.getOverallStats({ videoId: remoteVideoId, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | ||
64 | }) | ||
65 | |||
66 | it('Should fail without token', async function () { | ||
67 | await servers[0].videoStats.getOverallStats({ videoId: videoId, token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | ||
68 | }) | ||
69 | |||
70 | it('Should fail with another token', async function () { | ||
71 | await servers[0].videoStats.getOverallStats({ | ||
72 | videoId: videoId, | ||
73 | token: userAccessToken, | ||
74 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
75 | }) | ||
76 | }) | ||
77 | |||
78 | it('Should succeed with the correct parameters', async function () { | ||
79 | await servers[0].videoStats.getOverallStats({ videoId }) | ||
80 | }) | ||
81 | }) | ||
82 | |||
83 | describe('When getting timeserie stats', function () { | ||
84 | |||
85 | it('Should fail with a remote video', async function () { | ||
86 | await servers[0].videoStats.getTimeserieStats({ | ||
87 | videoId: remoteVideoId, | ||
88 | metric: 'viewers', | ||
89 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
90 | }) | ||
91 | }) | ||
92 | |||
93 | it('Should fail without token', async function () { | ||
94 | await servers[0].videoStats.getTimeserieStats({ | ||
95 | videoId: videoId, | ||
96 | token: null, | ||
97 | metric: 'viewers', | ||
98 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
99 | }) | ||
100 | }) | ||
101 | |||
102 | it('Should fail with another token', async function () { | ||
103 | await servers[0].videoStats.getTimeserieStats({ | ||
104 | videoId: videoId, | ||
105 | token: userAccessToken, | ||
106 | metric: 'viewers', | ||
107 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
108 | }) | ||
109 | }) | ||
110 | |||
111 | it('Should fail with an invalid metric', async function () { | ||
112 | await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'hello' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
113 | }) | ||
114 | |||
115 | it('Should succeed with the correct parameters', async function () { | ||
116 | await servers[0].videoStats.getTimeserieStats({ videoId, metric: 'viewers' }) | ||
117 | }) | ||
118 | }) | ||
119 | |||
120 | describe('When getting retention stats', function () { | ||
121 | |||
122 | it('Should fail with a remote video', async function () { | ||
123 | await servers[0].videoStats.getRetentionStats({ | ||
124 | videoId: remoteVideoId, | ||
125 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
126 | }) | ||
127 | }) | ||
128 | |||
129 | it('Should fail without token', async function () { | ||
130 | await servers[0].videoStats.getRetentionStats({ | ||
131 | videoId: videoId, | ||
132 | token: null, | ||
133 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | ||
134 | }) | ||
135 | }) | ||
136 | |||
137 | it('Should fail with another token', async function () { | ||
138 | await servers[0].videoStats.getRetentionStats({ | ||
139 | videoId: videoId, | ||
140 | token: userAccessToken, | ||
141 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
142 | }) | ||
143 | }) | ||
144 | |||
145 | it('Should fail on live video', async function () { | ||
146 | await servers[0].videoStats.getRetentionStats({ videoId: liveVideoId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) | ||
147 | }) | ||
148 | |||
149 | it('Should succeed with the correct parameters', async function () { | ||
150 | await servers[0].videoStats.getRetentionStats({ videoId }) | ||
151 | }) | ||
152 | }) | ||
153 | |||
154 | after(async function () { | ||
155 | await cleanupTests(servers) | ||
156 | }) | ||
157 | }) | ||