@auto-engineer/server-generator-apollo-emmett 0.10.4 → 0.10.5
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/CHANGELOG.md +8 -0
- package/dist/src/codegen/extract/events.d.ts +2 -2
- package/dist/src/codegen/extract/events.d.ts.map +1 -1
- package/dist/src/codegen/extract/events.js +16 -6
- package/dist/src/codegen/extract/events.js.map +1 -1
- package/dist/src/codegen/extract/gwt.js +7 -22
- package/dist/src/codegen/extract/gwt.js.map +1 -1
- package/dist/src/codegen/extract/imports.d.ts +29 -0
- package/dist/src/codegen/extract/imports.d.ts.map +1 -0
- package/dist/src/codegen/extract/imports.js +55 -0
- package/dist/src/codegen/extract/imports.js.map +1 -0
- package/dist/src/codegen/extract/index.d.ts +1 -0
- package/dist/src/codegen/extract/index.d.ts.map +1 -1
- package/dist/src/codegen/extract/index.js +1 -0
- package/dist/src/codegen/extract/index.js.map +1 -1
- package/dist/src/codegen/extract/messages.d.ts.map +1 -1
- package/dist/src/codegen/extract/messages.js +33 -7
- package/dist/src/codegen/extract/messages.js.map +1 -1
- package/dist/src/codegen/extract/query.d.ts +3 -1
- package/dist/src/codegen/extract/query.d.ts.map +1 -1
- package/dist/src/codegen/extract/query.js +12 -12
- package/dist/src/codegen/extract/query.js.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.d.ts.map +1 -1
- package/dist/src/codegen/scaffoldFromSchema.js +9 -1
- package/dist/src/codegen/scaffoldFromSchema.js.map +1 -1
- package/dist/src/codegen/templates/command/decide.specs.specs.ts +235 -8
- package/dist/src/codegen/templates/command/decide.specs.ts +8 -8
- package/dist/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
- package/dist/src/codegen/templates/command/decide.ts.ejs +2 -2
- package/dist/src/codegen/templates/command/events.ts.ejs +2 -2
- package/dist/src/codegen/templates/command/evolve.ts.ejs +3 -3
- package/dist/src/codegen/templates/command/handle.specs.ts +6 -6
- package/dist/src/codegen/templates/command/handle.ts.ejs +3 -3
- package/dist/src/codegen/templates/query/projection.specs.specs.ts +623 -0
- package/dist/src/codegen/templates/query/projection.specs.ts.ejs +174 -52
- package/dist/src/codegen/templates/query/projection.ts.ejs +30 -29
- package/dist/src/codegen/templates/react/react.specs.specs.ts +7 -4
- package/dist/src/codegen/templates/react/react.specs.ts.ejs +118 -67
- package/dist/src/codegen/types.d.ts +2 -0
- package/dist/src/codegen/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/codegen/extract/events.ts +20 -3
- package/src/codegen/extract/gwt.ts +10 -26
- package/src/codegen/extract/imports.ts +71 -0
- package/src/codegen/extract/index.ts +1 -0
- package/src/codegen/extract/messages.ts +34 -7
- package/src/codegen/extract/query.ts +17 -19
- package/src/codegen/scaffoldFromSchema.ts +13 -0
- package/src/codegen/templates/command/decide.specs.specs.ts +235 -8
- package/src/codegen/templates/command/decide.specs.ts +8 -8
- package/src/codegen/templates/command/decide.specs.ts.ejs +95 -30
- package/src/codegen/templates/command/decide.ts.ejs +2 -2
- package/src/codegen/templates/command/events.ts.ejs +2 -2
- package/src/codegen/templates/command/evolve.ts.ejs +3 -3
- package/src/codegen/templates/command/handle.specs.ts +6 -6
- package/src/codegen/templates/command/handle.ts.ejs +3 -3
- package/src/codegen/templates/query/projection.specs.specs.ts +623 -0
- package/src/codegen/templates/query/projection.specs.ts.ejs +174 -52
- package/src/codegen/templates/query/projection.ts.ejs +30 -29
- package/src/codegen/templates/react/react.specs.specs.ts +7 -4
- package/src/codegen/templates/react/react.specs.ts.ejs +118 -67
- package/src/codegen/types.ts +2 -0
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.d.ts +0 -2
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.d.ts.map +0 -1
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.js +0 -168
- package/dist/src/codegen/scaffoldFromSchema.query-slice-register.specs.js.map +0 -1
- package/dist/src/codegen/templates/query/projection.specs.specs..ts +0 -296
- package/src/codegen/scaffoldFromSchema.query-slice-register.specs.ts +0 -179
- package/src/codegen/templates/query/projection.specs.specs..ts +0 -296
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { generateScaffoldFilePlans } from './scaffoldFromSchema.js';
|
|
3
|
-
describe('Query slice register file generation', () => {
|
|
4
|
-
it('should not generate register.ts for query slices with data projections', async () => {
|
|
5
|
-
// Create a minimal model with a query slice that has data projections
|
|
6
|
-
const model = {
|
|
7
|
-
variant: 'specs',
|
|
8
|
-
messages: [], // Empty messages array to avoid undefined error
|
|
9
|
-
flows: [
|
|
10
|
-
{
|
|
11
|
-
id: 'flow-1',
|
|
12
|
-
name: 'Questionnaire Flow',
|
|
13
|
-
slices: [
|
|
14
|
-
{
|
|
15
|
-
id: 'AUTO-V7n8Rq5M',
|
|
16
|
-
type: 'query',
|
|
17
|
-
name: 'views the questionnaire',
|
|
18
|
-
client: {
|
|
19
|
-
description: 'Client for viewing questionnaire',
|
|
20
|
-
},
|
|
21
|
-
server: {
|
|
22
|
-
description: 'Views questionnaire progress',
|
|
23
|
-
specs: {
|
|
24
|
-
name: 'questionnaire progress specs',
|
|
25
|
-
rules: [
|
|
26
|
-
{
|
|
27
|
-
id: 'AUTO-r1A3Bp9W',
|
|
28
|
-
description: 'questionnaires show current progress',
|
|
29
|
-
examples: [
|
|
30
|
-
{
|
|
31
|
-
description: 'a question has already been answered',
|
|
32
|
-
given: [
|
|
33
|
-
{
|
|
34
|
-
eventRef: 'QuestionnaireLinkSent',
|
|
35
|
-
exampleData: {
|
|
36
|
-
questionnaireId: 'q-001',
|
|
37
|
-
participantId: 'participant-abc',
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
],
|
|
41
|
-
when: {
|
|
42
|
-
eventRef: 'ViewQuestionnaire',
|
|
43
|
-
exampleData: { questionnaireId: 'q-001' },
|
|
44
|
-
},
|
|
45
|
-
then: [
|
|
46
|
-
{
|
|
47
|
-
stateRef: 'QuestionnaireProgress',
|
|
48
|
-
exampleData: {
|
|
49
|
-
questionnaireId: 'q-001',
|
|
50
|
-
participantId: 'participant-abc',
|
|
51
|
-
status: 'in_progress',
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
data: [
|
|
61
|
-
{
|
|
62
|
-
target: {
|
|
63
|
-
type: 'State',
|
|
64
|
-
name: 'QuestionnaireProgress',
|
|
65
|
-
},
|
|
66
|
-
origin: {
|
|
67
|
-
type: 'projection',
|
|
68
|
-
name: 'Questionnaires',
|
|
69
|
-
idField: 'questionnaireId',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
};
|
|
79
|
-
// Generate scaffold plans for the model
|
|
80
|
-
const plans = await generateScaffoldFilePlans(model.flows, model.messages, model.integrations, '/tmp/test');
|
|
81
|
-
// Extract just the filenames from the generated files
|
|
82
|
-
const generatedFileNames = plans.map((plan) => {
|
|
83
|
-
const parts = plan.outputPath.split('/');
|
|
84
|
-
return parts[parts.length - 1];
|
|
85
|
-
});
|
|
86
|
-
// Query slices should NOT generate register.ts files
|
|
87
|
-
expect(generatedFileNames).not.toContain('register.ts');
|
|
88
|
-
// Query slices should generate projection-related files
|
|
89
|
-
expect(generatedFileNames).toContain('projection.ts');
|
|
90
|
-
expect(generatedFileNames).toContain('query.resolver.ts');
|
|
91
|
-
// Query slices should NOT generate command-related files
|
|
92
|
-
expect(generatedFileNames).not.toContain('commands.ts');
|
|
93
|
-
expect(generatedFileNames).not.toContain('handle.ts');
|
|
94
|
-
expect(generatedFileNames).not.toContain('decide.ts');
|
|
95
|
-
expect(generatedFileNames).not.toContain('mutation.resolver.ts');
|
|
96
|
-
});
|
|
97
|
-
it('should generate register.ts for command slices', async () => {
|
|
98
|
-
// Create a minimal model with a command slice
|
|
99
|
-
const model = {
|
|
100
|
-
variant: 'specs',
|
|
101
|
-
messages: [], // Empty messages array to avoid undefined error
|
|
102
|
-
flows: [
|
|
103
|
-
{
|
|
104
|
-
id: 'flow-2',
|
|
105
|
-
name: 'Command Flow',
|
|
106
|
-
slices: [
|
|
107
|
-
{
|
|
108
|
-
id: 'AUTO-CMD123',
|
|
109
|
-
type: 'command',
|
|
110
|
-
name: 'submit answer',
|
|
111
|
-
client: {
|
|
112
|
-
description: 'Submit answer client',
|
|
113
|
-
},
|
|
114
|
-
server: {
|
|
115
|
-
description: 'Submits an answer',
|
|
116
|
-
specs: {
|
|
117
|
-
name: 'submit answer specs',
|
|
118
|
-
rules: [
|
|
119
|
-
{
|
|
120
|
-
id: 'AUTO-rule123',
|
|
121
|
-
description: 'should accept valid answers',
|
|
122
|
-
examples: [
|
|
123
|
-
{
|
|
124
|
-
description: 'valid answer submission',
|
|
125
|
-
when: {
|
|
126
|
-
commandRef: 'AnswerQuestion',
|
|
127
|
-
exampleData: {
|
|
128
|
-
questionnaireId: 'q-001',
|
|
129
|
-
answer: 'Yes',
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
then: [
|
|
133
|
-
{
|
|
134
|
-
eventRef: 'QuestionAnswered',
|
|
135
|
-
exampleData: {
|
|
136
|
-
questionnaireId: 'q-001',
|
|
137
|
-
answer: 'Yes',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
};
|
|
152
|
-
// Generate scaffold plans for the model
|
|
153
|
-
const plans = await generateScaffoldFilePlans(model.flows, model.messages, model.integrations, '/tmp/test');
|
|
154
|
-
// Extract just the filenames from the generated files
|
|
155
|
-
const generatedFileNames = plans.map((plan) => {
|
|
156
|
-
const parts = plan.outputPath.split('/');
|
|
157
|
-
return parts[parts.length - 1];
|
|
158
|
-
});
|
|
159
|
-
// Command slices SHOULD generate register.ts files
|
|
160
|
-
expect(generatedFileNames).toContain('register.ts');
|
|
161
|
-
// Command slices should generate command-related files
|
|
162
|
-
expect(generatedFileNames).toContain('commands.ts');
|
|
163
|
-
expect(generatedFileNames).toContain('handle.ts');
|
|
164
|
-
expect(generatedFileNames).toContain('decide.ts');
|
|
165
|
-
expect(generatedFileNames).toContain('mutation.resolver.ts');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
//# sourceMappingURL=scaffoldFromSchema.query-slice-register.specs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scaffoldFromSchema.query-slice-register.specs.js","sourceRoot":"","sources":["../../../src/codegen/scaffoldFromSchema.query-slice-register.specs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AAGjE,QAAQ,CAAC,sCAAsC,EAAE,GAAG,EAAE;IACpD,EAAE,CAAC,wEAAwE,EAAE,KAAK,IAAI,EAAE;QACtF,sEAAsE;QACtE,MAAM,KAAK,GAAU;YACnB,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,EAAE,EAAE,gDAAgD;YAC9D,KAAK,EAAE;gBACL;oBACE,EAAE,EAAE,QAAQ;oBACZ,IAAI,EAAE,oBAAoB;oBAC1B,MAAM,EAAE;wBACN;4BACE,EAAE,EAAE,eAAe;4BACnB,IAAI,EAAE,OAAO;4BACb,IAAI,EAAE,yBAAyB;4BAC/B,MAAM,EAAE;gCACN,WAAW,EAAE,kCAAkC;6BAChD;4BACD,MAAM,EAAE;gCACN,WAAW,EAAE,8BAA8B;gCAC3C,KAAK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@@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { generateScaffoldFilePlans } from '../../scaffoldFromSchema';
|
|
3
|
-
import { Model as SpecsSchema } from '@auto-engineer/flow';
|
|
4
|
-
|
|
5
|
-
describe('projection.specs.ts.ejs', () => {
|
|
6
|
-
it('should generate a valid test spec for a query slice projection', async () => {
|
|
7
|
-
const spec: SpecsSchema = {
|
|
8
|
-
variant: 'specs',
|
|
9
|
-
flows: [
|
|
10
|
-
{
|
|
11
|
-
name: 'listing-flow',
|
|
12
|
-
slices: [
|
|
13
|
-
{
|
|
14
|
-
type: 'command',
|
|
15
|
-
name: 'CreateListing',
|
|
16
|
-
stream: 'listing-${propertyId}',
|
|
17
|
-
client: { description: '' },
|
|
18
|
-
server: {
|
|
19
|
-
description: '',
|
|
20
|
-
specs: {
|
|
21
|
-
name: 'CreateListing command',
|
|
22
|
-
rules: [
|
|
23
|
-
{
|
|
24
|
-
description: 'Should handle listing operations',
|
|
25
|
-
examples: [
|
|
26
|
-
{
|
|
27
|
-
description: 'User creates listing successfully',
|
|
28
|
-
when: {
|
|
29
|
-
commandRef: 'CreateListing',
|
|
30
|
-
exampleData: {
|
|
31
|
-
propertyId: 'listing_123',
|
|
32
|
-
title: 'Sea View Flat',
|
|
33
|
-
pricePerNight: 120,
|
|
34
|
-
location: 'Brighton',
|
|
35
|
-
maxGuests: 4,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
then: [
|
|
39
|
-
{
|
|
40
|
-
eventRef: 'ListingCreated',
|
|
41
|
-
exampleData: {
|
|
42
|
-
propertyId: 'listing_123',
|
|
43
|
-
title: 'Sea View Flat',
|
|
44
|
-
pricePerNight: 120,
|
|
45
|
-
location: 'Brighton',
|
|
46
|
-
maxGuests: 4,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
description: 'User removes listing successfully',
|
|
53
|
-
when: {
|
|
54
|
-
commandRef: 'RemoveListing',
|
|
55
|
-
exampleData: {
|
|
56
|
-
propertyId: 'listing_123',
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
then: [
|
|
60
|
-
{
|
|
61
|
-
eventRef: 'ListingRemoved',
|
|
62
|
-
exampleData: {},
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
],
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
type: 'query',
|
|
74
|
-
name: 'search-listings',
|
|
75
|
-
stream: 'listings',
|
|
76
|
-
client: { description: '' },
|
|
77
|
-
server: {
|
|
78
|
-
description: '',
|
|
79
|
-
data: [
|
|
80
|
-
{
|
|
81
|
-
origin: {
|
|
82
|
-
type: 'projection',
|
|
83
|
-
idField: 'propertyId',
|
|
84
|
-
name: 'AvailablePropertiesProjection',
|
|
85
|
-
},
|
|
86
|
-
target: {
|
|
87
|
-
type: 'State',
|
|
88
|
-
name: 'AvailableListings',
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
specs: {
|
|
93
|
-
name: 'Search listings query',
|
|
94
|
-
rules: [
|
|
95
|
-
{
|
|
96
|
-
description: 'Should project listings correctly',
|
|
97
|
-
examples: [
|
|
98
|
-
{
|
|
99
|
-
description: 'Listing created shows in search results',
|
|
100
|
-
when: [
|
|
101
|
-
{
|
|
102
|
-
eventRef: 'ListingCreated',
|
|
103
|
-
exampleData: {
|
|
104
|
-
propertyId: 'listing_123',
|
|
105
|
-
title: 'Sea View Flat',
|
|
106
|
-
pricePerNight: 120,
|
|
107
|
-
location: 'Brighton',
|
|
108
|
-
maxGuests: 4,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
],
|
|
112
|
-
then: [
|
|
113
|
-
{
|
|
114
|
-
stateRef: 'AvailableListings',
|
|
115
|
-
exampleData: {
|
|
116
|
-
propertyId: 'listing_123',
|
|
117
|
-
title: 'Sea View Flat',
|
|
118
|
-
pricePerNight: 120,
|
|
119
|
-
location: 'Brighton',
|
|
120
|
-
maxGuests: 4,
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
],
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
description: 'Listing removed disappears from search results',
|
|
127
|
-
when: [
|
|
128
|
-
{
|
|
129
|
-
eventRef: 'ListingRemoved',
|
|
130
|
-
exampleData: {
|
|
131
|
-
propertyId: 'listing_123',
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
then: [
|
|
136
|
-
{
|
|
137
|
-
stateRef: 'AvailableListings',
|
|
138
|
-
exampleData: {},
|
|
139
|
-
},
|
|
140
|
-
],
|
|
141
|
-
},
|
|
142
|
-
],
|
|
143
|
-
},
|
|
144
|
-
],
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
messages: [
|
|
152
|
-
{
|
|
153
|
-
type: 'command',
|
|
154
|
-
name: 'CreateListing',
|
|
155
|
-
fields: [
|
|
156
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
157
|
-
{ name: 'title', type: 'string', required: true },
|
|
158
|
-
{ name: 'pricePerNight', type: 'number', required: true },
|
|
159
|
-
{ name: 'location', type: 'string', required: true },
|
|
160
|
-
{ name: 'maxGuests', type: 'number', required: true },
|
|
161
|
-
],
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
type: 'command',
|
|
165
|
-
name: 'RemoveListing',
|
|
166
|
-
fields: [{ name: 'propertyId', type: 'string', required: true }],
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
type: 'event',
|
|
170
|
-
name: 'ListingCreated',
|
|
171
|
-
source: 'internal',
|
|
172
|
-
fields: [
|
|
173
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
174
|
-
{ name: 'title', type: 'string', required: true },
|
|
175
|
-
{ name: 'pricePerNight', type: 'number', required: true },
|
|
176
|
-
{ name: 'location', type: 'string', required: true },
|
|
177
|
-
{ name: 'maxGuests', type: 'number', required: true },
|
|
178
|
-
],
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
type: 'event',
|
|
182
|
-
name: 'ListingRemoved',
|
|
183
|
-
source: 'internal',
|
|
184
|
-
fields: [{ name: 'propertyId', type: 'string', required: true }],
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
type: 'state',
|
|
188
|
-
name: 'AvailableListings',
|
|
189
|
-
fields: [
|
|
190
|
-
{ name: 'propertyId', type: 'string', required: true },
|
|
191
|
-
{ name: 'title', type: 'string', required: true },
|
|
192
|
-
{ name: 'pricePerNight', type: 'number', required: true },
|
|
193
|
-
{ name: 'location', type: 'string', required: true },
|
|
194
|
-
{ name: 'maxGuests', type: 'number', required: true },
|
|
195
|
-
],
|
|
196
|
-
},
|
|
197
|
-
],
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const plans = await generateScaffoldFilePlans(spec.flows, spec.messages, undefined, 'src/domain/flows');
|
|
201
|
-
const specFile = plans.find((p) => p.outputPath.endsWith('projection.spec.ts'));
|
|
202
|
-
|
|
203
|
-
expect(specFile?.contents).toMatchInlineSnapshot(`
|
|
204
|
-
"import { describe, it, beforeEach, expect } from 'vitest';
|
|
205
|
-
import { v4 as uuid } from 'uuid';
|
|
206
|
-
import {
|
|
207
|
-
InMemoryProjectionSpec,
|
|
208
|
-
eventsInStream,
|
|
209
|
-
newEventsInStream
|
|
210
|
-
} from '@event-driven-io/emmett';
|
|
211
|
-
import { projection } from './projection';
|
|
212
|
-
|
|
213
|
-
import type { ListingCreated, ListingRemoved } from '../create-listing/events';
|
|
214
|
-
import type { AvailableListings } from './state';
|
|
215
|
-
|
|
216
|
-
type AllEvents = ListingCreated | ListingRemoved;
|
|
217
|
-
|
|
218
|
-
describe('AvailableListings projection', () => {
|
|
219
|
-
let given: InMemoryProjectionSpec<AllEvents>;
|
|
220
|
-
let propertyId: string;
|
|
221
|
-
|
|
222
|
-
beforeEach(() => {
|
|
223
|
-
propertyId = \`listing-\${uuid()}\`;
|
|
224
|
-
given = InMemoryProjectionSpec.for({ projection });
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it('handles ListingCreated', () =>
|
|
228
|
-
given([])
|
|
229
|
-
.when([
|
|
230
|
-
{
|
|
231
|
-
type: 'ListingCreated',
|
|
232
|
-
data: {
|
|
233
|
-
propertyId,
|
|
234
|
-
title: 'Sea View Flat',
|
|
235
|
-
pricePerNight: 120,
|
|
236
|
-
location: 'Brighton',
|
|
237
|
-
maxGuests: 4
|
|
238
|
-
},
|
|
239
|
-
metadata: {
|
|
240
|
-
streamName: propertyId,
|
|
241
|
-
streamPosition: 1n,
|
|
242
|
-
globalPosition: 1n
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
])
|
|
246
|
-
.then(async (state) => {
|
|
247
|
-
const document = await state.database
|
|
248
|
-
.collection<AvailableListings>('available-properties-projection')
|
|
249
|
-
.findOne((doc) => doc.propertyId === propertyId);
|
|
250
|
-
|
|
251
|
-
const expected: AvailableListings = {
|
|
252
|
-
propertyId,
|
|
253
|
-
title: 'Sea View Flat',
|
|
254
|
-
pricePerNight: 120,
|
|
255
|
-
location: 'Brighton',
|
|
256
|
-
maxGuests: 4
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
expect(document).toMatchObject(expected);
|
|
260
|
-
}));
|
|
261
|
-
|
|
262
|
-
it('handles ListingRemoved', () =>
|
|
263
|
-
given(
|
|
264
|
-
eventsInStream(propertyId, [
|
|
265
|
-
{
|
|
266
|
-
type: 'ListingCreated',
|
|
267
|
-
data: {
|
|
268
|
-
propertyId,
|
|
269
|
-
title: 'Sea View Flat',
|
|
270
|
-
pricePerNight: 120,
|
|
271
|
-
location: 'Brighton',
|
|
272
|
-
maxGuests: 4
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
])
|
|
276
|
-
)
|
|
277
|
-
.when(
|
|
278
|
-
newEventsInStream(propertyId, [
|
|
279
|
-
{
|
|
280
|
-
type: 'ListingRemoved',
|
|
281
|
-
data: {
|
|
282
|
-
propertyId
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
])
|
|
286
|
-
)
|
|
287
|
-
.then(async (state) => {
|
|
288
|
-
const document = await state.database
|
|
289
|
-
.collection<AvailableListings>('available-properties-projection')
|
|
290
|
-
.findOne((doc) => doc.propertyId === propertyId);
|
|
291
|
-
expect(document).toBeNull();
|
|
292
|
-
}));
|
|
293
|
-
});
|
|
294
|
-
`);
|
|
295
|
-
});
|
|
296
|
-
});
|
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { generateScaffoldFilePlans } from './scaffoldFromSchema';
|
|
3
|
-
import type { Model } from '@auto-engineer/flow';
|
|
4
|
-
|
|
5
|
-
describe('Query slice register file generation', () => {
|
|
6
|
-
it('should not generate register.ts for query slices with data projections', async () => {
|
|
7
|
-
// Create a minimal model with a query slice that has data projections
|
|
8
|
-
const model: Model = {
|
|
9
|
-
variant: 'specs',
|
|
10
|
-
messages: [], // Empty messages array to avoid undefined error
|
|
11
|
-
flows: [
|
|
12
|
-
{
|
|
13
|
-
id: 'flow-1',
|
|
14
|
-
name: 'Questionnaire Flow',
|
|
15
|
-
slices: [
|
|
16
|
-
{
|
|
17
|
-
id: 'AUTO-V7n8Rq5M',
|
|
18
|
-
type: 'query',
|
|
19
|
-
name: 'views the questionnaire',
|
|
20
|
-
client: {
|
|
21
|
-
description: 'Client for viewing questionnaire',
|
|
22
|
-
},
|
|
23
|
-
server: {
|
|
24
|
-
description: 'Views questionnaire progress',
|
|
25
|
-
specs: {
|
|
26
|
-
name: 'questionnaire progress specs',
|
|
27
|
-
rules: [
|
|
28
|
-
{
|
|
29
|
-
id: 'AUTO-r1A3Bp9W',
|
|
30
|
-
description: 'questionnaires show current progress',
|
|
31
|
-
examples: [
|
|
32
|
-
{
|
|
33
|
-
description: 'a question has already been answered',
|
|
34
|
-
given: [
|
|
35
|
-
{
|
|
36
|
-
eventRef: 'QuestionnaireLinkSent',
|
|
37
|
-
exampleData: {
|
|
38
|
-
questionnaireId: 'q-001',
|
|
39
|
-
participantId: 'participant-abc',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
],
|
|
43
|
-
when: {
|
|
44
|
-
eventRef: 'ViewQuestionnaire',
|
|
45
|
-
exampleData: { questionnaireId: 'q-001' },
|
|
46
|
-
},
|
|
47
|
-
then: [
|
|
48
|
-
{
|
|
49
|
-
stateRef: 'QuestionnaireProgress',
|
|
50
|
-
exampleData: {
|
|
51
|
-
questionnaireId: 'q-001',
|
|
52
|
-
participantId: 'participant-abc',
|
|
53
|
-
status: 'in_progress',
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
},
|
|
62
|
-
data: [
|
|
63
|
-
{
|
|
64
|
-
target: {
|
|
65
|
-
type: 'State',
|
|
66
|
-
name: 'QuestionnaireProgress',
|
|
67
|
-
},
|
|
68
|
-
origin: {
|
|
69
|
-
type: 'projection',
|
|
70
|
-
name: 'Questionnaires',
|
|
71
|
-
idField: 'questionnaireId',
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Generate scaffold plans for the model
|
|
83
|
-
const plans = await generateScaffoldFilePlans(model.flows, model.messages, model.integrations, '/tmp/test');
|
|
84
|
-
|
|
85
|
-
// Extract just the filenames from the generated files
|
|
86
|
-
const generatedFileNames = plans.map((plan) => {
|
|
87
|
-
const parts = plan.outputPath.split('/');
|
|
88
|
-
return parts[parts.length - 1];
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// Query slices should NOT generate register.ts files
|
|
92
|
-
expect(generatedFileNames).not.toContain('register.ts');
|
|
93
|
-
|
|
94
|
-
// Query slices should generate projection-related files
|
|
95
|
-
expect(generatedFileNames).toContain('projection.ts');
|
|
96
|
-
expect(generatedFileNames).toContain('query.resolver.ts');
|
|
97
|
-
|
|
98
|
-
// Query slices should NOT generate command-related files
|
|
99
|
-
expect(generatedFileNames).not.toContain('commands.ts');
|
|
100
|
-
expect(generatedFileNames).not.toContain('handle.ts');
|
|
101
|
-
expect(generatedFileNames).not.toContain('decide.ts');
|
|
102
|
-
expect(generatedFileNames).not.toContain('mutation.resolver.ts');
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should generate register.ts for command slices', async () => {
|
|
106
|
-
// Create a minimal model with a command slice
|
|
107
|
-
const model: Model = {
|
|
108
|
-
variant: 'specs',
|
|
109
|
-
messages: [], // Empty messages array to avoid undefined error
|
|
110
|
-
flows: [
|
|
111
|
-
{
|
|
112
|
-
id: 'flow-2',
|
|
113
|
-
name: 'Command Flow',
|
|
114
|
-
slices: [
|
|
115
|
-
{
|
|
116
|
-
id: 'AUTO-CMD123',
|
|
117
|
-
type: 'command',
|
|
118
|
-
name: 'submit answer',
|
|
119
|
-
client: {
|
|
120
|
-
description: 'Submit answer client',
|
|
121
|
-
},
|
|
122
|
-
server: {
|
|
123
|
-
description: 'Submits an answer',
|
|
124
|
-
specs: {
|
|
125
|
-
name: 'submit answer specs',
|
|
126
|
-
rules: [
|
|
127
|
-
{
|
|
128
|
-
id: 'AUTO-rule123',
|
|
129
|
-
description: 'should accept valid answers',
|
|
130
|
-
examples: [
|
|
131
|
-
{
|
|
132
|
-
description: 'valid answer submission',
|
|
133
|
-
when: {
|
|
134
|
-
commandRef: 'AnswerQuestion',
|
|
135
|
-
exampleData: {
|
|
136
|
-
questionnaireId: 'q-001',
|
|
137
|
-
answer: 'Yes',
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
then: [
|
|
141
|
-
{
|
|
142
|
-
eventRef: 'QuestionAnswered',
|
|
143
|
-
exampleData: {
|
|
144
|
-
questionnaireId: 'q-001',
|
|
145
|
-
answer: 'Yes',
|
|
146
|
-
},
|
|
147
|
-
},
|
|
148
|
-
],
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
},
|
|
152
|
-
],
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
],
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// Generate scaffold plans for the model
|
|
162
|
-
const plans = await generateScaffoldFilePlans(model.flows, model.messages, model.integrations, '/tmp/test');
|
|
163
|
-
|
|
164
|
-
// Extract just the filenames from the generated files
|
|
165
|
-
const generatedFileNames = plans.map((plan) => {
|
|
166
|
-
const parts = plan.outputPath.split('/');
|
|
167
|
-
return parts[parts.length - 1];
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// Command slices SHOULD generate register.ts files
|
|
171
|
-
expect(generatedFileNames).toContain('register.ts');
|
|
172
|
-
|
|
173
|
-
// Command slices should generate command-related files
|
|
174
|
-
expect(generatedFileNames).toContain('commands.ts');
|
|
175
|
-
expect(generatedFileNames).toContain('handle.ts');
|
|
176
|
-
expect(generatedFileNames).toContain('decide.ts');
|
|
177
|
-
expect(generatedFileNames).toContain('mutation.resolver.ts');
|
|
178
|
-
});
|
|
179
|
-
});
|