A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
feat: repo.updateVideo
Christian Fei9842a1ea415c
diff --git a/lib/repository.js b/lib/repository.jsindex 9bfc042..eabcf48 100644--- a/lib/repository.js+++ b/lib/repository.js@@ -71,6 +71,14 @@ export default class Repository {})this.saveVideos()}+ updateVideo(id, update) {+ const index = this.videos.findIndex(v => v.id === id)+ if (index !== -1) {+ Object.assign(this.videos[index], update)+ this.saveVideos()+ }+ return this.videos[index]+ }deleteVideo(id) {const files = fs.readdirSync(`${this.basePath}/videos`)files.forEach(file => {diff --git a/test/repository.test.js b/test/repository.test.jsindex 9fbd3b3..5cd9ecb 100644--- a/test/repository.test.js+++ b/test/repository.test.js@@ -90,7 +90,12 @@ test('sets video summary', () => {})test('patches new video with addedAt', () => {- const newVideo = video2- const patchedVideo = repo.patchVideo(newVideo)- assert.equal(patchedVideo.addedAt, Date.now())+ const patchedVideo = repo.patchVideo(video1)+ assert.ok(patchedVideo.addedAt)})++test('updates single video by id', () => {+ repo.upsertVideos(video1)+ const updatedVideo = repo.updateVideo(video1.id, { title: 'Updated Title' })+ assert.equal(updatedVideo.title, 'Updated Title')+})\ No newline at end of file