mirror of
https://github.com/iptv-org/iptv
synced 2026-10-21 18:46:20 -04:00
Update tests
This commit is contained in:
1 parent
a22cf5960e
commit
4d12a29e96
3 files changed
+112
-6
No files matched your search
@@ -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)
|
||||||
|
}
|
||||||
@@ -126,7 +126,7 @@ describe('playlist:validate', () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
if (process.env.DEBUG === 'true') console.log(cmd, error)
|
||||||
expect((error as ExecError).stdout).toContain(
|
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'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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' │
|
│ 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' │
|
│ 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' │
|
│ 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' │
|
│ 7 │ 19957 │ 'channel search' │ '13thStreet.au' │ undefined │ 'channel_closed' │
|
||||||
│ 8 │ 19957 │ 'channel search' │ '13thStreet.au' │ undefined │ 'channel_closed' │
|
│ 8 │ 19958 │ 'channel search' │ 'CNBCe.tr@SD' │ undefined │ 'duplicate_request' │
|
||||||
│ 9 │ 20956 │ 'channel search' │ 'IONTV.us' │ undefined │ 'fulfilled' │
|
│ 9 │ 19959 │ 'channel search' │ 'CNBCe.com' │ undefined │ 'invalid_channel_id' │
|
||||||
│ 10 │ 25157 │ 'streams:add' │ 'OnTimeSports.eg@SD' │ 'OnTime Sports SD.mu38' │ 'invalid_stream_url' │
|
│ 10 │ 19960 │ 'channel search' │ 'CNBCe.tr' │ undefined │ 'duplicate_request' │
|
||||||
│ 11 │ 39097 │ 'streams:edit' │ '~' │ 'https://jmp2.uk/plu-5a74b8e1e22a61737979c6bf.m3u8' │ 'nonexistent_link' │
|
│ 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()
|
└─────────┴─────────────┴──────────────────┴─────────────────────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────┴──────────────────────┘`).trim()
|
||||||
)
|
)
|
||||||
).toBe(true)
|
).toBe(true)
|
||||||
|
|||||||
Reference in new issue
Block a user