From 77680e2dc9f77e263bdc9477849a5afebc8e3b8d Mon Sep 17 00:00:00 2001 From: freearhey <7253922+freearhey@users.noreply.github.com> Date: Tue, 18 Mar 2025 08:31:07 +0300 Subject: [PATCH] Update tests --- tests/db/export.test.ts | 4 +++- tests/db/update.test.ts | 5 +++-- tests/db/validate.test.ts | 20 ++++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/tests/db/export.test.ts b/tests/db/export.test.ts index e807de52..f7534dcd 100644 --- a/tests/db/export.test.ts +++ b/tests/db/export.test.ts @@ -7,7 +7,7 @@ beforeEach(() => { it('can export data as json', () => { execSync( - 'DATA_DIR=tests/__data__/input/data API_DIR=tests/__data__/output/api npm run db:export', + 'DATA_DIR=tests/__data__/input/export/data API_DIR=tests/__data__/output/api npm run db:export', { encoding: 'utf8' } @@ -15,6 +15,8 @@ it('can export data as json', () => { expect(content('output/api/blocklist.json')).toEqual(content('expected/api/blocklist.json')) expect(content('output/api/channels.json')).toEqual(content('expected/api/channels.json')) + expect(content('output/api/timezones.json')).toEqual(content('expected/api/timezones.json')) + expect(content('output/api/feeds.json')).toEqual(content('expected/api/feeds.json')) }) function content(filepath: string) { diff --git a/tests/db/update.test.ts b/tests/db/update.test.ts index 255bbaeb..11bdf72a 100644 --- a/tests/db/update.test.ts +++ b/tests/db/update.test.ts @@ -3,7 +3,7 @@ import * as fs from 'fs-extra' beforeEach(() => { fs.emptyDirSync('tests/__data__/output') - fs.copySync('tests/__data__/input/data', 'tests/__data__/output/data') + fs.copySync('tests/__data__/input/update/data', 'tests/__data__/output/data') }) it('can update db with data from issues', () => { @@ -13,8 +13,9 @@ it('can update db with data from issues', () => { expect(content('output/data/blocklist.csv')).toEqual(content('expected/data/blocklist.csv')) expect(content('output/data/channels.csv')).toEqual(content('expected/data/channels.csv')) + expect(content('output/data/feeds.csv')).toEqual(content('expected/data/feeds.csv')) expect(stdout).toEqual( - 'OUTPUT=closes #5871, closes #5901, closes #5701, closes #5900, closes #5899, closes #5898, closes #5897, closes #5891' + 'OUTPUT=closes #6871, closes #5871, closes #7901, closes #5901, closes #5701, closes #8900, closes #5900, closes #5899, closes #5898, closes #5897, closes #5891' ) }) diff --git a/tests/db/validate.test.ts b/tests/db/validate.test.ts index f60d3eda..ba4f2fb8 100644 --- a/tests/db/validate.test.ts +++ b/tests/db/validate.test.ts @@ -46,10 +46,13 @@ describe('db:validate', () => { expect((error as ExecError).stdout).toContain( 'entry with the channel "002RadioTV.do" and ref "eee" already exists' ) + expect((error as ExecError).stdout).toContain( + 'entry with the channel "002RadioTV.do" and id "SD" already exists' + ) } }) - it('shows an error if an invalid value is specified', () => { + it('shows an error if the data contains an error', () => { try { execSync('DATA_DIR=tests/__data__/input/validate/invalid_value npm run db:validate', { encoding: 'utf8' @@ -57,13 +60,22 @@ describe('db:validate', () => { process.exit(1) } catch (error) { expect((error as ExecError).status).toBe(1) + expect((error as ExecError).stdout).toContain('"aaa.us" is missing in the channels.csv') expect((error as ExecError).stdout).toContain( - '2 "aaa.us" is missing in the channels.csv' + '002RadioTV.do: "website" must be a valid uri with a scheme matching the http|https pattern' ) expect((error as ExecError).stdout).toContain( - '2 002RadioTV.do: "website" must be a valid uri with a scheme matching the http|https pattern' + 'entry with the channel "002RadioTV.do" and is_main "true" already exists' ) - expect((error as ExecError).stdout).toContain('2 error(s)') + expect((error as ExecError).stdout).toContain('"0TV.dk" is missing in the channels.csv') + expect((error as ExecError).stdout).toContain('"SD" has an invalid replaced_by "M5.hu@HD"') + expect((error as ExecError).stdout).toContain( + '"0TV.dk@SD" has the wrong timezone "Europe/Copenhagen"' + ) + expect((error as ExecError).stdout).toContain( + 'SD: "video_format" with value "576I" fails to match the required pattern' + ) + expect((error as ExecError).stdout).toContain('7 error(s)') } })