mirror of
https://github.com/nfonteyne/octane-website.git
synced 2026-09-03 23:24:48 +02:00
update: unit test, push packages with ci/cd
This commit is contained in:
parent
e97aa2c6c3
commit
0300f7fef0
6 changed files with 165 additions and 5 deletions
16
test/spotify.test.js
Normal file
16
test/spotify.test.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { isValidSpotifyUrl } = require('../src/lib/spotify');
|
||||
|
||||
test('isValidSpotifyUrl: true for open.spotify.com links', () => {
|
||||
assert.equal(isValidSpotifyUrl('https://open.spotify.com/track/4uLU6hMCjMI75M1A2tKUQC'), true);
|
||||
});
|
||||
|
||||
test('isValidSpotifyUrl: false for other hosts', () => {
|
||||
assert.equal(isValidSpotifyUrl('https://www.youtube.com/watch?v=abc'), false);
|
||||
assert.equal(isValidSpotifyUrl('https://spotify.com/track/abc'), false);
|
||||
});
|
||||
|
||||
test('isValidSpotifyUrl: false for malformed URL', () => {
|
||||
assert.equal(isValidSpotifyUrl('not a url'), false);
|
||||
});
|
||||
36
test/youtube.test.js
Normal file
36
test/youtube.test.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const { test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { extractVideoId, isValidYoutubeUrl } = require('../src/lib/youtube');
|
||||
|
||||
test('extractVideoId: standard watch URL', () => {
|
||||
assert.equal(extractVideoId('https://www.youtube.com/watch?v=dQw4w9WgXcQ'), 'dQw4w9WgXcQ');
|
||||
});
|
||||
|
||||
test('extractVideoId: watch URL with extra query params', () => {
|
||||
assert.equal(
|
||||
extractVideoId('https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=30s&list=abc'),
|
||||
'dQw4w9WgXcQ'
|
||||
);
|
||||
});
|
||||
|
||||
test('extractVideoId: short youtu.be URL', () => {
|
||||
assert.equal(extractVideoId('https://youtu.be/dQw4w9WgXcQ'), 'dQw4w9WgXcQ');
|
||||
});
|
||||
|
||||
test('extractVideoId: embed URL', () => {
|
||||
assert.equal(extractVideoId('https://www.youtube.com/embed/dQw4w9WgXcQ'), 'dQw4w9WgXcQ');
|
||||
});
|
||||
|
||||
test('extractVideoId: non-YouTube host returns null', () => {
|
||||
assert.equal(extractVideoId('https://vimeo.com/12345'), null);
|
||||
});
|
||||
|
||||
test('extractVideoId: malformed URL returns null', () => {
|
||||
assert.equal(extractVideoId('not a url'), null);
|
||||
});
|
||||
|
||||
test('isValidYoutubeUrl: true for valid links, false otherwise', () => {
|
||||
assert.equal(isValidYoutubeUrl('https://www.youtube.com/watch?v=dQw4w9WgXcQ'), true);
|
||||
assert.equal(isValidYoutubeUrl('https://open.spotify.com/track/abc'), false);
|
||||
assert.equal(isValidYoutubeUrl(''), false);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue