aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/videos-common-filters.ts19
-rw-r--r--server/tests/api/videos/videos-common-filters.ts32
2 files changed, 48 insertions, 3 deletions
diff --git a/server/tests/api/check-params/videos-common-filters.ts b/server/tests/api/check-params/videos-common-filters.ts
index 11d9fd95b..3e44e2f67 100644
--- a/server/tests/api/check-params/videos-common-filters.ts
+++ b/server/tests/api/check-params/videos-common-filters.ts
@@ -122,6 +122,8 @@ describe('Test video filters validators', function () {
122 include?: VideoInclude 122 include?: VideoInclude
123 privacyOneOf?: VideoPrivacy[] 123 privacyOneOf?: VideoPrivacy[]
124 expectedStatus: HttpStatusCode 124 expectedStatus: HttpStatusCode
125 excludeAlreadyWatched?: boolean
126 unauthenticatedUser?: boolean
125 }) { 127 }) {
126 const paths = [ 128 const paths = [
127 '/api/v1/video-channels/root_channel/videos', 129 '/api/v1/video-channels/root_channel/videos',
@@ -131,14 +133,19 @@ describe('Test video filters validators', function () {
131 ] 133 ]
132 134
133 for (const path of paths) { 135 for (const path of paths) {
136 const token = options.unauthenticatedUser
137 ? undefined
138 : options.token || server.accessToken
139
134 await makeGetRequest({ 140 await makeGetRequest({
135 url: server.url, 141 url: server.url,
136 path, 142 path,
137 token: options.token || server.accessToken, 143 token,
138 query: { 144 query: {
139 isLocal: options.isLocal, 145 isLocal: options.isLocal,
140 privacyOneOf: options.privacyOneOf, 146 privacyOneOf: options.privacyOneOf,
141 include: options.include 147 include: options.include,
148 excludeAlreadyWatched: options.excludeAlreadyWatched
142 }, 149 },
143 expectedStatus: options.expectedStatus 150 expectedStatus: options.expectedStatus
144 }) 151 })
@@ -213,6 +220,14 @@ describe('Test video filters validators', function () {
213 } 220 }
214 }) 221 })
215 }) 222 })
223
224 it('Should fail when trying to exclude already watched videos for an unlogged user', async function () {
225 await testEndpoints({ excludeAlreadyWatched: true, unauthenticatedUser: true, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
226 })
227
228 it('Should succeed when trying to exclude already watched videos for a logged user', async function () {
229 await testEndpoints({ token: userAccessToken, excludeAlreadyWatched: true, expectedStatus: HttpStatusCode.OK_200 })
230 })
216 }) 231 })
217 232
218 after(async function () { 233 after(async function () {
diff --git a/server/tests/api/videos/videos-common-filters.ts b/server/tests/api/videos/videos-common-filters.ts
index 1ab78ac49..30251706b 100644
--- a/server/tests/api/videos/videos-common-filters.ts
+++ b/server/tests/api/videos/videos-common-filters.ts
@@ -162,13 +162,23 @@ describe('Test videos filter', function () {
162 tagsAllOf?: string[] 162 tagsAllOf?: string[]
163 token?: string 163 token?: string
164 expectedStatus?: HttpStatusCode 164 expectedStatus?: HttpStatusCode
165 excludeAlreadyWatched?: boolean
165 }) { 166 }) {
166 const res = await makeGetRequest({ 167 const res = await makeGetRequest({
167 url: options.server.url, 168 url: options.server.url,
168 path: options.path, 169 path: options.path,
169 token: options.token ?? options.server.accessToken, 170 token: options.token ?? options.server.accessToken,
170 query: { 171 query: {
171 ...pick(options, [ 'isLocal', 'include', 'category', 'tagsAllOf', 'hasWebtorrentFiles', 'hasHLSFiles', 'privacyOneOf' ]), 172 ...pick(options, [
173 'isLocal',
174 'include',
175 'category',
176 'tagsAllOf',
177 'hasWebtorrentFiles',
178 'hasHLSFiles',
179 'privacyOneOf',
180 'excludeAlreadyWatched'
181 ]),
172 182
173 sort: 'createdAt' 183 sort: 'createdAt'
174 }, 184 },
@@ -187,6 +197,7 @@ describe('Test videos filter', function () {
187 token?: string 197 token?: string
188 expectedStatus?: HttpStatusCode 198 expectedStatus?: HttpStatusCode
189 skipSubscription?: boolean 199 skipSubscription?: boolean
200 excludeAlreadyWatched?: boolean
190 } 201 }
191 ) { 202 ) {
192 const { skipSubscription = false } = options 203 const { skipSubscription = false } = options
@@ -525,6 +536,25 @@ describe('Test videos filter', function () {
525 } 536 }
526 } 537 }
527 }) 538 })
539
540 it('Should filter already watched videos by the user', async function () {
541 const { id } = await servers[0].videos.upload({ attributes: { name: 'video for history' } })
542
543 for (const path of paths) {
544 const videos = await listVideos({ server: servers[0], path, isLocal: true, excludeAlreadyWatched: true })
545 const foundVideo = videos.find(video => video.id === id)
546
547 expect(foundVideo).to.not.be.undefined
548 }
549 await servers[0].views.view({ id, token: servers[0].accessToken })
550
551 for (const path of paths) {
552 const videos = await listVideos({ server: servers[0], path, excludeAlreadyWatched: true })
553 const foundVideo = videos.find(video => video.id === id)
554
555 expect(foundVideo).to.be.undefined
556 }
557 })
528 }) 558 })
529 559
530 after(async function () { 560 after(async function () {