Skip to content
Open
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
34 changes: 34 additions & 0 deletions app/api/auth/login/route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { describe, expect, it } from 'vitest';
import { POST } from './route';

describe('POST /api/auth/login', () => {
it('rejects missing credential fields with 400', async () => {
const request = new Request('http://localhost/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ identifier: 'octocat' }),
});

const response = await POST(request);

expect(response.status).toBe(400);
const body = await response.json();
expect(body.error).toContain('required');
});

it('returns a frontend-ready success payload when identifier and password are present', async () => {
const request = new Request('http://localhost/api/auth/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ identifier: 'octocat', password: 'password123' }),
});

const response = await POST(request);

expect(response.status).toBe(200);
const body = await response.json();
expect(body.success).toBe(true);
expect(body.message).toContain('Authentication successful');
expect(body.user.identifier).toBe('octocat');
});
});
8 changes: 5 additions & 3 deletions app/api/Auth/login/route.ts → app/api/auth/login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { NextResponse } from 'next/server';
* Handles credentials authentication requests for frontend login.
* Integrates with NextAuth sessions and production backend user models.
*/
export async function POST(request: Request) {
export async function POST(request: Request): Promise<Response> {
try {
const body = await request.json();
const { identifier, password } = body;
const { identifier, password } = body as {
identifier?: string;
password?: string;
};

if (!identifier || !password) {
return NextResponse.json(
Expand All @@ -16,7 +19,6 @@ export async function POST(request: Request) {
);
}

// Frontend-ready credentials handler
return NextResponse.json(
{
success: true,
Expand Down
39 changes: 39 additions & 0 deletions app/api/auth/signup/route.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { describe, expect, it } from 'vitest';
import { POST } from './route';

describe('POST /api/auth/signup', () => {
it('rejects incomplete signup payloads with 400', async () => {
const request = new Request('http://localhost/api/auth/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ fullName: 'Octo Cat' }),
});

const response = await POST(request);

expect(response.status).toBe(400);
const body = await response.json();
expect(body.error).toContain('required');
});

it('creates a success response body for a complete POST payload', async () => {
const request = new Request('http://localhost/api/auth/signup', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
fullName: 'Octo Cat',
email: 'octocat@example.com',
password: 'password123',
}),
});

const response = await POST(request);

expect(response.status).toBe(201);
const body = await response.json();
expect(body.success).toBe(true);
expect(body.message).toContain('Account created');
expect(body.user.fullName).toBe('Octo Cat');
expect(body.user.email).toBe('octocat@example.com');
});
});
9 changes: 6 additions & 3 deletions app/api/Auth/signup/route.ts → app/api/auth/signup/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ import { NextResponse } from 'next/server';
* Handles user registration requests for frontend signup.
* Integrates with production database user creation.
*/
export async function POST(request: Request) {
export async function POST(request: Request): Promise<Response> {
try {
const body = await request.json();
const { fullName, email, password } = body;
const { fullName, email, password } = body as {
fullName?: string;
email?: string;
password?: string;
};

if (!fullName || !email || !password) {
return NextResponse.json(
Expand All @@ -16,7 +20,6 @@ export async function POST(request: Request) {
);
}

// Frontend-ready registration handler
return NextResponse.json(
{
success: true,
Expand Down
2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export const config = {
'/api/languages/:path*',
'/api/org/:path*',
'/api/spotify/:path*',
'/api/Auth/:path*',
'/api/auth/:path*',
'/api/achievements/:path*',
'/api/ci-analytics/:path*',
'/api/cicd/:path*',
Expand Down
Loading
Loading