performance-adlevels.real.test.ts•1.8 kB
import { describe, it, expect } from 'vitest';
import { registerTools } from '../../src/server-tools.js';
type ToolHandler = (input?: any) => Promise<any> | any;
class LiveServer { public tools: Record<string, ToolHandler> = {}; tool(def: any, handler: ToolHandler) { this.tools[def.name] = handler; } }
async function pickAccountId(server: LiveServer): Promise<string | undefined> {
const res = await server.tools['list_resources']({ kind: 'accounts', output_format: 'table' });
const text = res.content[0].text as string;
const m = text.match(/\b(\d{10})\b/);
return process.env.GOOGLE_ADS_ACCOUNT_ID || m?.[1];
}
describe('live: performance ad_group and ad levels', () => {
it('ad_group performance last 7 days', async () => {
if (!process.env.GOOGLE_ADS_DEVELOPER_TOKEN) return;
const server = new LiveServer();
registerTools(server as any);
const cid = await pickAccountId(server);
if (!cid) return;
const res = await server.tools['get_performance']({ customer_id: cid, level: 'ad_group', days: 7, limit: 5, output_format: 'table' });
const text = res.content[0].text as string;
expect(text.includes('Performance (ad_group)') || text.toLowerCase().includes('no results')).toBe(true);
}, 30_000);
it('ad performance last 7 days', async () => {
if (!process.env.GOOGLE_ADS_DEVELOPER_TOKEN) return;
const server = new LiveServer();
registerTools(server as any);
const cid = await pickAccountId(server);
if (!cid) return;
const res = await server.tools['get_performance']({ customer_id: cid, level: 'ad', days: 7, limit: 5, output_format: 'table' });
const text = res.content[0].text as string;
expect(text.includes('Performance (ad)') || text.toLowerCase().includes('no results')).toBe(true);
}, 30_000);
});