import { INestApplication } from "@nestjs/common"; import { BASIC_ME_QUERY, HEALTH_QUERY, HELLO_QUERY, INTROSPECTION_QUERY, } from "./queries/load-queries"; import { makeUnauthenticatedRequest, setupTestApp } from "./test-utils"; describe("App Integration Tests (e2e)", () => { let app: INestApplication; beforeAll(async () => { app = await setupTestApp(); }); afterAll(async () => { await app.close(); }); describe("App Queries", () => { it("should return hello message", async () => { const response = await makeUnauthenticatedRequest(app) .send({ query: HELLO_QUERY, }) .expect(200); expect(response.body.data.hello).toBeDefined(); expect(typeof response.body.data.hello).toBe("string"); }); it("should return health status", async () => { const response = await makeUnauthenticatedRequest(app) .send({ query: HEALTH_QUERY, }) .expect(200); expect(response.body.data.health).toBeDefined(); expect(response.body.data.health.status).toBe("ok"); expect(response.body.data.health.timestamp).toBeDefined(); expect(response.body.data.health.timezone).toBeDefined(); expect(response.body.data.health.uptime).toBeDefined(); expect(typeof response.body.data.health.uptime).toBe("number"); }); }); describe("GraphQL Schema Validation", () => { it("should return introspection query results", async () => { const response = await makeUnauthenticatedRequest(app) .send({ query: INTROSPECTION_QUERY, }) .expect(200); expect(response.body.data.__schema).toBeDefined(); expect(response.body.data.__schema.queryType).toBeDefined(); expect(response.body.data.__schema.mutationType).toBeDefined(); }); }); describe("Error Handling", () => { it("should return error for invalid token", async () => { const response = await makeUnauthenticatedRequest(app) .set("Authorization", "Bearer invalid-token") .send({ query: BASIC_ME_QUERY, }) .expect(200); expect(response.body.errors).toBeDefined(); expect(response.body.errors[0].message).toContain("Invalid token"); }); it("should return error for missing authorization header", async () => { const response = await makeUnauthenticatedRequest(app) .send({ query: BASIC_ME_QUERY, }) .expect(200); expect(response.body.errors).toBeDefined(); expect(response.body.errors[0].message).toContain("No token provided"); }); }); });