Files
epg/tests/commands/channels/validate.test.ts

55 lines
3.2 KiB
TypeScript
Raw Normal View History

2023-10-15 14:08:23 +03:00
import { execSync } from 'child_process'
import os from 'os'
type ExecError = {
status: number
stdout: string
}
2025-04-02 07:12:46 +03:00
let ENV_VAR = 'DATA_DIR=tests/__data__/input/__data__'
2023-10-15 14:08:23 +03:00
if (os.platform() === 'win32') {
2025-04-02 07:12:46 +03:00
ENV_VAR = 'SET "DATA_DIR=tests/__data__/input/__data__" &&'
2023-10-15 14:08:23 +03:00
}
describe('channels:validate', () => {
it('will show a message if the file contains a duplicate', () => {
try {
2025-04-02 07:12:46 +03:00
const cmd = `${ENV_VAR} npm run channels:validate --- tests/__data__/input/channels_validate/duplicate.channels.xml`
2025-01-05 19:02:24 +03:00
const stdout = execSync(cmd, { encoding: 'utf8' })
2025-01-07 19:24:50 +03:00
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
2023-10-15 14:08:23 +03:00
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
2024-12-15 06:17:31 +03:00
expect((error as ExecError).stdout).toContain(`
2025-04-02 07:12:46 +03:00
(index) type lang xmltv_id site_id name
0 'duplicate' 'en' 'Bravo.us@East' '140' 'Bravo'
2024-12-15 06:17:31 +03:00
1 error(s) in 1 file(s)
`)
2023-10-15 14:08:23 +03:00
}
})
it('will show a message if the file contains a channel with wrong xmltv_id', () => {
try {
2025-04-02 07:12:46 +03:00
const cmd = `${ENV_VAR} npm run channels:validate --- tests/__data__/input/channels_validate/wrong_xmltv_id.channels.xml`
2025-01-05 19:02:24 +03:00
const stdout = execSync(cmd, { encoding: 'utf8' })
2025-01-07 19:24:50 +03:00
if (process.env.DEBUG === 'true') console.log(cmd, stdout)
2023-10-15 14:08:23 +03:00
process.exit(1)
} catch (error) {
expect((error as ExecError).status).toBe(1)
2024-12-15 06:17:31 +03:00
expect((error as ExecError).stdout).toContain(`
2023-10-15 14:08:23 +03:00
2024-12-15 06:17:31 +03:00
(index) type lang xmltv_id site_id name
2023-10-15 14:08:23 +03:00
2024-12-15 06:17:31 +03:00
0 'wrong_xmltv_id' 'en' 'CNNInternational' '140' 'CNN International'
2023-10-15 14:08:23 +03:00
2024-12-15 06:17:31 +03:00
1 error(s) in 1 file(s)
`)
2023-10-15 14:08:23 +03:00
}
})
})