Files
solelog/apps/api/test/me.test.ts

23 lines
737 B
TypeScript

import { describe, it, expect } from 'vitest';
import { createApp } from '../src/app';
import { authToken, bearer } from './helpers';
describe('GET /api/me', () => {
it('rejects an unauthenticated request', async () => {
const app = createApp();
const res = await app.request('/api/me');
expect(res.status).toBe(401);
});
it('returns the user for a valid bearer token (create -> sign-in -> me)', async () => {
const app = createApp();
const email = 'me@example.com';
const token = await authToken(app, email);
const res = await app.request('/api/me', { headers: bearer(token) });
expect(res.status).toBe(200);
const body = await res.json();
expect(body.user.email).toBe(email);
});
});