* init * get unit test working for course.ts file * added some other tests * tests halfway + change config to accomodate js files * utility functions tests done * fix: config file + miscellaneous fixes * fix: prepare script * fix lock file --------- Co-authored-by: Rotimi Best <[email protected]>
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
import { formatYoutubeVideo, getEmbedId } from './formatYoutubeVideo';
|
|
|
|
describe('format youtube video', () => {
|
|
test('should return the same url when given a valid youtube embed url', () => {
|
|
const url = 'https://www.youtube.com/embed/qajK1J1neAM';
|
|
const errors = { video: '' };
|
|
const result = formatYoutubeVideo(url, errors);
|
|
expect(result).toBe(url);
|
|
});
|
|
|
|
test('should return the correct embed url when given a youtube url with a start time parameter', () => {
|
|
const url = 'https://www.youtube.com/watch?v=qajK1J1neAM&start=123';
|
|
const errors = { video: '' };
|
|
const result = formatYoutubeVideo(url, errors);
|
|
expect(result).toBe('https://www.youtube.com/embed/qajK1J1neAM');
|
|
});
|
|
});
|
|
|
|
describe('getEmbedId', () => {
|
|
test('should return the correct embed id when the url contains "embed"', () => {
|
|
const url = 'https://www.youtube.com/embed/qajK1J1neAM';
|
|
const expectedEmbedId = 'qajK1J1neAM';
|
|
|
|
const result = getEmbedId(url);
|
|
|
|
expect(result).toBe(expectedEmbedId);
|
|
});
|
|
|
|
test('should return an empty string when the url does not contain "watch" or "embed" and is not in the format "youtu.be/"', () => {
|
|
const url = 'https://www.youtube.com/invalid-url';
|
|
const expectedEmbedId = '';
|
|
|
|
const result = getEmbedId(url);
|
|
|
|
expect(result).toBe(expectedEmbedId);
|
|
});
|
|
|
|
test('should return an empty string when the url is an empty string', () => {
|
|
const url = '';
|
|
const expectedEmbedId = '';
|
|
|
|
const result = getEmbedId(url);
|
|
|
|
expect(result).toBe(expectedEmbedId);
|
|
});
|
|
});
|