-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathseed-loader-service.test.ts
More file actions
136 lines (127 loc) · 4.66 KB
/
Copy pathseed-loader-service.test.ts
File metadata and controls
136 lines (127 loc) · 4.66 KB
1
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { describe, it, expect } from 'vitest';
import type { ISeedLoaderService } from './seed-loader-service';
import type { SeedLoaderRequest, SeedLoaderResult, ObjectDependencyGraph } from '../data/seed-loader.zod';
import type { Seed } from '../data/seed.zod';
describe('Seed Loader Service Contract', () => {
it('should allow a minimal implementation with required methods', () => {
const service: ISeedLoaderService = {
load: async (_request: SeedLoaderRequest): Promise<SeedLoaderResult> => {
return {
success: true,
dryRun: false,
dependencyGraph: { nodes: [], insertOrder: [], circularDependencies: [] },
results: [],
errors: [],
summary: {
objectsProcessed: 0,
totalRecords: 0,
totalInserted: 0,
totalUpdated: 0,
totalSkipped: 0,
totalErrored: 0,
totalReferencesResolved: 0,
totalReferencesDeferred: 0,
circularDependencyCount: 0,
durationMs: 0,
},
};
},
buildDependencyGraph: async (_objectNames: string[]): Promise<ObjectDependencyGraph> => {
return { nodes: [], insertOrder: [], circularDependencies: [] };
},
validate: async (_datasets: Seed[]): Promise<SeedLoaderResult> => {
return {
success: true,
dryRun: true,
dependencyGraph: { nodes: [], insertOrder: [], circularDependencies: [] },
results: [],
errors: [],
summary: {
objectsProcessed: 0,
totalRecords: 0,
totalInserted: 0,
totalUpdated: 0,
totalSkipped: 0,
totalErrored: 0,
totalReferencesResolved: 0,
totalReferencesDeferred: 0,
circularDependencyCount: 0,
durationMs: 0,
},
};
},
};
expect(typeof service.load).toBe('function');
expect(typeof service.buildDependencyGraph).toBe('function');
expect(typeof service.validate).toBe('function');
});
it('should return a valid result from load()', async () => {
const service: ISeedLoaderService = {
load: async (request) => ({
success: true,
dryRun: request.config.dryRun,
dependencyGraph: { nodes: [], insertOrder: [], circularDependencies: [] },
results: [],
errors: [],
summary: {
objectsProcessed: request.seeds.length,
totalRecords: request.seeds.reduce((sum, d) => sum + d.records.length, 0),
totalInserted: 0,
totalUpdated: 0,
totalSkipped: 0,
totalErrored: 0,
totalReferencesResolved: 0,
totalReferencesDeferred: 0,
circularDependencyCount: 0,
durationMs: 42,
},
}),
buildDependencyGraph: async () => ({ nodes: [], insertOrder: [], circularDependencies: [] }),
validate: async () => ({
success: true,
dryRun: true,
dependencyGraph: { nodes: [], insertOrder: [], circularDependencies: [] },
results: [],
errors: [],
summary: {
objectsProcessed: 0, totalRecords: 0, totalInserted: 0, totalUpdated: 0,
totalSkipped: 0, totalErrored: 0, totalReferencesResolved: 0,
totalReferencesDeferred: 0, circularDependencyCount: 0, durationMs: 0,
},
}),
};
const result = await service.load({
seeds: [
{ object: 'account', externalId: 'name', mode: 'upsert', env: ['prod', 'dev', 'test'], records: [{ name: 'Acme' }] },
],
config: {
dryRun: false, haltOnError: false, multiPass: true,
defaultMode: 'upsert', batchSize: 1000, transaction: false,
},
});
expect(result.success).toBe(true);
expect(result.dryRun).toBe(false);
expect(result.summary.objectsProcessed).toBe(1);
expect(result.summary.totalRecords).toBe(1);
});
it('should return a dependency graph from buildDependencyGraph()', async () => {
const service: ISeedLoaderService = {
load: async () => ({} as any),
buildDependencyGraph: async (objectNames) => ({
nodes: objectNames.map(name => ({
object: name,
dependsOn: [],
references: [],
})),
insertOrder: objectNames,
circularDependencies: [],
}),
validate: async () => ({} as any),
};
const graph = await service.buildDependencyGraph(['account', 'contact']);
expect(graph.nodes).toHaveLength(2);
expect(graph.insertOrder).toEqual(['account', 'contact']);
expect(graph.circularDependencies).toEqual([]);
});
});