Skip to content

Commit 0e2a2e9

Browse files
authored
fix(compass-generative-ai): fix api contract and anticipate future change CLOUDP-344335 (#7330)
Fix api contract and anticipate future change
1 parent 15b4683 commit 0e2a2e9

File tree

5 files changed

+110
-157
lines changed

5 files changed

+110
-157
lines changed

packages/compass-collection/src/components/mock-data-generator-modal/mock-data-generator-modal.spec.tsx

Lines changed: 35 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,14 @@ describe('MockDataGeneratorModal', () => {
8181
atlasAiService: {
8282
getMockDataSchema: () => {
8383
return Promise.resolve({
84-
content: {
85-
fields: [
86-
{
87-
fieldPath: 'name',
88-
mongoType: 'string',
89-
fakerMethod: 'person.firstName',
90-
fakerArgs: [],
91-
isArray: false,
92-
probability: 1.0,
93-
},
94-
],
95-
},
84+
fields: [
85+
{
86+
fieldPath: 'name',
87+
mongoType: 'string',
88+
fakerMethod: 'person.firstName',
89+
fakerArgs: [],
90+
},
91+
],
9692
} as MockDataSchemaResponse);
9793
},
9894
},
@@ -287,42 +283,32 @@ describe('MockDataGeneratorModal', () => {
287283
const mockServicesWithMockDataResponse = createMockServices();
288284
mockServicesWithMockDataResponse.atlasAiService.getMockDataSchema = () =>
289285
Promise.resolve({
290-
content: {
291-
fields: [
292-
{
293-
fieldPath: 'name',
294-
mongoType: 'string',
295-
fakerMethod: 'person.firstName',
296-
fakerArgs: [],
297-
isArray: false,
298-
probability: 1.0,
299-
},
300-
{
301-
fieldPath: 'age',
302-
mongoType: 'int',
303-
fakerMethod: 'number.int',
304-
fakerArgs: [],
305-
isArray: false,
306-
probability: 1.0,
307-
},
308-
{
309-
fieldPath: 'email',
310-
mongoType: 'string',
311-
fakerMethod: 'internet',
312-
fakerArgs: [],
313-
isArray: false,
314-
probability: 1.0,
315-
},
316-
{
317-
fieldPath: 'username',
318-
mongoType: 'string',
319-
fakerMethod: 'noSuchMethod',
320-
fakerArgs: [],
321-
isArray: false,
322-
probability: 1.0,
323-
},
324-
],
325-
},
286+
fields: [
287+
{
288+
fieldPath: 'name',
289+
mongoType: 'string',
290+
fakerMethod: 'person.firstName',
291+
fakerArgs: [],
292+
},
293+
{
294+
fieldPath: 'age',
295+
mongoType: 'int',
296+
fakerMethod: 'number.int',
297+
fakerArgs: [],
298+
},
299+
{
300+
fieldPath: 'email',
301+
mongoType: 'string',
302+
fakerMethod: 'internet',
303+
fakerArgs: [],
304+
},
305+
{
306+
fieldPath: 'username',
307+
mongoType: 'string',
308+
fakerMethod: 'noSuchMethod',
309+
fakerArgs: [],
310+
},
311+
],
326312
});
327313

328314
it('shows a loading spinner when the faker schema generation is in progress', async () => {
@@ -332,9 +318,7 @@ describe('MockDataGeneratorModal', () => {
332318
setTimeout(
333319
() =>
334320
resolve({
335-
content: {
336-
fields: [],
337-
},
321+
fields: [],
338322
}),
339323
1000
340324
)

packages/compass-collection/src/components/mock-data-generator-modal/types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,4 @@ export type MockDataGeneratorState =
3535
| MockDataGeneratorCompletedState
3636
| MockDataGeneratorErrorState;
3737

38-
export type FakerSchemaMapping = Omit<
39-
MockDataSchemaResponse['content']['fields'][number],
40-
'isArray'
41-
>;
38+
export type FakerSchemaMapping = MockDataSchemaResponse['fields'][number];

packages/compass-collection/src/modules/collection-tab.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ const validateFakerSchema = (
702702
fakerSchema: MockDataSchemaResponse,
703703
logger: Logger
704704
) => {
705-
return fakerSchema.content.fields.map((field) => {
705+
return fakerSchema.fields.map((field) => {
706706
const { fakerMethod } = field;
707707

708708
const [moduleName, methodName, ...rest] = fakerMethod.split('.');

packages/compass-generative-ai/src/atlas-ai-service.spec.ts

Lines changed: 56 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -428,26 +428,20 @@ describe('AtlasAiService', function () {
428428
if (apiURLPreset === 'cloud') {
429429
it('makes a post request to the correct endpoint', async function () {
430430
const mockResponse = {
431-
content: {
432-
fields: [
433-
{
434-
fieldPath: 'name',
435-
mongoType: 'string',
436-
fakerMethod: 'person.fullName',
437-
fakerArgs: [],
438-
isArray: false,
439-
probability: 1.0,
440-
},
441-
{
442-
fieldPath: 'age',
443-
mongoType: 'int',
444-
fakerMethod: 'number.int',
445-
fakerArgs: [{ json: '{"min": 18, "max": 65}' }],
446-
isArray: false,
447-
probability: 0.8,
448-
},
449-
],
450-
},
431+
fields: [
432+
{
433+
fieldPath: 'name',
434+
mongoType: 'string',
435+
fakerMethod: 'person.fullName',
436+
fakerArgs: [],
437+
},
438+
{
439+
fieldPath: 'age',
440+
mongoType: 'int',
441+
fakerMethod: 'number.int',
442+
fakerArgs: [{ json: '{"min": 18, "max": 65}' }],
443+
},
444+
],
451445
};
452446
const fetchStub = sandbox
453447
.stub()
@@ -469,26 +463,20 @@ describe('AtlasAiService', function () {
469463

470464
it('includes sample values by default (includeSampleValues=true)', async function () {
471465
const mockResponse = {
472-
content: {
473-
fields: [
474-
{
475-
fieldPath: 'name',
476-
mongoType: 'string',
477-
fakerMethod: 'person.fullName',
478-
fakerArgs: [],
479-
isArray: false,
480-
probability: 1.0,
481-
},
482-
{
483-
fieldPath: 'age',
484-
mongoType: 'int',
485-
fakerMethod: 'number.int',
486-
fakerArgs: [{ json: '{"min": 18, "max": 122}' }],
487-
isArray: false,
488-
probability: 0.8,
489-
},
490-
],
491-
},
466+
fields: [
467+
{
468+
fieldPath: 'name',
469+
mongoType: 'string',
470+
fakerMethod: 'person.fullName',
471+
fakerArgs: [],
472+
},
473+
{
474+
fieldPath: 'age',
475+
mongoType: 'int',
476+
fakerMethod: 'number.int',
477+
fakerArgs: [{ json: '{"min": 18, "max": 122}' }],
478+
},
479+
],
492480
};
493481
const fetchStub = sandbox
494482
.stub()
@@ -515,26 +503,20 @@ describe('AtlasAiService', function () {
515503

516504
it('excludes sample values when includeSampleValues=false', async function () {
517505
const mockResponse = {
518-
content: {
519-
fields: [
520-
{
521-
fieldPath: 'name',
522-
mongoType: 'string',
523-
fakerMethod: 'person.fullName',
524-
fakerArgs: [],
525-
isArray: false,
526-
probability: 1.0,
527-
},
528-
{
529-
fieldPath: 'age',
530-
mongoType: 'int',
531-
fakerMethod: 'number.int',
532-
fakerArgs: [{ json: '{"min": 18, "max": 65}' }],
533-
isArray: false,
534-
probability: 0.8,
535-
},
536-
],
537-
},
506+
fields: [
507+
{
508+
fieldPath: 'name',
509+
mongoType: 'string',
510+
fakerMethod: 'person.fullName',
511+
fakerArgs: [],
512+
},
513+
{
514+
fieldPath: 'age',
515+
mongoType: 'int',
516+
fakerMethod: 'number.int',
517+
fakerArgs: [{ json: '{"min": 18, "max": 65}' }],
518+
},
519+
],
538520
};
539521
const fetchStub = sandbox
540522
.stub()
@@ -559,26 +541,20 @@ describe('AtlasAiService', function () {
559541

560542
it('makes POST request with correct headers and body structure', async function () {
561543
const mockResponse = {
562-
content: {
563-
fields: [
564-
{
565-
fieldPath: 'name',
566-
mongoType: 'string',
567-
fakerMethod: 'person.fullName',
568-
fakerArgs: [],
569-
isArray: false,
570-
probability: 1.0,
571-
},
572-
{
573-
fieldPath: 'age',
574-
mongoType: 'int',
575-
fakerMethod: 'number.int',
576-
fakerArgs: [{ json: '{"min": 18, "max": 65}' }],
577-
isArray: false,
578-
probability: 0.8,
579-
},
580-
],
581-
},
544+
fields: [
545+
{
546+
fieldPath: 'name',
547+
mongoType: 'string',
548+
fakerMethod: 'person.fullName',
549+
fakerArgs: [],
550+
},
551+
{
552+
fieldPath: 'age',
553+
mongoType: 'int',
554+
fakerMethod: 'number.int',
555+
fakerArgs: [{ json: '{"min": 18, "max": 65}' }],
556+
},
557+
],
582558
};
583559
const fetchStub = sandbox
584560
.stub()

packages/compass-generative-ai/src/atlas-ai-service.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -232,27 +232,23 @@ export interface MockDataSchemaRequest {
232232
}
233233

234234
export const MockDataSchemaResponseShape = z.object({
235-
content: z.object({
236-
fields: z.array(
237-
z.object({
238-
fieldPath: z.string(),
239-
mongoType: z.string(),
240-
fakerMethod: z.string(),
241-
fakerArgs: z.array(
242-
z.union([
243-
z.object({
244-
json: z.string(),
245-
}),
246-
z.string(),
247-
z.number(),
248-
z.boolean(),
249-
])
250-
),
251-
isArray: z.boolean(),
252-
probability: z.number(),
253-
})
254-
),
255-
}),
235+
fields: z.array(
236+
z.object({
237+
fieldPath: z.string(),
238+
mongoType: z.string(),
239+
fakerMethod: z.string(),
240+
fakerArgs: z.array(
241+
z.union([
242+
z.object({
243+
json: z.string(),
244+
}),
245+
z.string(),
246+
z.number(),
247+
z.boolean(),
248+
])
249+
),
250+
})
251+
),
256252
});
257253

258254
export type MockDataSchemaResponse = z.infer<

0 commit comments

Comments
 (0)