Files
epg/tests/commands/guides/update.test.js

96 lines
3.9 KiB
JavaScript
Raw Normal View History

2022-02-26 23:21:44 +03:00
const { execSync } = require('child_process')
const fs = require('fs-extra')
const path = require('path')
2022-03-15 15:26:24 +03:00
const glob = require('glob')
2022-02-26 23:21:44 +03:00
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
2022-04-16 23:05:58 +03:00
fs.copyFileSync(
'tests/__data__/input/database/update-guides/programs.db',
'tests/__data__/output/programs.db'
)
2023-01-08 13:17:49 +03:00
})
2022-10-26 04:41:20 +03:00
2023-01-08 13:17:49 +03:00
it('can generate /guides', () => {
2022-02-26 23:21:44 +03:00
const stdout = execSync(
2022-10-26 04:41:20 +03:00
'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/output/logs DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output CURR_DATE=2022-10-20 npm run guides:update',
2022-02-26 23:21:44 +03:00
{ encoding: 'utf8' }
)
2023-01-08 13:17:49 +03:00
expect(stdout).toBe(
`
> guides:update
> NODE_OPTIONS=--max-old-space-size=5120 node scripts/commands/guides/update.js
starting...
loading data/countries.json...
loading data/channels.json...
loading data/regions.json...
loading data/subdivisions.json...
loading database/programs.db...
found 5 programs
creating tests/__data__/output/guides/dk.xml...
creating tests/__data__/output/guides/dk.xml.gz...
creating tests/__data__/output/guides/dk.json...
creating tests/__data__/output/guides/uk.xml...
creating tests/__data__/output/guides/uk.xml.gz...
creating tests/__data__/output/guides/uk.json...
2023-01-08 15:02:36 +03:00
creating tests/__data__/output/guides/allente.se/da.xml...
creating tests/__data__/output/guides/allente.se/da.xml.gz...
creating tests/__data__/output/guides/allente.se/da.json...
creating tests/__data__/output/guides/virginmedia.com/en.xml...
creating tests/__data__/output/guides/virginmedia.com/en.xml.gz...
creating tests/__data__/output/guides/virginmedia.com/en.json...
creating tests/__data__/output/guides/sky.com/fr.xml...
creating tests/__data__/output/guides/sky.com/fr.xml.gz...
creating tests/__data__/output/guides/sky.com/fr.json...
creating tests/__data__/output/guides/sky.com/en.xml...
creating tests/__data__/output/guides/sky.com/en.xml.gz...
creating tests/__data__/output/guides/sky.com/en.json...
2023-01-08 13:17:49 +03:00
creating tests/__data__/output/logs/guides/update.log...
report:
(index) type site lang channel broadcast_area languages
0 'no_guide' 'sky.com' 'fr' 'CNN.us' [ 'c/US' ] [ 'eng' ]
found 1 error(s)
`
)
2022-10-19 23:08:34 +03:00
const uncompressed = glob
2022-10-26 04:41:20 +03:00
.sync('tests/__data__/expected/guides/*.xml')
2022-10-19 23:08:34 +03:00
.map(f => f.replace('tests/__data__/expected/', ''))
uncompressed.forEach(filepath => {
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
2022-03-15 15:26:24 +03:00
const compressed = glob
2022-10-26 04:41:20 +03:00
.sync('tests/__data__/expected/guides/*.xml.gz')
2022-03-15 15:26:24 +03:00
.map(f => f.replace('tests/__data__/expected/', ''))
compressed.forEach(filepath => {
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
2022-10-06 14:12:53 +03:00
const json = glob
2022-10-26 04:41:20 +03:00
.sync('tests/__data__/expected/guides/*.json')
2022-10-06 14:12:53 +03:00
.map(f => f.replace('tests/__data__/expected/', ''))
json.forEach(filepath => {
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
2022-02-26 23:21:44 +03:00
2022-10-26 04:41:20 +03:00
expect(content('output/logs/guides/update.log')).toEqual(
content('expected/logs/guides/update.log')
)
})
2022-02-26 23:21:44 +03:00
function content(filepath) {
2022-03-15 15:26:24 +03:00
return fs.readFileSync(`tests/__data__/${filepath}`, {
2022-02-26 23:21:44 +03:00
encoding: 'utf8'
})
}