Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions packages/social/ugig/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
import { fakeConnectContext, smokeTest } from '@profullstack/sh1pt-core/testing';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { smokeTest } from '@profullstack/sh1pt-core/testing';
import adapter from './index.js';

smokeTest(adapter, { idPrefix: 'social' });

afterEach(() => {
vi.restoreAllMocks();
});

describe('social-ugig adapter', () => {
it('connects through the current ugig profile endpoint', async () => {
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
json: async () => ({ profile: { id: 'user-123', username: 'safe_earn_393559' } }),
} as any);

const ctx = fakeConnectContext({ UGIG_TOKEN: 'test-token' });
const result = await adapter.connect(ctx as any, {});

expect(result.accountId).toBe('safe_earn_393559');
expect(fetch).toHaveBeenCalledWith(
'https://ugig.net/api/profile',
expect.objectContaining({
headers: { Authorization: 'Bearer test-token' },
}),
);
});
});
9 changes: 4 additions & 5 deletions packages/social/ugig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { defineSocial, oauthSetup } from '@profullstack/sh1pt-core';
// GET /api/gigs — list gigs
// POST /api/applications — apply to a gig
// POST /api/auth/login — authenticate (email + password)
// GET /api/profile — get authenticated user profile
// GET /api/users/me — get authenticated user profile
//
// Rate limits: not publicly documented; avoid bursting > ~10 req/min.

Expand All @@ -34,13 +34,12 @@ export default defineSocial<Config>({
const token = ctx.secret('UGIG_TOKEN');
if (!token) throw new Error('UGIG_TOKEN not in vault — see setup()');

const res = await fetch(`${UGIG_API}/profile`, {
const res = await fetch(`${UGIG_API}/users/me`, {
headers: { Authorization: `Bearer ${token}` },
});
if (!res.ok) throw new Error(`ugig auth check failed: HTTP ${res.status}`);
const data = await res.json() as { profile?: { username?: string; id?: string }; username?: string; id?: string };
const profile = data.profile ?? data;
const username = profile.username ?? config.username ?? 'ugig';
const data = await res.json() as { username?: string; id?: string };
const username = data.username ?? config.username ?? 'ugig';
ctx.log(`ugig connected · @${username}`);
return { accountId: username };
},
Expand Down
Loading