Skip to content

Commit

Permalink
feat: changed cuids in MSW to dynamic faker strings to prevent file c… (
Browse files Browse the repository at this point in the history
#980)

* feat: changed cuids in MSW to dynamic faker strings to prevent file changes on each generation

* Update constants.ts

---------

Co-authored-by: Melloware <mellowaredev@gmail.com>
  • Loading branch information
Will-Mann-16 and melloware authored Oct 28, 2023
1 parent d4f17ce commit c1949f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/msw/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ export const DEFAULT_FORMAT_MOCK: Record<
uuid: 'faker.string.uuid()',
zipCode: 'faker.location.zipCode()',
};

// #980 replace CUID so tests are consistent
export const DEFAULT_OBJECT_KEY_MOCK = 'faker.string.alphanumeric(5)';
3 changes: 2 additions & 1 deletion packages/msw/src/getters/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ReferenceObject, SchemaObject } from 'openapi3-ts';
import { resolveMockValue } from '../resolvers/value';
import { MockDefinition, MockSchemaObject } from '../types';
import { combineSchemasMock } from './combine';
import { DEFAULT_OBJECT_KEY_MOCK } from '../constants';

export const getMockObject = ({
item,
Expand Down Expand Up @@ -148,7 +149,7 @@ export const getMockObject = ({
return {
...resolvedValue,
value: `{
'${cuid()}': ${resolvedValue.value}
'[${DEFAULT_OBJECT_KEY_MOCK}]': ${resolvedValue.value}
}`,
};
}
Expand Down

0 comments on commit c1949f4

Please sign in to comment.