From 21b7629bdca0e9c3f7b04f913920ebcad5c12bfa Mon Sep 17 00:00:00 2001 From: Roberto Tonino Date: Wed, 2 Jun 2021 17:28:45 +0200 Subject: [PATCH] test: added more date tests and added download tests; workflow: mapped @/ path in jest config --- jest.config.js | 3 +++ src/utils/downloads.js | 10 +++++----- tests/unit/utils/dates.spec.js | 9 ++++++++- tests/unit/utils/downloads.spec.js | 12 ++++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 tests/unit/utils/downloads.spec.js diff --git a/jest.config.js b/jest.config.js index f975602..edbf306 100644 --- a/jest.config.js +++ b/jest.config.js @@ -6,5 +6,8 @@ module.exports = { setupFiles: ['dotenv/config'], transform: { '^.+\\.[t|j]sx?$': 'babel-jest' + }, + moduleNameMapper: { + '@/(.*)': ['/src/$1'] } } diff --git a/src/utils/downloads.js b/src/utils/downloads.js index 5564a99..1bf6e91 100644 --- a/src/utils/downloads.js +++ b/src/utils/downloads.js @@ -10,12 +10,12 @@ export function sendAddToQueue(url, bitrate = null) { fetchData('addToQueue', { url, bitrate }, 'POST') } +/** + * @param {{ link: string }[]} releases + * @returns {string} + */ export function aggregateDownloadLinks(releases) { - const links = [] - - releases.forEach(release => { - links.push(release.link) - }) + const links = releases.map(release => release.link) return links.join(';') } diff --git a/tests/unit/utils/dates.spec.js b/tests/unit/utils/dates.spec.js index 566384c..56ea726 100644 --- a/tests/unit/utils/dates.spec.js +++ b/tests/unit/utils/dates.spec.js @@ -2,8 +2,15 @@ import { checkNewRelease } from '../../../src/utils/dates.js' describe('date utils', () => { describe('checkNewRelease', () => { - it("returns true with today's date", () => { + it("returns a positive result checking today's date", () => { expect(checkNewRelease(new Date())).toBe(true) }) + + it("returns a negative result checking a week ago's date", () => { + const dateToCheck = new Date() + dateToCheck.setDate(dateToCheck.getDate() - 7) + + expect(checkNewRelease(dateToCheck)).toBe(false) + }) }) }) diff --git a/tests/unit/utils/downloads.spec.js b/tests/unit/utils/downloads.spec.js new file mode 100644 index 0000000..f6395d7 --- /dev/null +++ b/tests/unit/utils/downloads.spec.js @@ -0,0 +1,12 @@ +import { aggregateDownloadLinks } from '../../../src/utils/downloads' + +describe('download utils', () => { + describe('aggregateDownloadLinks', () => { + it('merges links into a single string', () => { + const release = { link: 'abcde' } + const aggregated = aggregateDownloadLinks([release, release]) + + expect(aggregated).toBe('abcde;abcde') + }) + }) +})