refactor: align export, settings and database with the VidIQ record model
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
6de9e9656c
commit
1cf5270704
+24
-13
@@ -6,33 +6,45 @@ const record = (over = {}) => ({
|
||||
videoId: 'dQw4w9WgXcQ',
|
||||
title: 'Hello',
|
||||
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
thumbnailUrl: 'https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg',
|
||||
channelId: 'UC1',
|
||||
thumbnailUrl: 'https://i.ytimg.com/vi/dQw4w9WgXcQ/mqdefault.jpg',
|
||||
channelTitle: 'Chan',
|
||||
channelUrl: 'https://www.youtube.com/@chan',
|
||||
subscribers: 1000,
|
||||
views: 50000,
|
||||
publishedAt: '2026-10-01T00:00:00Z',
|
||||
durationSec: 600,
|
||||
outlierScore: 50,
|
||||
isShort: false,
|
||||
score: 50,
|
||||
vidiqScore: null,
|
||||
foundOn: 'home',
|
||||
firstSeenAt: '2026-10-25T10:00:00.000Z',
|
||||
updatedAt: '2026-10-25T10:00:00.000Z',
|
||||
...over,
|
||||
});
|
||||
|
||||
test('COLUMNS lists the stored fields in order', () => {
|
||||
assert.deepEqual(COLUMNS, [
|
||||
'videoId',
|
||||
'title',
|
||||
'url',
|
||||
'thumbnailUrl',
|
||||
'channelTitle',
|
||||
'channelUrl',
|
||||
'subscribers',
|
||||
'views',
|
||||
'outlierScore',
|
||||
'isShort',
|
||||
'foundOn',
|
||||
'firstSeenAt',
|
||||
'updatedAt',
|
||||
]);
|
||||
});
|
||||
|
||||
test('toCsv writes a header and one row per record', () => {
|
||||
const csv = toCsv([record()]);
|
||||
assert.equal(
|
||||
csv,
|
||||
toCsv([record()]),
|
||||
COLUMNS.join(',') +
|
||||
'\r\n' +
|
||||
'dQw4w9WgXcQ,Hello,https://www.youtube.com/watch?v=dQw4w9WgXcQ,' +
|
||||
'https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg,UC1,Chan,https://www.youtube.com/@chan,' +
|
||||
'1000,50000,2026-10-01T00:00:00Z,600,false,50,,home,' +
|
||||
'2026-10-25T10:00:00.000Z,2026-10-25T10:00:00.000Z\r\n',
|
||||
'https://i.ytimg.com/vi/dQw4w9WgXcQ/mqdefault.jpg,Chan,https://www.youtube.com/@chan,' +
|
||||
'1000,50000,50,false,home,2026-10-25T10:00:00.000Z,2026-10-25T10:00:00.000Z\r\n',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -42,10 +54,9 @@ test('toCsv quotes commas, quotes and newlines', () => {
|
||||
});
|
||||
|
||||
test('toCsv writes null and undefined as empty cells and keeps booleans readable', () => {
|
||||
const csv = toCsv([record({ subscribers: null, vidiqScore: 7.5, isShort: true, channelUrl: undefined })]);
|
||||
const csv = toCsv([record({ subscribers: null, isShort: true, channelUrl: undefined })]);
|
||||
const row = csv.split('\r\n')[1];
|
||||
assert.ok(row.includes(',true,'));
|
||||
assert.ok(row.includes(',7.5,'));
|
||||
assert.ok(row.includes('Chan,,,50000')); // channelUrl and subscribers empty
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user