test(helpers): add db, fetch, app, and auth test helpers
withTestDb sets up an in-memory SQLite handle with migrations applied, swaps the production singleton via _setDbForTest, and restores in a finally block. installFetchStub captures every outbound request and throws if restored twice. requestApp wraps Oak's app.handle so route tests can run without listen(). stubAuthenticate flips the server's authenticator indirection.
This commit is contained in:
18
tests/_helpers/auth.ts
Normal file
18
tests/_helpers/auth.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
_resetAuthenticatorForTest,
|
||||
_setAuthenticatorForTest,
|
||||
} from "../../server.ts";
|
||||
|
||||
export type AuthStub = { restore: () => void };
|
||||
|
||||
export const stubAuthenticate = (didOrError: string | Error): AuthStub => {
|
||||
_setAuthenticatorForTest(() => {
|
||||
if (didOrError instanceof Error) {
|
||||
return Promise.reject(didOrError);
|
||||
}
|
||||
return Promise.resolve(didOrError);
|
||||
});
|
||||
return {
|
||||
restore: () => _resetAuthenticatorForTest(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user