-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathauth.controller.spec.ts
More file actions
34 lines (32 loc) · 1.15 KB
/
Copy pathauth.controller.spec.ts
File metadata and controls
34 lines (32 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { AuthController } from "./auth.controller";
import { AuthService } from "./auth.service";
import { AuthenticatedSession } from "./auth.types";
import { SessionService } from "./session.service";
describe("AuthController", () => {
it("rotates the authenticated session and returns a bearer token", async () => {
const authService = {} as AuthService;
const expiresAt = new Date("2030-01-01T00:00:00.000Z");
const sessionService = {
rotate: jest.fn().mockResolvedValue({
token: "new-session.token",
sessionId: "new-session",
expiresAt,
}),
} as unknown as SessionService;
const controller = new AuthController(authService, sessionService);
const session: AuthenticatedSession = {
sessionId: "old-session",
id: "user-1",
walletAddress: "G".padEnd(56, "A"),
walletHash: "sha256:wallet",
role: "WORKER",
};
await expect(controller.rotate(session)).resolves.toEqual({
token: "new-session.token",
tokenType: "Bearer",
sessionId: "new-session",
expiresAt,
});
expect(sessionService.rotate).toHaveBeenCalledWith("old-session", session);
});
});