Skip to content

Commit 0726ec1

Browse files
authored
Merge pull request #539 from gn-t-k/bugfix/A-1-authentication-testing-export
fix: @next-lift/authenticationのtestingエクスポートをモック関数に整備
2 parents b3bb922 + bad3c10 commit 0726ec1

File tree

6 files changed

+54
-23
lines changed

6 files changed

+54
-23
lines changed

docs/issues/A-1-authentication-testing-export.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

packages/authentication/CLAUDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Better Authを使った認証とPer-User DBクレデンシャル管理を担う
1616
| `./user-database-credentials` | Per-User DBクレデンシャルのCRUD、有効なクレデンシャル取得(期限切れ時自動更新) |
1717
| `./integrations/better-auth-nextjs` | Next.js向けBetter Auth統合 |
1818
| `./integrations/better-auth-react` | React/Expo向けBetter Auth統合 |
19+
| `./testing` | テスト用モック関数(saveUserDatabaseCredentials, getValidCredentials) |
1920

2021
## データベーススキーマ
2122

packages/authentication/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"./create-auth": "./src/features/instance/create-auth.ts",
88
"./user-database-credentials": "./src/features/user-database-credentials/index.ts",
99
"./integrations/better-auth-nextjs": "./src/features/integrations/better-auth-nextjs.ts",
10-
"./integrations/better-auth-react": "./src/features/integrations/better-auth-react.ts"
10+
"./integrations/better-auth-react": "./src/features/integrations/better-auth-react.ts",
11+
"./testing": "./src/testing/index.ts"
1112
},
1213
"scripts": {
1314
"lint": "biome check .",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { R } from "@praha/byethrow";
2+
import { vi } from "vitest";
3+
import type { GetValidCredentialsError } from "./get-valid-credentials";
4+
import * as module from "./get-valid-credentials";
5+
6+
export const mockGetValidCredentialsOk = (
7+
overrides?: Partial<R.InferSuccess<typeof module.getValidCredentials>>,
8+
) => {
9+
return vi.spyOn(module, "getValidCredentials").mockResolvedValue(
10+
R.succeed({
11+
dbName: "mock-per-user-db-name",
12+
url: "libsql://mock-per-user-db.turso.io",
13+
token: "mock-valid-token",
14+
expiresAt: new Date("2026-12-31T00:00:00.000Z"),
15+
...overrides,
16+
}),
17+
);
18+
};
19+
20+
export const mockGetValidCredentialsError = (
21+
error: GetValidCredentialsError,
22+
) => {
23+
return vi
24+
.spyOn(module, "getValidCredentials")
25+
.mockResolvedValue(R.fail(error));
26+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { R } from "@praha/byethrow";
2+
import { vi } from "vitest";
3+
import * as module from "./save-user-database-credentials";
4+
5+
export const mockSaveUserDatabaseCredentialsOk = () => {
6+
return vi
7+
.spyOn(module, "saveUserDatabaseCredentials")
8+
.mockResolvedValue(R.succeed(undefined));
9+
};
10+
11+
export const mockSaveUserDatabaseCredentialsError = (
12+
error: module.SaveUserDatabaseCredentialsError | module.EncryptTokenError,
13+
) => {
14+
return vi
15+
.spyOn(module, "saveUserDatabaseCredentials")
16+
.mockResolvedValue(R.fail(error));
17+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export {
2+
mockGetValidCredentialsError,
3+
mockGetValidCredentialsOk,
4+
} from "../features/user-database-credentials/get-valid-credentials.mock.js";
5+
export {
6+
mockSaveUserDatabaseCredentialsError,
7+
mockSaveUserDatabaseCredentialsOk,
8+
} from "../features/user-database-credentials/save-user-database-credentials.mock.js";

0 commit comments

Comments
 (0)