| 12 | * Use this for REST API integration tests. |
| 13 | */ |
| 14 | export function createTestApp(options: TestAppOptions = {}) { |
| 15 | const { teamId = "test-team-id", userId = "test-user-id" } = options; |
| 16 | |
| 17 | const app = new OpenAPIHono<Context>(); |
| 18 | |
| 19 | // Mock auth middleware - inject test team/user IDs |
| 20 | app.use( |
| 21 | "*", |
| 22 | createMiddleware<Context>(async (c, next) => { |
| 23 | c.set("teamId", teamId); |
| 24 | c.set("session", { |
| 25 | user: { |
| 26 | id: userId, |
| 27 | email: "test@example.com", |
| 28 | }, |
| 29 | }); |
| 30 | c.set("db", {} as Context["Variables"]["db"]); // Mock DB instance - actual queries are mocked at module level |
| 31 | // Set all scopes for testing (grants full access) |
| 32 | c.set("scopes", [ |
| 33 | "transactions.read", |
| 34 | "transactions.write", |
| 35 | "invoices.read", |
| 36 | "invoices.write", |
| 37 | "customers.read", |
| 38 | "customers.write", |
| 39 | "bank_accounts.read", |
| 40 | "bank_accounts.write", |
| 41 | ] as Context["Variables"]["scopes"]); |
| 42 | await next(); |
| 43 | }), |
| 44 | ); |
| 45 | |
| 46 | return app; |
| 47 | } |