Adds ConsentFactoryProtocol / ConsentGrantMeta / ConsentProtocol to core-shared/di/bind-protocols so feature binders can wire per-user consent without a hard dep on the optional @repo/core-consent package. BindContext gains an optional consentFactory? field following the same pattern as bus?, auditLog?, etc. signUpUseCase gains a 4th optional dep (consentFactory). When present and the input includes a cookieHeader containing cc_consent=<categories>, the use case calls consent.grant for each category with method:"signup-migration" and returns a clearCookie payload (Max-Age:0) so the anonymous cookie is cleared on the HTTP response. Tests use RecordingConsent from @repo/core-testing to assert migration call shape and cookie-clear; no-cookie and no-factory branches are also covered. All coverage bands hold at 100% for use-cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
2.2 KiB
TypeScript
48 lines
2.2 KiB
TypeScript
// Feature-level test: sign-up, then sign-in with the new credentials, then sign-out.
|
|
// Constructs the full chain via direct injection (no container rebinding).
|
|
|
|
import { describe, it, expect } from "vitest";
|
|
import { RecordingEventBus } from "@repo/core-testing/instrumentation";
|
|
import { MockUsersRepository } from "../src/infrastructure/repositories/users.repository.mock";
|
|
import { MockAuthenticationService } from "../src/infrastructure/services/authentication.service.mock";
|
|
import { signInUseCase } from "../src/application/use-cases/sign-in.use-case";
|
|
import { signUpUseCase } from "../src/application/use-cases/sign-up.use-case";
|
|
import { signOutUseCase } from "../src/application/use-cases/sign-out.use-case";
|
|
import { signInController } from "../src/interface-adapters/controllers/sign-in.controller";
|
|
import { signUpController } from "../src/interface-adapters/controllers/sign-up.controller";
|
|
import { signOutController } from "../src/interface-adapters/controllers/sign-out.controller";
|
|
|
|
describe("auth feature: sign-up → sign-in → sign-out", () => {
|
|
it("a new user can sign up, then sign in, then sign out", async () => {
|
|
// Construct the full chain via direct injection
|
|
const users = new MockUsersRepository([]);
|
|
const auth = new MockAuthenticationService(users);
|
|
|
|
const signIn = signInController(signInUseCase(users, auth));
|
|
const signUp = signUpController(
|
|
signUpUseCase(users, auth, new RecordingEventBus(), undefined),
|
|
);
|
|
const signOut = signOutController(signOutUseCase(auth));
|
|
|
|
// signUp returns a cookie (presenter shape)
|
|
const signUpCookie = await signUp({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
confirmPassword: "verysecret",
|
|
});
|
|
expect(signUpCookie.name).toBe("session");
|
|
expect(signUpCookie.value).toBeTruthy();
|
|
|
|
const signInCookie = await signIn({
|
|
username: "newperson",
|
|
password: "verysecret",
|
|
});
|
|
expect(signInCookie.name).toBe("session");
|
|
expect(signInCookie.value).toBeTruthy();
|
|
|
|
// signOut takes { sessionId } and returns void
|
|
const signOutResult = await signOut({ sessionId: signInCookie.value });
|
|
expect(signOutResult).toBeUndefined();
|
|
});
|
|
});
|