Assist_Design/apps/bff/test/catalog-contract.spec.ts
barsa 6567bc5907 Enhance TypeScript configurations and improve error handling in services
- Updated tsconfig.json to include test files for better type checking.
- Refined type annotations in FreebitAuthService for improved clarity and type safety.
- Enhanced currency index extraction logic in WhmcsCurrencyService for better type inference.
- Improved utility functions in whmcs-client.utils.ts to handle various value types more robustly.
- Simplified user creation logic in WhmcsLinkWorkflowService by removing unnecessary type conversions.
- Updated RequestWithCookies type in auth.controller.ts and global-auth.guard.ts to allow optional cookies.
- Refactored OrderFulfillmentOrchestrator to utilize a more specific mapping result type for better type safety.
- Added error logging enhancements in UsersService for improved traceability.
- Updated catalog contract tests to ensure response validation aligns with new schemas.
- Improved InvoiceTable component to handle payment and download actions more cleanly.
2025-10-22 10:23:56 +09:00

51 lines
1.6 KiB
TypeScript

/// <reference types="jest" />
import request from "supertest";
import type { INestApplication } from "@nestjs/common";
import { Test } from "@nestjs/testing";
import type { Server } from "node:http";
import { AppModule } from "../src/app.module";
import {
parseInternetCatalog,
internetCatalogResponseSchema,
} from "@customer-portal/domain/catalog";
import { apiSuccessResponseSchema } from "@customer-portal/domain/common/schema";
const internetCatalogApiResponseSchema = apiSuccessResponseSchema(internetCatalogResponseSchema);
const isRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === "object" && value !== null;
const isHttpServer = (value: unknown): value is Server =>
isRecord(value) && typeof value.listen === "function" && typeof value.close === "function";
describe("Catalog contract", () => {
let app: INestApplication;
beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [AppModule],
}).compile();
app = moduleRef.createNestApplication();
await app.init();
});
afterAll(async () => {
await app.close();
});
it("should return internet catalog matching domain schema", async () => {
const serverCandidate: unknown = app.getHttpServer();
if (!isHttpServer(serverCandidate)) {
throw new Error("Expected Nest application to expose an HTTP server");
}
const response = await request(serverCandidate).get("/catalog/internet/plans");
expect(response.status).toBe(200);
const payload = internetCatalogApiResponseSchema.parse(response.body);
expect(() => parseInternetCatalog(payload.data)).not.toThrow();
});
});