test(auth): tighten R25 + sign-in controller assertions per code review
Code-quality reviewer flagged:
- R25 'malformed output' tests used .rejects.toThrow(/parse|invalid/i)
which could match unrelated errors. Replaced with
.rejects.toBeInstanceOf(ZodError) for both sign-in and sign-up.
- sign-in controller test asserted result.name only as truthy; the
parallel sign-up test was already precise (toBe('session')). Tightened
to match.
61 tests still passing for @repo/auth.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { ZodError } from "zod";
|
||||||
import { signInUseCase, signInOutputSchema } from "@/application/use-cases/sign-in.use-case";
|
import { signInUseCase, signInOutputSchema } from "@/application/use-cases/sign-in.use-case";
|
||||||
import { MockUsersRepository } from "@/infrastructure/repositories/users.repository.mock";
|
import { MockUsersRepository } from "@/infrastructure/repositories/users.repository.mock";
|
||||||
import { MockAuthenticationService } from "@/infrastructure/services/authentication.service.mock";
|
import { MockAuthenticationService } from "@/infrastructure/services/authentication.service.mock";
|
||||||
@@ -60,7 +61,7 @@ describe("signInUseCase output validation (R25)", () => {
|
|||||||
} as unknown as IAuthenticationService;
|
} as unknown as IAuthenticationService;
|
||||||
|
|
||||||
const useCase = signInUseCase(users, auth);
|
const useCase = signInUseCase(users, auth);
|
||||||
await expect(useCase({ username: "alice", password: "x" })).rejects.toThrow(/parse|invalid/i);
|
await expect(useCase({ username: "alice", password: "x" })).rejects.toBeInstanceOf(ZodError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("exports an output schema that mirrors the success shape", () => {
|
it("exports an output schema that mirrors the success shape", () => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { describe, it, expect } from "vitest";
|
import { describe, it, expect } from "vitest";
|
||||||
|
import { ZodError } from "zod";
|
||||||
import { signUpUseCase, signUpOutputSchema } from "@/application/use-cases/sign-up.use-case";
|
import { signUpUseCase, signUpOutputSchema } from "@/application/use-cases/sign-up.use-case";
|
||||||
import { MockUsersRepository } from "@/infrastructure/repositories/users.repository.mock";
|
import { MockUsersRepository } from "@/infrastructure/repositories/users.repository.mock";
|
||||||
import { MockAuthenticationService } from "@/infrastructure/services/authentication.service.mock";
|
import { MockAuthenticationService } from "@/infrastructure/services/authentication.service.mock";
|
||||||
@@ -48,7 +49,7 @@ describe("signUpUseCase output validation (R25)", () => {
|
|||||||
const useCase = signUpUseCase(users, auth);
|
const useCase = signUpUseCase(users, auth);
|
||||||
await expect(
|
await expect(
|
||||||
useCase({ username: "carol", password: "secret_password", confirmPassword: "secret_password" }),
|
useCase({ username: "carol", password: "secret_password", confirmPassword: "secret_password" }),
|
||||||
).rejects.toThrow(/parse|invalid/i);
|
).rejects.toBeInstanceOf(ZodError);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("exports an output schema that mirrors the success shape", () => {
|
it("exports an output schema that mirrors the success shape", () => {
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ describe("signInController", () => {
|
|||||||
username: "alice",
|
username: "alice",
|
||||||
password: "testpassword",
|
password: "testpassword",
|
||||||
});
|
});
|
||||||
expect(result).toBeDefined();
|
expect(result.name).toBe("session");
|
||||||
expect(result.name).toBeTruthy();
|
|
||||||
expect(result.value).toBeTruthy();
|
expect(result.value).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user