✨ feature: Enhance output options with Google Sheets integration and improve Excel writer functionality
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { GoogleSheetsWriter } from '../src/output/googleSheets.js';
|
||||
|
||||
describe('GoogleSheetsWriter', () => {
|
||||
it('creates missing sheets and appends content, sponsor, and dead-link rows', async () => {
|
||||
const calls: unknown[] = [];
|
||||
const sheets = {
|
||||
spreadsheets: {
|
||||
get: async () => ({
|
||||
data: { sheets: [{ properties: { title: 'Sponsored Links' } }] }
|
||||
}),
|
||||
batchUpdate: async (request: unknown) => {
|
||||
calls.push(request);
|
||||
},
|
||||
values: {
|
||||
append: async (request: unknown) => {
|
||||
calls.push(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
await new GoogleSheetsWriter('sheet-1', undefined, sheets).write({
|
||||
rows: [
|
||||
{
|
||||
'Source Newsletter': 'A Very Long Newsletter Name That Is Fine In Google Sheets',
|
||||
Title: '=Formula',
|
||||
'Link URL': 'https://example.com'
|
||||
}
|
||||
],
|
||||
sponsors: [{ Newsletter: 'Weekly', Sponsor: 'Acme', Link: 'https://sponsor.example' }],
|
||||
deadLinks: [{ URL: 'https://dead.example', Status: '404' }]
|
||||
});
|
||||
|
||||
expect(calls[0]).toMatchObject({
|
||||
spreadsheetId: 'sheet-1',
|
||||
requestBody: {
|
||||
requests: [
|
||||
{
|
||||
addSheet: {
|
||||
properties: { title: 'A Very Long Newsletter Name That Is Fine In Google Sheets' }
|
||||
}
|
||||
},
|
||||
{ addSheet: { properties: { title: 'Dead Links' } } }
|
||||
]
|
||||
}
|
||||
});
|
||||
expect(calls).toContainEqual(
|
||||
expect.objectContaining({
|
||||
spreadsheetId: 'sheet-1',
|
||||
range: "'A Very Long Newsletter Name That Is Fine In Google Sheets'!A1",
|
||||
requestBody: {
|
||||
values: [
|
||||
[
|
||||
'Issue Date',
|
||||
'Category',
|
||||
'Link URL',
|
||||
'Title',
|
||||
'Description',
|
||||
'Page Title + Meta',
|
||||
'Also In'
|
||||
],
|
||||
['', '', 'https://example.com', "'=Formula", '', '', '']
|
||||
]
|
||||
}
|
||||
})
|
||||
);
|
||||
expect(calls).toContainEqual(
|
||||
expect.objectContaining({
|
||||
range: "'Sponsored Links'!A1"
|
||||
})
|
||||
);
|
||||
expect(calls).toContainEqual(
|
||||
expect.objectContaining({
|
||||
range: "'Dead Links'!A1"
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user