custom-media: add converter to CyTube Media object
This commit is contained in:
parent
8b7cdfd4c3
commit
f4ce2fe69d
5 changed files with 131 additions and 2 deletions
|
|
@ -1,5 +1,5 @@
|
|||
const assert = require('assert');
|
||||
const { validate } = require('../lib/custom-media');
|
||||
const { validate, convert } = require('../lib/custom-media');
|
||||
|
||||
describe('custom-media', () => {
|
||||
let valid, invalid;
|
||||
|
|
@ -203,4 +203,71 @@ describe('custom-media', () => {
|
|||
assert.throws(() => validate(invalid), /URL hostname must be a domain name/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#convert', () => {
|
||||
let expected;
|
||||
|
||||
beforeEach(() => {
|
||||
expected = {
|
||||
title: 'Test Video',
|
||||
seconds: 10,
|
||||
duration: '00:10',
|
||||
type: 'cm',
|
||||
meta: {
|
||||
direct: {
|
||||
1080: [
|
||||
{
|
||||
link: 'https://example.com/video.mp4',
|
||||
contentType: 'video/mp4',
|
||||
quality: 1080
|
||||
}
|
||||
]
|
||||
},
|
||||
textTracks: [
|
||||
{
|
||||
url: 'https://example.com/subtitles.vtt',
|
||||
contentType: 'text/vtt',
|
||||
name: 'English Subtitles'
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
function cleanForComparison(actual) {
|
||||
actual = actual.pack();
|
||||
delete actual.id;
|
||||
|
||||
// Strip out extraneous undefineds
|
||||
for (let key in actual.meta) {
|
||||
if (actual.meta[key] === undefined) delete actual.meta[key];
|
||||
}
|
||||
|
||||
return actual;
|
||||
}
|
||||
|
||||
it('converts custom metadata to a CyTube Media object', () => {
|
||||
const media = convert(valid);
|
||||
|
||||
assert(media.id != null, 'should have generated id');
|
||||
|
||||
const actual = cleanForComparison(media);
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
|
||||
it('sets duration to 0 if live = true', () => {
|
||||
valid.live = true;
|
||||
expected.duration = '00:00';
|
||||
expected.seconds = 0;
|
||||
|
||||
const media = convert(valid);
|
||||
|
||||
assert(media.id != null, 'should have generated id');
|
||||
|
||||
const actual = cleanForComparison(media);
|
||||
|
||||
assert.deepStrictEqual(actual, expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
18
test/util/hash.js
Normal file
18
test/util/hash.js
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
const { hash } = require('../../lib/util/hash');
|
||||
const assert = require('assert');
|
||||
|
||||
describe('hash', () => {
|
||||
describe('#hash', () => {
|
||||
const input = 'this is a test';
|
||||
|
||||
it('hashes input correctly', () => {
|
||||
const sha256_hex = '2e99758548972a8e8822ad47fa1017ff72f06f3ff6a016851f45c398732bc50c';
|
||||
assert.strictEqual(hash('sha256', input, 'hex'), sha256_hex);
|
||||
});
|
||||
|
||||
it('hashes input to base64', () => {
|
||||
const sha256_base64 = 'Lpl1hUiXKo6IIq1H+hAX/3Lwbz/2oBaFH0XDmHMrxQw=';
|
||||
assert.strictEqual(hash('sha256', input, 'base64'), sha256_base64);
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue