@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.
- package/dist/test-utils/index.d.ts +3122 -0
- package/dist/test-utils/index.js +386 -0
- package/package.json +6 -1
- package/src/README.md +14 -11
- package/src/__tests__/publish.test.ts +11 -6
- package/src/_gen/__tests__/__snapshots__/contracts.md.snap +530 -529
- package/src/_gen/__tests__/scaffold-contracts.test.ts +30 -19
- package/src/business/acquisition/api-schemas.ts +167 -72
- package/src/commands/queue/types/task.ts +15 -10
- package/src/execution/core/sse-executions.ts +7 -3
- package/src/execution/engine/tools/lead-service-types.ts +6 -5
- package/src/execution/engine/tools/tool-maps.ts +14 -6
- package/src/platform/registry/stats-types.ts +8 -6
- package/src/reference/_generated/contracts.md +2 -1
- package/src/test-utils/README.md +42 -150
- package/src/test-utils/index.ts +10 -11
- package/src/test-utils/published.ts +4 -0
- package/src/test-utils/rls/RLSTestContext.ts +3 -3
package/src/test-utils/README.md
CHANGED
|
@@ -1,150 +1,42 @@
|
|
|
1
|
-
# Test Utilities
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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/`
|
package/src/test-utils/index.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export * from './mocks'
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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'
|
|
@@ -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 '
|
|
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
|
|