import { describe, it, expect, vi } from 'vitest';
import { schedulePost, getPostAnalytics } from '../src/hootsuite-service';
vi.mock('../src/hootsuite-client', () => ({
HootsuiteClient: vi.fn().mockImplementation(() => ({
createMessage: vi.fn().mockResolvedValue({
id: 'msg_abc123',
state: 'SCHEDULED',
scheduledSendTime: '2026-04-07T14:00:00Z',
socialProfileIds: ['sp_twitter', 'sp_linkedin'],
}),
getAnalytics: vi.fn().mockResolvedValue({
postId: 'msg_abc123',
metrics: { impressions: 1200, clicks: 85, engagement_rate: 0.071 },
}),
listSocialProfiles: vi.fn().mockResolvedValue({
profiles: [
{ id: 'sp_twitter', type: 'TWITTER', name: '@company' },
{ id: 'sp_linkedin', type: 'LINKEDIN', name: 'Company Page' },
],
}),
})),
}));
describe('Hootsuite Service', () => {
it('schedules a multi-network post', async () => {
const result = await schedulePost('Launch day!', {
profiles: ['sp_twitter', 'sp_linkedin'],
scheduledTime: '2026-04-07T14:00:00Z',
});
expect(result.state).toBe('SCHEDULED');
expect(result.socialProfileIds).toHaveLength(2);
});
it('retrieves post analytics', async () => {
const analytics = await getPostAnalytics('msg_abc123');
expect(analytics.metrics.engagement_rate).toBeGreaterThan(0.05);
});
});
import { describe, it, expect } from 'vitest';
const hasCredentials = !!process.env.HOOTSUITE_CLIENT_ID;
describe.skipIf(!hasCredentials)('Hootsuite Live API', () => {
it('lists social profiles via OAuth', async () => {
const tokenRes = await fetch('https://platform.hootsuite.com/oauth2/token', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({
grant_type: 'refresh_token',
client_id: process.env.HOOTSUITE_CLIENT_ID!,
client_secret: process.env.HOOTSUITE_CLIENT_SECRET!,
refresh_token: process.env.HOOTSUITE_REFRESH_TOKEN!,
}),
});
const { access_token } = await tokenRes.json();
const res = await fetch('https://platform.hootsuite.com/v1/socialProfiles', {
headers: { Authorization: `Bearer ${access_token}` },
});
expect(res.status).toBe(200);
});
});