Skip to content
Merged
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
75 changes: 0 additions & 75 deletions backend/src/__tests__/registration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ import express from "express";
import router from "../routes/registration";
import { pool } from ".."; // Assuming pool is exported from your index file

// Define types for the mock response data
interface MockClient {
query: Mock;
release: Mock;
begin: Mock;
commit: Mock;
rollback: Mock;
}

interface Registration {
user_id?: number;
license_number?: string;
Expand Down Expand Up @@ -170,70 +161,4 @@ describe("Registration API", () => {
});
});
});

describe("POST /approve", () => {
it("should return 400 if license number is not provided", async () => {
const response = await request(app).post("/approve").send({});

expect(response.status).toBe(400);
expect(response.body).toEqual({
title: "Validation Error",
message: "License number is required.",
});
});

it("should return 404 if registration not found", async () => {
const license_number = "12345678";
(pool.query as Mock).mockResolvedValueOnce({ rows: [] }); // No matching registration

const response = await request(app)
.post("/approve")
.send({ license_number });

expect(response.status).toBe(404);
expect(response.body).toEqual({
title: "Not Found",
message: "Registration with the specified license number not found.",
});
});

it("should approve the registration and update driver details", async () => {
const license_number = "12345678";
const mockRegistration: Registration = {
school_email: "[email protected]",
user_id: 1,
};
const mockDriver = { email: "", id: 1 };

// Mocking registration and driver fetch queries
(pool.query as Mock)
.mockResolvedValueOnce({ rows: [mockRegistration] }) // Mock registration fetch
.mockResolvedValueOnce({ rows: [mockDriver] }); // Mock driver fetch

// Mock pool.connect to return a mock client
const mockClient: MockClient = {
query: vi.fn().mockResolvedValueOnce({}), // Mocking successful query
release: vi.fn(),
begin: vi.fn().mockResolvedValueOnce({}),
commit: vi.fn().mockResolvedValueOnce({}),
rollback: vi.fn().mockResolvedValueOnce({}),
};
(pool.connect as Mock).mockResolvedValue(mockClient);

const response = await request(app)
.post("/approve")
.send({ license_number });

expect(response.status).toBe(200);
expect(response.body).toEqual({
title: "Driver Updated!",
message: "Driver's email and user_id have been updated successfully.",
});

expect(pool.query).toHaveBeenCalledTimes(3); // Expect 3 queries: registration, driver, deletion
expect(pool.connect).toHaveBeenCalledOnce();
expect(mockClient.begin).toHaveBeenCalledOnce(); // Ensure transaction start
expect(mockClient.commit).toHaveBeenCalledOnce(); // Ensure transaction commit
});
});
});
203 changes: 0 additions & 203 deletions backend/src/__tests__/violation.test.ts

This file was deleted.

Loading