test: added more date tests and added download tests; workflow: mapped @/ path in jest config
This commit is contained in:
parent
bda628b30b
commit
21b7629bdc
@ -6,5 +6,8 @@ module.exports = {
|
|||||||
setupFiles: ['dotenv/config'],
|
setupFiles: ['dotenv/config'],
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.[t|j]sx?$': 'babel-jest'
|
'^.+\\.[t|j]sx?$': 'babel-jest'
|
||||||
|
},
|
||||||
|
moduleNameMapper: {
|
||||||
|
'@/(.*)': ['<rootDir>/src/$1']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,12 @@ export function sendAddToQueue(url, bitrate = null) {
|
|||||||
fetchData('addToQueue', { url, bitrate }, 'POST')
|
fetchData('addToQueue', { url, bitrate }, 'POST')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{ link: string }[]} releases
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
export function aggregateDownloadLinks(releases) {
|
export function aggregateDownloadLinks(releases) {
|
||||||
const links = []
|
const links = releases.map(release => release.link)
|
||||||
|
|
||||||
releases.forEach(release => {
|
|
||||||
links.push(release.link)
|
|
||||||
})
|
|
||||||
|
|
||||||
return links.join(';')
|
return links.join(';')
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,15 @@ import { checkNewRelease } from '../../../src/utils/dates.js'
|
|||||||
|
|
||||||
describe('date utils', () => {
|
describe('date utils', () => {
|
||||||
describe('checkNewRelease', () => {
|
describe('checkNewRelease', () => {
|
||||||
it("returns true with today's date", () => {
|
it("returns a positive result checking today's date", () => {
|
||||||
expect(checkNewRelease(new Date())).toBe(true)
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
12
tests/unit/utils/downloads.spec.js
Normal file
12
tests/unit/utils/downloads.spec.js
Normal file
@ -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')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user