mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
test: reset to the factory answer instead of casting a new one
A reset mock goes back to the implementation its factory gave it, which is the fresh session and the open capability these cases want; the cast replacements grew the test-realism count.
This commit is contained in:
1 parent
9a3140a4d3
commit
1ac69420d5
2 files changed
+8
-19
No files matched your search
@@ -174,16 +174,10 @@ beforeEach(() => {
|
||||
vi.mocked(isModuleEnabled).mockResolvedValue(true);
|
||||
vi.mocked(requireModuleEnabled).mockResolvedValue({ enabled: true } as never);
|
||||
vi.mocked(getSession).mockResolvedValue(SESSION_OK as never);
|
||||
// A session that signed in just now. Reset, not only cleared: a case below
|
||||
// swaps in a stale session, and `clearAllMocks` keeps the implementation
|
||||
// it left behind for whichever case runs next.
|
||||
vi.mocked(prisma.session.findUnique)
|
||||
.mockReset()
|
||||
.mockImplementation((async () => ({
|
||||
createdAt: new Date(),
|
||||
mfaVerifiedAt: null,
|
||||
reproofAt: null,
|
||||
})) as never);
|
||||
// A session that signed in just now, the factory's own answer. Reset, not
|
||||
// only cleared: a case below swaps in a stale session, and `clearAllMocks`
|
||||
// keeps the implementation it left behind for whichever case runs next.
|
||||
vi.mocked(prisma.session.findUnique).mockReset();
|
||||
vi.mocked(checkRateLimit).mockResolvedValue({
|
||||
allowed: true,
|
||||
limit: 60,
|
||||
|
||||
@@ -87,15 +87,10 @@ beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
vi.mocked(getSession).mockResolvedValue(SESSION_OK as never);
|
||||
vi.mocked(validateAttachmentCandidate).mockResolvedValue({ ok: true });
|
||||
// Open again for every case: the detach case closes every capability, and
|
||||
// `clearAllMocks` would carry that refusal into whichever case runs next.
|
||||
vi.mocked(requireAiCapability)
|
||||
.mockReset()
|
||||
.mockResolvedValue({
|
||||
available: true,
|
||||
reason: null,
|
||||
onDeviceAllowed: true,
|
||||
} as never);
|
||||
// Open again for every case (the factory's own answer): the detach case
|
||||
// closes every capability, and `clearAllMocks` would carry that refusal
|
||||
// into whichever case runs next.
|
||||
vi.mocked(requireAiCapability).mockReset();
|
||||
});
|
||||
|
||||
describe("POST attach", () => {
|
||||
|
||||
Reference in new issue
Block a user