@elevasis/core 0.8.3 → 0.10.0
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 +643 -316
- package/dist/test-utils/index.js +20736 -2
- package/package.json +1 -1
- package/src/business/projects/types.ts +1 -1
- package/src/execution/engine/tools/integration/server/adapters/google-sheets/__tests__/google-sheets.integration.test.ts +261 -261
- package/src/platform/constants/versions.ts +1 -1
- package/src/projects/api-schemas.test.ts +39 -0
- package/src/projects/api-schemas.ts +1 -1
- package/src/test-utils/README.md +5 -10
- package/src/test-utils/entities.ts +108 -0
- package/src/test-utils/index.ts +2 -0
- package/src/test-utils/organization-model.ts +65 -0
- package/src/test-utils/published.ts +4 -2
- package/src/test-utils/test-utils.test.ts +49 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { z } from 'zod'
|
|
2
|
+
import {
|
|
3
|
+
BaseCompanySchema,
|
|
4
|
+
BaseContactSchema,
|
|
5
|
+
BaseDealSchema,
|
|
6
|
+
BaseMilestoneSchema,
|
|
7
|
+
BaseProjectSchema,
|
|
8
|
+
BaseTaskSchema
|
|
9
|
+
} from '../business/base-entities'
|
|
10
|
+
|
|
11
|
+
type BaseProjectFixture = z.infer<typeof BaseProjectSchema>
|
|
12
|
+
type BaseDealFixture = z.infer<typeof BaseDealSchema>
|
|
13
|
+
type BaseCompanyFixture = z.infer<typeof BaseCompanySchema>
|
|
14
|
+
type BaseContactFixture = z.infer<typeof BaseContactSchema>
|
|
15
|
+
type BaseMilestoneFixture = z.infer<typeof BaseMilestoneSchema>
|
|
16
|
+
type BaseTaskFixture = z.infer<typeof BaseTaskSchema>
|
|
17
|
+
|
|
18
|
+
const DEFAULT_ORGANIZATION_ID = '00000000-0000-0000-0000-000000000010'
|
|
19
|
+
const DEFAULT_PROJECT_ID = '00000000-0000-0000-0000-000000000100'
|
|
20
|
+
const DEFAULT_TIMESTAMP = '2025-01-01T00:00:00Z'
|
|
21
|
+
|
|
22
|
+
export function makeProject(overrides: Partial<BaseProjectFixture> = {}): BaseProjectFixture {
|
|
23
|
+
return BaseProjectSchema.parse({
|
|
24
|
+
id: DEFAULT_PROJECT_ID,
|
|
25
|
+
organizationId: DEFAULT_ORGANIZATION_ID,
|
|
26
|
+
name: 'Test Project',
|
|
27
|
+
kind: 'client-delivery',
|
|
28
|
+
status: 'active',
|
|
29
|
+
description: 'A test project',
|
|
30
|
+
metadata: {},
|
|
31
|
+
createdAt: DEFAULT_TIMESTAMP,
|
|
32
|
+
updatedAt: DEFAULT_TIMESTAMP,
|
|
33
|
+
...overrides
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function makeDeal(overrides: Partial<BaseDealFixture> = {}): BaseDealFixture {
|
|
38
|
+
return BaseDealSchema.parse({
|
|
39
|
+
id: '00000000-0000-0000-0000-000000000200',
|
|
40
|
+
organizationId: DEFAULT_ORGANIZATION_ID,
|
|
41
|
+
contactEmail: 'buyer@test.com',
|
|
42
|
+
stage: 'qualified',
|
|
43
|
+
metadata: {},
|
|
44
|
+
createdAt: DEFAULT_TIMESTAMP,
|
|
45
|
+
updatedAt: DEFAULT_TIMESTAMP,
|
|
46
|
+
...overrides
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function makeCompany(overrides: Partial<BaseCompanyFixture> = {}): BaseCompanyFixture {
|
|
51
|
+
return BaseCompanySchema.parse({
|
|
52
|
+
id: '00000000-0000-0000-0000-000000000300',
|
|
53
|
+
organizationId: DEFAULT_ORGANIZATION_ID,
|
|
54
|
+
name: 'Test Company',
|
|
55
|
+
domain: 'test.example',
|
|
56
|
+
status: 'active',
|
|
57
|
+
metadata: {},
|
|
58
|
+
createdAt: DEFAULT_TIMESTAMP,
|
|
59
|
+
updatedAt: DEFAULT_TIMESTAMP,
|
|
60
|
+
...overrides
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function makeContact(overrides: Partial<BaseContactFixture> = {}): BaseContactFixture {
|
|
65
|
+
return BaseContactSchema.parse({
|
|
66
|
+
id: '00000000-0000-0000-0000-000000000400',
|
|
67
|
+
organizationId: DEFAULT_ORGANIZATION_ID,
|
|
68
|
+
email: 'contact@test.com',
|
|
69
|
+
firstName: 'Test',
|
|
70
|
+
lastName: 'Contact',
|
|
71
|
+
status: 'active',
|
|
72
|
+
metadata: {},
|
|
73
|
+
createdAt: DEFAULT_TIMESTAMP,
|
|
74
|
+
updatedAt: DEFAULT_TIMESTAMP,
|
|
75
|
+
...overrides
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function makeMilestone(overrides: Partial<BaseMilestoneFixture> = {}): BaseMilestoneFixture {
|
|
80
|
+
return BaseMilestoneSchema.parse({
|
|
81
|
+
id: '00000000-0000-0000-0000-000000000500',
|
|
82
|
+
organizationId: DEFAULT_ORGANIZATION_ID,
|
|
83
|
+
projectId: DEFAULT_PROJECT_ID,
|
|
84
|
+
name: 'Test Milestone',
|
|
85
|
+
status: 'not-started',
|
|
86
|
+
description: 'A test milestone',
|
|
87
|
+
metadata: {},
|
|
88
|
+
createdAt: DEFAULT_TIMESTAMP,
|
|
89
|
+
updatedAt: DEFAULT_TIMESTAMP,
|
|
90
|
+
...overrides
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function makeTask(overrides: Partial<BaseTaskFixture> = {}): BaseTaskFixture {
|
|
95
|
+
return BaseTaskSchema.parse({
|
|
96
|
+
id: '00000000-0000-0000-0000-000000000600',
|
|
97
|
+
organizationId: DEFAULT_ORGANIZATION_ID,
|
|
98
|
+
projectId: DEFAULT_PROJECT_ID,
|
|
99
|
+
name: 'Test Task',
|
|
100
|
+
status: 'todo',
|
|
101
|
+
type: 'general',
|
|
102
|
+
description: 'A test task',
|
|
103
|
+
metadata: {},
|
|
104
|
+
createdAt: DEFAULT_TIMESTAMP,
|
|
105
|
+
updatedAt: DEFAULT_TIMESTAMP,
|
|
106
|
+
...overrides
|
|
107
|
+
})
|
|
108
|
+
}
|
package/src/test-utils/index.ts
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { DeepPartial, OrganizationModel } from '../organization-model/published'
|
|
2
|
+
import { OrganizationModelSchema, resolveOrganizationModel } from '../organization-model/published'
|
|
3
|
+
import type { SupabaseUserProfile } from '../supabase'
|
|
4
|
+
import { createTestUser } from './fixtures'
|
|
5
|
+
|
|
6
|
+
export interface TestInitializationError {
|
|
7
|
+
layer: 'auth' | 'profile' | 'organization'
|
|
8
|
+
message: string
|
|
9
|
+
originalError?: Error
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface TestInitializationState {
|
|
13
|
+
userReady: boolean
|
|
14
|
+
organizationReady: boolean
|
|
15
|
+
allReady: boolean
|
|
16
|
+
isInitializing: boolean
|
|
17
|
+
error: TestInitializationError | null
|
|
18
|
+
retry: () => void
|
|
19
|
+
profile: SupabaseUserProfile | null
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type TestInitializationStateOverrides = Partial<
|
|
23
|
+
Omit<TestInitializationState, 'error' | 'profile' | 'retry'>
|
|
24
|
+
> & {
|
|
25
|
+
error?: TestInitializationError | null
|
|
26
|
+
profile?: Partial<SupabaseUserProfile> | SupabaseUserProfile | null
|
|
27
|
+
retry?: () => void
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function makeOrganizationModel(
|
|
31
|
+
overrides?: DeepPartial<OrganizationModel>
|
|
32
|
+
): OrganizationModel {
|
|
33
|
+
return OrganizationModelSchema.parse(resolveOrganizationModel(overrides))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function makeUserProfile(
|
|
37
|
+
overrides: Partial<SupabaseUserProfile> = {}
|
|
38
|
+
): SupabaseUserProfile {
|
|
39
|
+
return createTestUser(overrides)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function makeInitializationState(
|
|
43
|
+
overrides: TestInitializationStateOverrides = {}
|
|
44
|
+
): TestInitializationState {
|
|
45
|
+
const defaultState: TestInitializationState = {
|
|
46
|
+
userReady: true,
|
|
47
|
+
organizationReady: true,
|
|
48
|
+
allReady: true,
|
|
49
|
+
isInitializing: false,
|
|
50
|
+
error: null,
|
|
51
|
+
retry: () => undefined,
|
|
52
|
+
profile: makeUserProfile()
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
...defaultState,
|
|
57
|
+
...overrides,
|
|
58
|
+
profile:
|
|
59
|
+
overrides.profile === undefined
|
|
60
|
+
? defaultState.profile
|
|
61
|
+
: overrides.profile === null
|
|
62
|
+
? null
|
|
63
|
+
: makeUserProfile(overrides.profile)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
// Published test utilities are intentionally narrow.
|
|
2
|
-
// Internal fixtures and Vitest-heavy mocks remain monorepo-only.
|
|
3
1
|
export * from './rls'
|
|
4
2
|
export * from './browser-mocks'
|
|
3
|
+
export * from './fixtures'
|
|
4
|
+
export * from './mocks'
|
|
5
|
+
export * from './entities'
|
|
6
|
+
export * from './organization-model'
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { BaseProjectSchema, BaseTaskSchema } from '../business/base-entities'
|
|
3
|
+
import { DEFAULT_ORGANIZATION_MODEL } from '../organization-model'
|
|
4
|
+
import {
|
|
5
|
+
makeInitializationState,
|
|
6
|
+
makeOrganizationModel,
|
|
7
|
+
makeProject,
|
|
8
|
+
makeTask,
|
|
9
|
+
makeUserProfile,
|
|
10
|
+
TEST_ORGS,
|
|
11
|
+
TEST_USERS
|
|
12
|
+
} from './published'
|
|
13
|
+
|
|
14
|
+
describe('published test-utils factories', () => {
|
|
15
|
+
it('creates schema-validated base entities with overrides', () => {
|
|
16
|
+
const project = makeProject({ name: 'Custom Project', metadata: { source: 'test' } })
|
|
17
|
+
const task = makeTask({ projectId: project.id, status: 'done' })
|
|
18
|
+
|
|
19
|
+
expect(BaseProjectSchema.parse(project)).toMatchObject({
|
|
20
|
+
name: 'Custom Project',
|
|
21
|
+
metadata: { source: 'test' }
|
|
22
|
+
})
|
|
23
|
+
expect(BaseTaskSchema.parse(task)).toMatchObject({
|
|
24
|
+
projectId: project.id,
|
|
25
|
+
status: 'done'
|
|
26
|
+
})
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('creates organization model and initialization fixtures', () => {
|
|
30
|
+
const model = makeOrganizationModel({
|
|
31
|
+
branding: { organizationName: 'Test Brand' },
|
|
32
|
+
features: DEFAULT_ORGANIZATION_MODEL.features.map((feature) =>
|
|
33
|
+
feature.id === 'seo' ? { ...feature, enabled: true } : feature
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
const profile = makeUserProfile({ id: TEST_USERS.admin.id, email: TEST_USERS.admin.email })
|
|
37
|
+
const state = makeInitializationState({ profile, organizationReady: false, allReady: false })
|
|
38
|
+
|
|
39
|
+
expect(model.branding.organizationName).toBe('Test Brand')
|
|
40
|
+
expect(model.features.find((feature) => feature.id === 'seo')?.enabled).toBe(true)
|
|
41
|
+
expect(state.profile?.email).toBe(TEST_USERS.admin.email)
|
|
42
|
+
expect(state.organizationReady).toBe(false)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('promotes existing fixture surface through the public barrel', () => {
|
|
46
|
+
expect(TEST_USERS.admin.email).toBe('admin@test.com')
|
|
47
|
+
expect(TEST_ORGS.acme.name).toBe('Acme Corp')
|
|
48
|
+
})
|
|
49
|
+
})
|