@elevasis/core 0.8.0 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,150 +1,42 @@
1
- # Test Utilities
2
-
3
- Shared test utilities for Elevasis monorepo testing. Provides fixtures, mocks, and test helpers following DRY principles.
4
-
5
- ## Structure
6
-
7
- ```
8
- test-utils/
9
- ├── fixtures/ # Test data using real Supabase types
10
- │ ├── users.ts # User fixtures (SupabaseUserProfile)
11
- │ ├── organizations.ts
12
- │ ├── memberships.ts
13
- │ └── api-keys.ts
14
- ├── mocks/ # Mock implementations
15
- │ ├── supabase.ts # Supabase client mock
16
- │ └── workos.ts # WorkOS JWT mock
17
- └── index.ts # Re-exports all utilities
18
- ```
19
-
20
- ## Fixtures
21
-
22
- All fixtures use actual Supabase types from `@elevasis/core/supabase` for type safety.
23
-
24
- ### User Fixtures
25
-
26
- ```typescript
27
- import { TEST_USERS, createTestUser } from '@elevasis/core/test-utils'
28
-
29
- // Pre-defined users
30
- TEST_USERS.admin // Platform admin user
31
- TEST_USERS.regularUser // Regular user with membership
32
- TEST_USERS.inactiveUser // Inactive user
33
-
34
- // Create custom user
35
- const customUser = createTestUser({
36
- email: 'custom@example.com',
37
- is_platform_admin: true
38
- })
39
- ```
40
-
41
- ### Organization Fixtures
42
-
43
- ```typescript
44
- import { TEST_ORGS, createTestOrg } from '@elevasis/core/test-utils'
45
-
46
- TEST_ORGS.acme // Acme Corp (active, test org)
47
- TEST_ORGS.beta // Beta Inc (active, test org)
48
- TEST_ORGS.gamma // Gamma LLC (active, test org)
49
- TEST_ORGS.inactive // Inactive Org
50
- ```
51
-
52
- ### Membership Fixtures
53
-
54
- ```typescript
55
- import { TEST_MEMBERSHIPS, TEST_MEMBERSHIPS_WITH_ORG } from '@elevasis/core/test-utils'
56
-
57
- // Simple memberships
58
- TEST_MEMBERSHIPS.regularUserAcme // regularUser admin in Acme
59
- TEST_MEMBERSHIPS.regularUserBeta // regularUser member in Beta
60
-
61
- // Memberships with organization data (for joined queries)
62
- TEST_MEMBERSHIPS_WITH_ORG.regularUserAcme
63
- ```
64
-
65
- ### API Key Fixtures
66
-
67
- ```typescript
68
- import { TEST_API_KEYS, TEST_API_KEY_PLAINTEXTS } from '@elevasis/core/test-utils'
69
-
70
- // API key records (with hashed keys)
71
- TEST_API_KEYS.acmeKey
72
- TEST_API_KEYS.betaKey
73
-
74
- // Plaintext keys for Authorization headers
75
- TEST_API_KEY_PLAINTEXTS.acmeKey // 'sk_test_acme_12345'
76
- ```
77
-
78
- ## Mocks
79
-
80
- ### Supabase Client Mock
81
-
82
- ```typescript
83
- import { createMockSupabaseClient, TEST_USERS, TEST_ORGS } from '@elevasis/core/test-utils'
84
- import { vi } from 'vitest'
85
-
86
- // Create mock with test data
87
- const mockClient = createMockSupabaseClient({
88
- users: [TEST_USERS.admin, TEST_USERS.regularUser],
89
- organizations: [TEST_ORGS.acme, TEST_ORGS.beta]
90
- })
91
-
92
- // Use in tests
93
- vi.mock('../lib/supabase', () => ({ supabaseClient: mockClient }))
94
-
95
- // Query will work with mock data
96
- const { data } = await supabaseClient
97
- .from('users')
98
- .select('*')
99
- .eq('email', 'admin@test.com')
100
- .single()
101
- // data === TEST_USERS.admin
102
- ```
103
-
104
- ### WorkOS JWT Mock
105
-
106
- ```typescript
107
- import { createMockVerifyJWT, mockExtractToken, TEST_USERS } from '@elevasis/core/test-utils'
108
- import { vi } from 'vitest'
109
-
110
- const mockVerifyJWT = createMockVerifyJWT({
111
- 'valid-token': {
112
- workosId: TEST_USERS.admin.workos_user_id,
113
- supabaseId: TEST_USERS.admin.id,
114
- email: TEST_USERS.admin.email
115
- }
116
- })
117
-
118
- vi.mock('../identity/auth/jwt-verifier', () => ({
119
- verifyJWT: mockVerifyJWT,
120
- extractToken: mockExtractToken
121
- }))
122
-
123
- // JWT verification will return mock user
124
- const user = await verifyJWT('valid-token')
125
- // user.email === 'admin@test.com'
126
- ```
127
-
128
- ## Usage in Apps
129
-
130
- Apps can import test utilities directly:
131
-
132
- ```typescript
133
- // In apps/api/src/test-utils/index.ts
134
- export * from '@elevasis/core/test-utils' // Re-export shared utilities
135
- export * from './fastify-test' // Add app-specific utilities
136
- ```
137
-
138
- ## Type Safety
139
-
140
- All fixtures use actual Supabase types:
141
- - Changes to database schema automatically update test types
142
- - TypeScript compiler validates test data structure
143
- - Single source of truth for types
144
-
145
- ## Design Principles
146
-
147
- - **DRY:** Shared fixtures in `@elevasis/core`, imported by apps
148
- - **Type Safety:** Use `SupabaseUserProfile`, `SupabaseOrganization`, etc.
149
- - **Realistic Data:** Fixtures match production schema and patterns
150
- - **Composable:** Combine fixtures, mocks, and helpers as needed
1
+ # Test Utilities
2
+
3
+ Published test helpers for downstream consumers of `@elevasis/core`.
4
+
5
+ The public `@elevasis/core/test-utils` subpath is intentionally narrow. It exposes:
6
+
7
+ - `RLSTestContext` for dev-database RLS integration tests
8
+ - `setupMatchMedia`, `setupResizeObserver`, and `setupBrowserMocks` for jsdom/browser test setup
9
+
10
+ Internal monorepo fixtures and Vitest-specific mocks still exist under `packages/core/src/test-utils/`, but they are not part of the published package contract.
11
+
12
+ ## Published Usage
13
+
14
+ ### Browser Mocks
15
+
16
+ ```typescript
17
+ import { setupBrowserMocks } from '@elevasis/core/test-utils'
18
+
19
+ setupBrowserMocks()
20
+ ```
21
+
22
+ ### RLS Integration Tests
23
+
24
+ ```typescript
25
+ import { RLSTestContext } from '@elevasis/core/test-utils'
26
+
27
+ const ctx = new RLSTestContext()
28
+ ```
29
+
30
+ `RLSTestContext` requires a configured Supabase development environment:
31
+
32
+ - `SUPABASE_URL`
33
+ - `SUPABASE_ANON_KEY`
34
+ - `SUPABASE_SERVICE_KEY`
35
+ - `SUPABASE_JWT_SECRET`
36
+
37
+ ## Internal Scope
38
+
39
+ The following folders remain implementation detail for the monorepo and are not published:
40
+
41
+ - `fixtures/`
42
+ - `mocks/`
@@ -1,11 +1,10 @@
1
- // Fixtures
2
- export * from './fixtures'
3
-
4
- // Mocks
5
- export * from './mocks'
6
-
7
- // RLS Testing
8
- export * from './rls'
9
-
10
- // Browser Mocks (for React/UI testing)
11
- export * from './browser-mocks'
1
+ // Published test utilities are intentionally narrow.
2
+ // Internal fixtures and Vitest-heavy mocks stay private to the monorepo.
3
+ export * from './rls'
4
+
5
+ export * from './browser-mocks'
6
+
7
+ // Monorepo-only compatibility surface for internal test helpers.
8
+ // publishConfig.exports keeps these out of the public @elevasis/core package.
9
+ export * from './fixtures'
10
+ export * from './mocks'
@@ -0,0 +1,4 @@
1
+ // Published test utilities are intentionally narrow.
2
+ // Internal fixtures and Vitest-heavy mocks remain monorepo-only.
3
+ export * from './rls'
4
+ export * from './browser-mocks'
@@ -19,9 +19,9 @@
19
19
  * ```
20
20
  */
21
21
 
22
- import { createClient, SupabaseClient } from '@supabase/supabase-js'
23
- import jwt from 'jsonwebtoken'
24
- import type { Database } from '@repo/core'
22
+ import { createClient, SupabaseClient } from '@supabase/supabase-js'
23
+ import jwt from 'jsonwebtoken'
24
+ import type { Database } from '../../supabase/database.types'
25
25
 
26
26
  type Role = 'admin' | 'member'
27
27