A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
test: revisit repository tests
Christian Fei09c6e151c608
diff --git a/lib/repository.js b/lib/repository.jsindex 6b0de37..b5e185a 100644--- a/lib/repository.js+++ b/lib/repository.js@@ -81,12 +81,12 @@ export default class Repository {}getVideos (query = {}) {- const hasFilters = Object.keys(query).length > 1+ const filterKeys = Object.keys(query).filter(k => k !== 'filter')let videos = this.videos.filter(v => query.excluded === 'true' ? true : this.filterByExcludedTerms(v)).filter(v => query.downloaded === 'true' ? v.downloaded : true).filter(v => query.ignored === 'true' ? v.ignored : true)- .filter(v => hasFilters ? true : !v.ignored)+ .filter(v => filterKeys.length > 0 ? true : !v.ignored).sort((a, b) => +new Date(b.publishedAt) - +new Date(a.publishedAt))if (query.filter) {diff --git a/test/repository.search.test.js b/test/repository.search.test.jsnew file mode 100644index 0000000..2711993--- /dev/null+++ b/test/repository.search.test.js@@ -0,0 +1,35 @@+import { test, describe } from 'node:test'+import fs from 'fs'+import assert from 'assert'+import Repository from '../lib/repository.js'++let repo+test.beforeEach(() => {+ if (fs.existsSync('./test/data')) {+ fs.rmSync('./test/data', { recursive: true })+ }+ repo = new Repository('./test/data')+})++const video1 = { id: '12345', channelName: 'tester', title: 'The Code', description: 'some description in common' }+const video2 = { id: '67890', channelName: 'programmer', title: 'The Error', description: 'some description' }++describe('search', () => {+ test('searches videos by title', async () => {+ repo.upsertVideos([video1, video2])+ const results = await repo.getVideos({ filter: 'The Error' })+ assert.equal(results.length, 1)+ assert.deepEqual(results, [video2])+ })+ test('searches videos by channel name', async () => {+ repo.upsertVideos([video1, video2])+ const results = await repo.getVideos({ filter: '@tester' })+ assert.equal(results.length, 1)+ assert.deepEqual(results, [video1])+ })+ test('searches videos by description', async () => {+ repo.upsertVideos([video1, video2])+ const results = await repo.getVideos({ filter: 'some description' })+ assert.equal(results.length, 2)+ })+})diff --git a/test/repository.test.js b/test/repository.test.jsindex 5218678..fffae9f 100644--- a/test/repository.test.js+++ b/test/repository.test.js@@ -10,6 +10,7 @@ test.beforeEach(() => {}repo = new Repository('./test/data')})+const video1 = { id: '12345', channelName: 'tester', title: 'The Code', description: 'some description in common' }const video2 = { id: '67890', channelName: 'programmer', title: 'The Error', description: 'some description' }@@ -162,23 +163,3 @@ describe('excluded terms', () => {})})})--describe('search', () => {- test('searches videos by title', async () => {- repo.upsertVideos([video1, video2])- const results = await repo.getVideos({ filter: 'The Error' })- assert.equal(results.length, 1)- assert.deepEqual(results, [video2])- })- test('searches videos by channel name', async () => {- repo.upsertVideos([video1, video2])- const results = await repo.getVideos({ filter: 'tester' })- assert.equal(results.length, 1)- assert.deepEqual(results, [video1])- })- test('searches videos by description', async () => {- repo.upsertVideos([video1, video2])- const results = await repo.getVideos({ filter: 'some description' })- assert.equal(results.length, 2)- })-})