style: run prettier on entire codebase
This commit is contained in:
@@ -1,47 +1,51 @@
|
||||
import { describe, it, expect, beforeAll, afterAll } from 'vitest';
|
||||
import { buildApp, extractCookie } from './helpers';
|
||||
import { describe, it, expect, beforeAll, afterAll } from "vitest";
|
||||
import { buildApp, extractCookie } from "./helpers";
|
||||
|
||||
let app: Awaited<ReturnType<typeof buildApp>>;
|
||||
|
||||
beforeAll(async () => { app = await buildApp(); });
|
||||
afterAll(async () => { await app.close(); });
|
||||
beforeAll(async () => {
|
||||
app = await buildApp();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
||||
describe('POST /api/admin/login', () => {
|
||||
it('returns 401 for invalid credentials', async () => {
|
||||
describe("POST /api/admin/login", () => {
|
||||
it("returns 401 for invalid credentials", async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/admin/login',
|
||||
payload: { username: 'nonexistent', password: 'wrong' },
|
||||
method: "POST",
|
||||
url: "/api/admin/login",
|
||||
payload: { username: "nonexistent", password: "wrong" },
|
||||
});
|
||||
expect(res.statusCode).toBe(401);
|
||||
expect(res.json().success).toBe(false);
|
||||
});
|
||||
|
||||
it('returns 400 for missing fields', async () => {
|
||||
it("returns 400 for missing fields", async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/admin/login',
|
||||
method: "POST",
|
||||
url: "/api/admin/login",
|
||||
payload: {},
|
||||
});
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/admin/refresh', () => {
|
||||
it('returns 401 without refresh token', async () => {
|
||||
describe("POST /api/admin/refresh", () => {
|
||||
it("returns 401 without refresh token", async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/admin/refresh',
|
||||
method: "POST",
|
||||
url: "/api/admin/refresh",
|
||||
});
|
||||
expect(res.statusCode).toBe(401);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/admin/logout', () => {
|
||||
it('clears refresh token cookie', async () => {
|
||||
describe("POST /api/admin/logout", () => {
|
||||
it("clears refresh token cookie", async () => {
|
||||
const res = await app.inject({
|
||||
method: 'POST',
|
||||
url: '/api/admin/logout',
|
||||
method: "POST",
|
||||
url: "/api/admin/logout",
|
||||
});
|
||||
expect(res.statusCode).toBeLessThan(500);
|
||||
});
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import Fastify from 'fastify';
|
||||
import cookie from '@fastify/cookie';
|
||||
import rateLimit from '@fastify/rate-limit';
|
||||
import authRoutes from '../routes/admin/auth';
|
||||
import totpRoutes from '../routes/admin/totp';
|
||||
import Fastify from "fastify";
|
||||
import cookie from "@fastify/cookie";
|
||||
import rateLimit from "@fastify/rate-limit";
|
||||
import authRoutes from "../routes/admin/auth";
|
||||
import totpRoutes from "../routes/admin/totp";
|
||||
|
||||
export async function buildApp() {
|
||||
const app = Fastify({ logger: false });
|
||||
await app.register(cookie);
|
||||
await app.register(rateLimit, { max: 1000, timeWindow: '1 minute' });
|
||||
await app.register(authRoutes, { prefix: '/api/admin' });
|
||||
await app.register(totpRoutes, { prefix: '/api/admin/totp' });
|
||||
await app.register(rateLimit, { max: 1000, timeWindow: "1 minute" });
|
||||
await app.register(authRoutes, { prefix: "/api/admin" });
|
||||
await app.register(totpRoutes, { prefix: "/api/admin/totp" });
|
||||
return app;
|
||||
}
|
||||
|
||||
export function extractCookie(response: any, name: string): string | undefined {
|
||||
const cookies = response.headers['set-cookie'];
|
||||
const cookies = response.headers["set-cookie"];
|
||||
if (!cookies) return undefined;
|
||||
const arr = Array.isArray(cookies) ? cookies : [cookies];
|
||||
for (const c of arr) {
|
||||
if (c.startsWith(`${name}=`)) {
|
||||
return c.split(';')[0].split('=')[1];
|
||||
return c.split(";")[0].split("=")[1];
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { generateSharedNumber, generateOfferNumber } from '../services/numbering.service';
|
||||
import { describe, it, expect } from "vitest";
|
||||
import {
|
||||
generateSharedNumber,
|
||||
generateOfferNumber,
|
||||
} from "../services/numbering.service";
|
||||
|
||||
describe('generateSharedNumber', () => {
|
||||
it('returns correct format (YYtypeCode + 4 digits)', async () => {
|
||||
describe("generateSharedNumber", () => {
|
||||
it("returns correct format (YYtypeCode + 4 digits)", async () => {
|
||||
const num = await generateSharedNumber();
|
||||
const yy = String(new Date().getFullYear()).slice(-2);
|
||||
expect(num).toMatch(new RegExp(`^${yy}\\d{2,}\\d{4}$`));
|
||||
});
|
||||
});
|
||||
|
||||
describe('generateOfferNumber', () => {
|
||||
it('returns correct format (YEAR/PREFIX/NNN)', async () => {
|
||||
describe("generateOfferNumber", () => {
|
||||
it("returns correct format (YEAR/PREFIX/NNN)", async () => {
|
||||
const num = await generateOfferNumber();
|
||||
const year = new Date().getFullYear();
|
||||
expect(num).toMatch(new RegExp(`^${year}/[A-Z]+/\\d{3,}$`));
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config({ path: '.env.test' });
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config({ path: ".env.test" });
|
||||
|
||||
Reference in New Issue
Block a user