2021-03-09 20:28:52 +01:00
|
|
|
const { howlong } = require('../../src/howlongtobeat/howlong.js')
|
2021-03-05 14:08:10 +01:00
|
|
|
const fs = require('fs');
|
|
|
|
const fsp = require('fs').promises;
|
2021-03-09 20:28:52 +01:00
|
|
|
const { rmdir } = require('./../utils')
|
2021-03-05 14:08:10 +01:00
|
|
|
|
|
|
|
const mdsample = `---
|
|
|
|
title: "wizardry 8 review"
|
|
|
|
game_name: "Wizardry 8"
|
|
|
|
---
|
|
|
|
|
|
|
|
blabla nice one 9/10 GG!
|
|
|
|
`
|
|
|
|
|
2021-07-01 13:49:30 +02:00
|
|
|
jest.disableAutomock()
|
|
|
|
jest.unmock('got')
|
|
|
|
|
2021-03-05 14:08:10 +01:00
|
|
|
const dumpdir = `${__dirname}/howlong-stub`
|
|
|
|
beforeEach(async () => {
|
|
|
|
if(fs.existsSync(dumpdir)) {
|
|
|
|
rmdir(dumpdir)
|
|
|
|
}
|
|
|
|
fs.mkdirSync(dumpdir)
|
|
|
|
|
|
|
|
await fsp.writeFile(`${dumpdir}/howlongtobeat-sample.md`, mdsample, 'utf-8')
|
|
|
|
})
|
|
|
|
|
2021-07-01 13:49:30 +02:00
|
|
|
test('howlong adds howlong to beat id and hours to frontmatter', async() => {
|
|
|
|
await howlong({
|
|
|
|
postDir: dumpdir,
|
|
|
|
downloadDir: dumpdir
|
|
|
|
})
|
2021-03-05 14:08:10 +01:00
|
|
|
|
|
|
|
const actualmd = await fsp.readFile(`${dumpdir}/howlongtobeat-sample.md`, 'utf-8')
|
2021-03-05 15:00:34 +01:00
|
|
|
expect(actualmd).toMatchSnapshot()
|
2021-03-05 14:08:10 +01:00
|
|
|
})
|
2021-07-01 13:49:30 +02:00
|
|
|
|
2022-11-06 09:52:39 +01:00
|
|
|
test('howlong downloads the thumbnail as cover.jpg into respective downloaddir', async() => {
|
2021-07-01 13:49:30 +02:00
|
|
|
await howlong({
|
|
|
|
postDir: dumpdir,
|
|
|
|
downloadDir: dumpdir
|
|
|
|
})
|
|
|
|
|
2022-11-06 09:52:39 +01:00
|
|
|
const actualmd = await fsp.readFile(`${dumpdir}/howlongtobeat-sample/cover.jpg`, 'utf-8')
|
2021-07-01 13:49:30 +02:00
|
|
|
expect(actualmd).not.toBeUndefined()
|
|
|
|
})
|