Skip to content

Commit dd22acf

Browse files
committed
clean up probability handling in AtlasAiService and in faker schema validation
1 parent a1bdd4d commit dd22acf

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
renderWithActiveConnection,
66
waitFor,
77
userEvent,
8+
waitForElementToBeRemoved,
89
} from '@mongodb-js/testing-library-compass';
910
import { Provider } from 'react-redux';
1011
import { createStore, applyMiddleware } from 'redux';
@@ -511,10 +512,9 @@ describe('MockDataGeneratorModal', () => {
511512

512513
// advance to the schema editor step
513514
userEvent.click(screen.getByText('Confirm'));
514-
515-
await waitFor(() => {
516-
expect(screen.getByTestId('faker-schema-editor')).to.exist;
517-
});
515+
await waitForElementToBeRemoved(() =>
516+
screen.queryByTestId('faker-schema-editor-loader')
517+
);
518518

519519
// select the "name" field
520520
userEvent.click(screen.getByText('name'));

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,12 @@ const validateFakerSchema = (
772772

773773
// Process all input schema fields in a single O(n) pass
774774
for (const fieldPath of Object.keys(inputSchema)) {
775-
const fakerMapping = fakerSchemaRaw[fieldPath];
776-
777-
if (fakerMapping) {
775+
if (fakerSchemaRaw[fieldPath]) {
776+
// input schema field exists in faker schema
777+
const fakerMapping = {
778+
...fakerSchemaRaw[fieldPath],
779+
probability: inputSchema[fieldPath].probability,
780+
};
778781
// Validate the faker method
779782
if (isValidFakerMethod(fakerMapping.fakerMethod)) {
780783
result[fieldPath] = fakerMapping;
@@ -789,7 +792,7 @@ const validateFakerSchema = (
789792
mongoType: fakerMapping.mongoType,
790793
fakerMethod: UNRECOGNIZED_FAKER_METHOD,
791794
fakerArgs: [],
792-
probability: inputSchema[fieldPath].probability,
795+
probability: fakerMapping.probability,
793796
};
794797
}
795798
} else {

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,10 @@ describe('AtlasAiService', function () {
393393
name: {
394394
type: 'string',
395395
sampleValues: ['John', 'Jane', 'Bob'],
396-
probability: 0.9,
397396
},
398397
age: {
399398
type: 'number',
400399
sampleValues: [25, 30, 35],
401-
probability: 0.8,
402400
},
403401
},
404402
includeSampleValues: false,
@@ -536,7 +534,6 @@ describe('AtlasAiService', function () {
536534
);
537535
expect(requestBody.schema.age).to.not.have.property('sampleValues');
538536
expect(requestBody.schema.name.type).to.equal('string');
539-
expect(requestBody.schema.age.probability).to.equal(0.8);
540537
});
541538

542539
it('makes POST request with correct headers and body structure', async function () {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ const aiURLConfig = {
218218
export interface MockDataSchemaRawField {
219219
type: string;
220220
sampleValues?: unknown[];
221-
probability?: number;
222221
}
223222

224223
export interface MockDataSchemaRequest {
@@ -475,7 +474,7 @@ export class AtlasAiService {
475474
Omit<MockDataSchemaRawField, 'sampleValues'>
476475
> = {};
477476
for (const [k, v] of Object.entries(schema)) {
478-
newSchema[k] = { type: v.type, probability: v.probability };
477+
newSchema[k] = { type: v.type };
479478
}
480479
schema = newSchema;
481480
}

0 commit comments

Comments
 (0)