mirror of
https://github.com/snobu/destreamer.git
synced 2026-01-17 05:22:18 +00:00
refactor toward SharePoint downloader
This commit is contained in:
85
test/test.ts
85
test/test.ts
@@ -1,32 +1,14 @@
|
||||
import { parseInputFile } from '../src/Utils';
|
||||
import puppeteer from 'puppeteer';
|
||||
import { extractStreamGuids, parseInputFile } from '../src/Utils';
|
||||
import assert from 'assert';
|
||||
import tmp from 'tmp';
|
||||
import fs from 'fs';
|
||||
import { Session } from './Types';
|
||||
|
||||
|
||||
describe('Puppeteer', () => {
|
||||
it('should grab GitHub page title', async () => {
|
||||
const browser = await puppeteer.launch({
|
||||
headless: true,
|
||||
args: ['--disable-dev-shm-usage', '--fast-start', '--no-sandbox']
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
await page.goto('https://github.com/', { waitUntil: 'load' });
|
||||
|
||||
let pageTitle = await page.title();
|
||||
assert.equal(true, pageTitle.includes('GitHub'));
|
||||
|
||||
await browser.close();
|
||||
}).timeout(30000); // yeah, this may take a while...
|
||||
});
|
||||
import { StreamSession, VideoUrl } from './Types';
|
||||
|
||||
|
||||
// we cannot test groups parsing as that requires an actual session
|
||||
describe('Destreamer parsing', () => {
|
||||
it('Input file to arrays of URLs and DIRs', async () => {
|
||||
const testSession: Session = {
|
||||
it('Input file to arrays of guids', async () => {
|
||||
const testSession: StreamSession = {
|
||||
AccessToken: '',
|
||||
ApiGatewayUri: '',
|
||||
ApiGatewayVersion: ''
|
||||
@@ -44,33 +26,42 @@ describe('Destreamer parsing', () => {
|
||||
'https://web.microsoftstream.com/video/xxxxxx-gggg-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
''
|
||||
];
|
||||
const expectedGUIDsOut: Array<string> = [
|
||||
'xxxxxxxx-aaaa-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-bbbb-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-cccc-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-dddd-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
'xxxxxxxx-eeee-xxxx-xxxx-xxxxxxxxxxxx'
|
||||
];
|
||||
const expectedDirOut: Array<string> = [
|
||||
'videos',
|
||||
'luca',
|
||||
'videos',
|
||||
'videos',
|
||||
'videos'
|
||||
|
||||
const expectedStreamOut: Array<VideoUrl> = [
|
||||
{
|
||||
url: 'xxxxxxxx-aaaa-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
outDir: 'videos'
|
||||
},
|
||||
{
|
||||
url: 'xxxxxxxx-bbbb-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
outDir: 'luca'
|
||||
},
|
||||
{
|
||||
url: 'xxxxxxxx-cccc-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
outDir: 'videos'
|
||||
},
|
||||
{
|
||||
url: 'xxxxxxxx-dddd-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
outDir: 'videos'
|
||||
},
|
||||
{
|
||||
url: 'xxxxxxxx-eeee-xxxx-xxxx-xxxxxxxxxxxx',
|
||||
outDir: 'videos'
|
||||
},
|
||||
];
|
||||
|
||||
const tmpFile = tmp.fileSync({ postfix: '.txt' });
|
||||
fs.writeFileSync(tmpFile.fd, testIn.join('\r\n'));
|
||||
const [testUrlOut , testDirOut]: Array<Array<string>> = await parseInputFile(tmpFile.name, 'videos', testSession);
|
||||
if (testUrlOut.length !== expectedGUIDsOut.length) {
|
||||
throw "Expected url list and test list don't have the same number of elements".red;
|
||||
}
|
||||
else if (testDirOut.length !== expectedDirOut.length) {
|
||||
throw "Expected dir list and test list don't have the same number of elements".red;
|
||||
}
|
||||
assert.deepStrictEqual(testUrlOut, expectedGUIDsOut,
|
||||
'Error in parsing the URLs, missmatch between test and expected'.red);
|
||||
assert.deepStrictEqual(testUrlOut, expectedGUIDsOut,
|
||||
'Error in parsing the DIRs, missmatch between test and expected'.red);
|
||||
|
||||
const [testStreamUrls]: Array<Array<VideoUrl>> = parseInputFile(tmpFile.name, 'videos');
|
||||
|
||||
assert.deepStrictEqual(
|
||||
await extractStreamGuids(testStreamUrls, testSession),
|
||||
expectedStreamOut,
|
||||
'Error in parsing the URLs, missmatch between test and expected'.red
|
||||
);
|
||||
// assert.deepStrictEqual(testUrlOut, expectedGUIDsOut,
|
||||
// 'Error in parsing the DIRs, missmatch between test and expected'.red);
|
||||
assert.ok('Parsing of input file ok');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user