Skip to content

Commit

Permalink
code review issues are resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
huseyinbuyukdere committed Feb 13, 2025
1 parent b42f196 commit 4211203
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,9 @@ export const plugin: PluginFunction<TypescriptMocksPluginConfig> = (schema, docu

const { includedTypes, excludedTypes } = config;
const shouldGenerateMockForType = (typeName: string) => {
if (!typeName) {
return true;
}
if (includedTypes && includedTypes.length > 0) {
return includedTypes.includes(typeName);
}
Expand Down
26 changes: 26 additions & 0 deletions tests/__snapshots__/typescript-mock-data.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,32 @@ export const aQuery = (overrides?: Partial<Query>): Query => {
"
`;

exports[`should generate mock data only for included types 1`] = `
"
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : '1550ff93-cd31-49b4-a3c3-8ef1cb68bdc3',
url: overrides && overrides.hasOwnProperty('url') ? overrides.url! : 'consectetur',
};
};

export const aUser = (overrides?: Partial<User>): User => {
return {
id: overrides && overrides.hasOwnProperty('id') ? overrides.id! : 'b5756f00-51a6-422a-81a7-dc13ee6a6375',
creationDate: overrides && overrides.hasOwnProperty('creationDate') ? overrides.creationDate! : '2021-06-27T14:29:24.774Z',
login: overrides && overrides.hasOwnProperty('login') ? overrides.login! : 'sordeo',
avatar: overrides && overrides.hasOwnProperty('avatar') ? overrides.avatar! : anAvatar(),
status: overrides && overrides.hasOwnProperty('status') ? overrides.status! : Status.Online,
customStatus: overrides && overrides.hasOwnProperty('customStatus') ? overrides.customStatus! : AbcStatus.HasXyzStatus,
scalarValue: overrides && overrides.hasOwnProperty('scalarValue') ? overrides.scalarValue! : 'arx',
camelCaseThing: overrides && overrides.hasOwnProperty('camelCaseThing') ? overrides.camelCaseThing! : aCamelCaseThing(),
unionThing: overrides && overrides.hasOwnProperty('unionThing') ? overrides.unionThing! : anAvatar(),
prefixedEnum: overrides && overrides.hasOwnProperty('prefixedEnum') ? overrides.prefixedEnum! : PrefixedEnum.PrefixedValue,
};
};
"
`;

exports[`should generate mock data with PascalCase enum values by default 1`] = `
"
export const anAvatar = (overrides?: Partial<Avatar>): Avatar => {
Expand Down
1 change: 1 addition & 0 deletions tests/typescript-mock-data.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ it('should generate mock data only for included types', async () => {
includedTypes: ['User', 'Avatar'],
});

expect(result).toMatchSnapshot();
expect(result).toBeDefined();
expect(result).toContain('export const aUser');
expect(result).toContain('export const anAvatar');
Expand Down

0 comments on commit 4211203

Please sign in to comment.