diff --git a/tests/commands/discussion/validate.test.ts b/tests/commands/discussion/validate.test.ts new file mode 100644 index 0000000000..54adb808cc --- /dev/null +++ b/tests/commands/discussion/validate.test.ts @@ -0,0 +1,104 @@ +import { describe, beforeEach, it, expect } from 'vitest' +import { pathToFileURL } from 'node:url' +import { execFileSync } from 'child_process' +import * as fs from 'fs-extra' + +const ENV = { + ...process.env, + DATA_DIR: 'tests/__data__/input/data', + STREAMS_DIR: 'tests/__data__/output/streams', + LOGS_DIR: 'tests/__data__/output/logs', + GITHUB_REPOSITORY: 'test-owner/test-repo', + GITHUB_SHA: 'main' +} + +beforeEach(() => { + fs.emptyDirSync('tests/__data__/output') + fs.copySync('tests/__data__/input/discussion_validate/streams', 'tests/__data__/output/streams') +}) + +describe('discussion:validate', () => { + it('can handle fulfilled channel search request', () => { + const discussionNumber = 19956 + const body = '### Channel ID\n\nCNBCe.tr@SD' + + const stdout = runDiscussionValidate(discussionNumber, body) + if (process.env.DEBUG === 'true') console.log(stdout) + + const result = readResultJson() + expect(result.status).toBe('fulfilled') + expect(result.label).toBe('check:failed') + expect(result.comment).toContain('https://github.com/test-owner/test-repo/blob/main/') + expect(result.close).toBe('true') + }) + + it('can handle duplicate channel search request', () => { + const discussionNumber = 19958 + const body = '### Channel ID\n\nCNBCe.tr@SD' + + try { + runDiscussionValidate(discussionNumber, body) + throw new Error('Expected process to fail for duplicate request') + } catch { + const result = readResultJson() + expect(result.status).toBe('duplicate_request') + expect(result.label).toBe('check:failed') + expect(result.comment).toContain('Duplicate of #19956.') + expect(result.close).toBe('true') + } + }) + + it('can handle invalid channel id request', () => { + const discussionNumber = 19959 + const body = '### Channel ID\n\nCNBCe.com@SD' + + try { + runDiscussionValidate(discussionNumber, body) + throw new Error('Expected process to fail for invalid channel ID') + } catch { + const result = readResultJson() + expect(result.status).toBe('invalid_channel_id') + expect(result.label).toBe('check:failed') + expect(result.comment).toContain('There is no channel with the ID "CNBCe.com" in the database.') + expect(result.close).toBe('true') + } + }) + + it('can handle missing feed id request', () => { + const discussionNumber = 19960 + const body = '### Channel ID\n\nCNBCe.tr' + + try { + runDiscussionValidate(discussionNumber, body) + throw new Error('Expected process to fail for missing feed ID') + } catch { + const result = readResultJson() + expect(result.status).toBe('missing_feed_id') + expect(result.label).toBe('check:failed') + expect(result.comment).toContain('The request is missing the feed ID.') + expect(result.close).toBe('true') + } + }) +}) + +function runDiscussionValidate(number: number, body: string) { + return execFileSync( + process.execPath, + [ + '--import', + 'tsx', + 'scripts/commands/discussion/validate.ts', + '--number', + `${number}`, + '--body', + body + ], + { encoding: 'utf8', env: ENV } + ) +} + +function readResultJson() { + const filepath = 'tests/__data__/output/logs/result.json' + const raw = fs.readFileSync(pathToFileURL(filepath), { encoding: 'utf8' }) + return JSON.parse(raw) +} \ No newline at end of file diff --git a/tests/commands/playlist/validate.test.ts b/tests/commands/playlist/validate.test.ts index 29595ad853..6b4c664814 100644 --- a/tests/commands/playlist/validate.test.ts +++ b/tests/commands/playlist/validate.test.ts @@ -126,7 +126,7 @@ describe('playlist:validate', () => { } catch (error) { if (process.env.DEBUG === 'true') console.log(cmd, error) expect((error as ExecError).stdout).toContain( - 'log_level.m3u\n 2 error \"new: https://streamer2.nexgen.bz/07-CHANNEL7/index.m3u8\" is not a valid URL\n\n1 problems (1 errors, 0 warnings)\n' + 'log_level.m3u\n 2 error "new: https://streamer2.nexgen.bz/07-CHANNEL7/index.m3u8" is not a valid URL\n\n1 problems (1 errors, 0 warnings)\n' ) } }) diff --git a/tests/commands/report/create.test.ts b/tests/commands/report/create.test.ts index 35a96a26d5..1a4d730f02 100644 --- a/tests/commands/report/create.test.ts +++ b/tests/commands/report/create.test.ts @@ -23,11 +23,13 @@ describe('report:create', () => { │ 4 │ 14179 │ 'streams:add' │ 'ManoramaNews.in' │ '(https://mitelefe.com/Api/Videos/GetSourceUrl/694564/0/HLS / https://ssl.cloud.telefe.com/Api/Vid...' │ 'invalid_stream_url' │ │ 5 │ 15175 │ 'streams:add' │ 'Channel7.bz@SD' │ 'new: https://streamer2.nexgen.bz/07-CHANNEL7/index.m3u8' │ 'invalid_stream_url' │ │ 6 │ 16120 │ 'streams:remove' │ undefined │ 'http://190.61.102.67:2000/play/a038/index.m3u8' │ 'nonexistent_link' │ -│ 7 │ 19956 │ 'channel search' │ 'CNBCe.tr' │ undefined │ 'invalid_channel_id' │ -│ 8 │ 19957 │ 'channel search' │ '13thStreet.au' │ undefined │ 'channel_closed' │ -│ 9 │ 20956 │ 'channel search' │ 'IONTV.us' │ undefined │ 'fulfilled' │ -│ 10 │ 25157 │ 'streams:add' │ 'OnTimeSports.eg@SD' │ 'OnTime Sports SD.mu38' │ 'invalid_stream_url' │ -│ 11 │ 39097 │ 'streams:edit' │ '~' │ 'https://jmp2.uk/plu-5a74b8e1e22a61737979c6bf.m3u8' │ 'nonexistent_link' │ +│ 7 │ 19957 │ 'channel search' │ '13thStreet.au' │ undefined │ 'channel_closed' │ +│ 8 │ 19958 │ 'channel search' │ 'CNBCe.tr@SD' │ undefined │ 'duplicate_request' │ +│ 9 │ 19959 │ 'channel search' │ 'CNBCe.com' │ undefined │ 'invalid_channel_id' │ +│ 10 │ 19960 │ 'channel search' │ 'CNBCe.tr' │ undefined │ 'duplicate_request' │ +│ 11 │ 20956 │ 'channel search' │ 'IONTV.us' │ undefined │ 'fulfilled' │ +│ 12 │ 25157 │ 'streams:add' │ 'OnTimeSports.eg@SD' │ 'OnTime Sports SD.mu38' │ 'invalid_stream_url' │ +│ 13 │ 39097 │ 'streams:edit' │ '~' │ 'https://jmp2.uk/plu-5a74b8e1e22a61737979c6bf.m3u8' │ 'nonexistent_link' │ └─────────┴─────────────┴──────────────────┴─────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────────────────┘`).trim() ) ).toBe(true)