Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

refactor: repository test extract video vars

Christian Fei79359bff6c7a
diff --git a/test/repository.test.js b/test/repository.test.js
index 746f185..2ac95dd 100644
--- a/test/repository.test.js
+++ b/test/repository.test.js
@@ -10,6 +10,8 @@ test.beforeEach(() => {
}
repo = new Repository('./test/data')
})
+const video1 = {id: '12345', channelName: 'tester', title: 'The Code'}
+const video2 = {id: '67890', channelName: 'programmer', title: 'The Error'}
test('empty repo provisions data folder', () => {
assert.ok(repo)
@@ -34,56 +36,56 @@ test('gets channels', () => {
})
test('upserts videos', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
assert.equal(repo.getVideos().length, 2)
})
test('gets channel videos', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
const videos = repo.getChannelVideos('tester')
assert.equal(videos.length, 1)
assert.equal(videos[0].title, 'The Code')
})
test('gets single video by id', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
const video = repo.getVideo('12345')
assert.equal(video.title, 'The Code')
})
test('deletes a video by id and sets downloaded true', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
repo.deleteVideo('12345')
assert.equal(repo.getVideos().length, 2)
assert.deepEqual(repo.getVideo('12345'), {id: '12345', channelName: 'tester', title: 'The Code', downloaded: false})
})
test('toggles ignore video', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
repo.toggleIgnoreVideo('12345')
assert.equal(repo.getVideo('12345').ignored, true)
})
test('marks video as downloaded', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
repo.setVideoDownloaded('12345')
assert.equal(repo.getVideo('12345').downloaded, true)
})
test('sets video transcript', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
repo.setVideoTranscript('12345', 'This is the transcript for The Code')
assert.equal(repo.getVideo('12345').transcript, 'This is the transcript for The Code')
})
test('sets video summary', () => {
- repo.upsertVideos([{id: '12345', channelName: 'tester', title: 'The Code'}, {id: '67890', channelName: 'programmer', title: 'The Error'}])
+ repo.upsertVideos([video1, video2])
repo.setVideoSummary('12345', 'This is the summary for The Code')
assert.equal(repo.getVideo('12345').summary, 'This is the summary for The Code')
})
test('patches new video with addedAt', () => {
- const newVideo = {id: '67890', channelName: 'programmer', title: 'The Error'}
+ const newVideo = video2
const patchedVideo = repo.patchVideo(newVideo)
assert.equal(patchedVideo.addedAt, Date.now())
-})
\ No newline at end of file
+})