diff --git a/models/custom-view/src/custom-view-installation-permission/types.ts b/models/custom-view/src/custom-view-installation-permission/types.ts index 144f4c2a3..23cf6b228 100644 --- a/models/custom-view/src/custom-view-installation-permission/types.ts +++ b/models/custom-view/src/custom-view-installation-permission/types.ts @@ -1,13 +1,13 @@ import type { TBuilder } from '@commercetools-test-data/core'; +import type { TMcSettingsCustomViewInstallationPermission } from '../../../../graphql-types'; -export type TCustomViewInstallationPermission = { - name: string; - oAuthScopes: string[]; -}; export type TCustomViewInstallationPermissionGraphql = - TCustomViewInstallationPermission & { - __typename: 'CustomViewInstallationPermission'; - }; + TMcSettingsCustomViewInstallationPermission; + +export type TCustomViewInstallationPermission = Omit< + TCustomViewInstallationPermissionGraphql, + '__typename' +>; export type TCustomViewInstallationPermissionBuilder = TBuilder; diff --git a/models/custom-view/src/custom-view-installation/custom-view-installation/builder.spec.ts b/models/custom-view/src/custom-view-installation/custom-view-installation/builder.spec.ts new file mode 100644 index 000000000..9a306b5fa --- /dev/null +++ b/models/custom-view/src/custom-view-installation/custom-view-installation/builder.spec.ts @@ -0,0 +1,57 @@ +/* eslint-disable jest/no-disabled-tests */ +/* eslint-disable jest/valid-title */ +import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; +import type { + TCustomViewInstallation, + TCustomViewInstallationGraphql, +} from './types'; +import * as CustomViewInstallationModel from './index'; + +describe('builder', () => { + it( + ...createBuilderSpec( + 'default', + CustomViewInstallationModel.random(), + expect.objectContaining({ + id: expect.any(String), + createdAt: expect.any(String), + updatedAt: expect.any(String), + acceptedPermissions: expect.arrayContaining([ + expect.objectContaining({ + name: expect.stringMatching(/^(view|manage)$/), + oAuthScopes: expect.arrayContaining([expect.any(String)]), + }), + ]), + installInAllProjects: expect.any(Boolean), + projects: expect.any(Array), + ownerId: expect.any(String), + owner: expect.any(Object), + }) + ) + ); + it( + ...createBuilderSpec< + TCustomViewInstallation, + TCustomViewInstallationGraphql + >( + 'graphql', + CustomViewInstallationModel.random(), + expect.objectContaining({ + __typename: 'CustomViewInstallation', + id: expect.any(String), + createdAt: expect.any(String), + updatedAt: expect.any(String), + acceptedPermissions: expect.arrayContaining([ + expect.objectContaining({ + name: expect.stringMatching(/^(view|manage)$/), + oAuthScopes: expect.arrayContaining([expect.any(String)]), + }), + ]), + installInAllProjects: expect.any(Boolean), + projects: expect.any(Array), + ownerId: expect.any(String), + owner: expect.any(Object), + }) + ) + ); +}); diff --git a/models/custom-view/src/custom-view-installation/custom-view-installation/builder.ts b/models/custom-view/src/custom-view-installation/custom-view-installation/builder.ts new file mode 100644 index 000000000..903afaab4 --- /dev/null +++ b/models/custom-view/src/custom-view-installation/custom-view-installation/builder.ts @@ -0,0 +1,15 @@ +import { Builder } from '@commercetools-test-data/core'; +import generator from './generator'; +import transformers from './transformers'; +import type { + TCustomViewInstallation, + TCreateCustomViewInstallationBuilder, +} from './types'; + +const Model: TCreateCustomViewInstallationBuilder = () => + Builder({ + generator, + transformers, + }); + +export default Model; diff --git a/models/custom-view/src/custom-view-installation/custom-view-installation/generator.ts b/models/custom-view/src/custom-view-installation/custom-view-installation/generator.ts new file mode 100644 index 000000000..8fba71278 --- /dev/null +++ b/models/custom-view/src/custom-view-installation/custom-view-installation/generator.ts @@ -0,0 +1,24 @@ +import { fake, Generator } from '@commercetools-test-data/core'; +import { createRelatedDates } from '@commercetools-test-data/utils'; +import * as CustomViewInstallationPermission from '../../custom-view-installation-permission'; +import type { TCustomViewInstallation } from './types'; + +const [getOlderDate, getNewerDate] = createRelatedDates(); + +const generator = Generator({ + fields: { + id: fake((f) => f.string.uuid()), + createdAt: fake(getOlderDate), + updatedAt: fake(getNewerDate), + acceptedPermissions: fake(() => [ + CustomViewInstallationPermission.presets.ViewOnlyPermissions(), + CustomViewInstallationPermission.presets.ManageOnlyPermissions(), + ]), + projects: fake(() => []), + installInAllProjects: fake((f) => f.datatype.boolean()), + owner: fake(() => ({})), + ownerId: fake((f) => f.string.uuid()), + }, +}); + +export default generator; diff --git a/models/custom-view/src/custom-view-installation/custom-view-installation/index.ts b/models/custom-view/src/custom-view-installation/custom-view-installation/index.ts new file mode 100644 index 000000000..153b04270 --- /dev/null +++ b/models/custom-view/src/custom-view-installation/custom-view-installation/index.ts @@ -0,0 +1,3 @@ +export { default as random } from './builder'; +export * as presets from './presets'; +export * from './types'; diff --git a/models/custom-view/src/custom-view-installation/custom-view-installation/presets/index.ts b/models/custom-view/src/custom-view-installation/custom-view-installation/presets/index.ts new file mode 100644 index 000000000..763e57fe0 --- /dev/null +++ b/models/custom-view/src/custom-view-installation/custom-view-installation/presets/index.ts @@ -0,0 +1,3 @@ +const presets = {}; + +export default presets; diff --git a/models/custom-view/src/custom-view-installation/custom-view-installation/transformers.ts b/models/custom-view/src/custom-view-installation/custom-view-installation/transformers.ts new file mode 100644 index 000000000..e2ebd4c36 --- /dev/null +++ b/models/custom-view/src/custom-view-installation/custom-view-installation/transformers.ts @@ -0,0 +1,25 @@ +import { Transformer } from '@commercetools-test-data/core'; +import type { + TCustomViewInstallation, + TCustomViewInstallationGraphql, +} from './types'; + +const transformers = { + default: Transformer( + 'default', + { + buildFields: ['acceptedPermissions', 'projects'], + } + ), + graphql: Transformer( + 'graphql', + { + buildFields: ['acceptedPermissions', 'projects'], + addFields: () => ({ + __typename: 'CustomViewInstallation', + }), + } + ), +}; + +export default transformers; diff --git a/models/custom-view/src/custom-view-installation/custom-view-installation/types.ts b/models/custom-view/src/custom-view-installation/custom-view-installation/types.ts new file mode 100644 index 000000000..68cceda0f --- /dev/null +++ b/models/custom-view/src/custom-view-installation/custom-view-installation/types.ts @@ -0,0 +1,13 @@ +import type { TBuilder } from '@commercetools-test-data/core'; +import type { TMcSettingsCustomViewInstallation } from '../../../../../graphql-types'; + +export type TCustomViewInstallationGraphql = TMcSettingsCustomViewInstallation; + +export type TCustomViewInstallation = Omit< + TCustomViewInstallationGraphql, + '__typename' +>; + +export type TCustomViewInstallationBuilder = TBuilder; +export type TCreateCustomViewInstallationBuilder = + () => TCustomViewInstallationBuilder; diff --git a/models/custom-view/src/custom-view-installation/index.ts b/models/custom-view/src/custom-view-installation/index.ts index d18a01a1d..42d3b3863 100644 --- a/models/custom-view/src/custom-view-installation/index.ts +++ b/models/custom-view/src/custom-view-installation/index.ts @@ -1,2 +1,3 @@ // Export models +export * as CustomViewInstallation from './custom-view-installation'; export * as RestrictedCustomViewInstallationForOrganization from './restricted-custom-view-installation-for-organization'; diff --git a/models/custom-view/src/custom-view-installation/restricted-custom-view-installation-for-organization/types.ts b/models/custom-view/src/custom-view-installation/restricted-custom-view-installation-for-organization/types.ts index 073f2128b..b4b0ef229 100644 --- a/models/custom-view/src/custom-view-installation/restricted-custom-view-installation-for-organization/types.ts +++ b/models/custom-view/src/custom-view-installation/restricted-custom-view-installation-for-organization/types.ts @@ -1,26 +1,13 @@ import type { TBuilder } from '@commercetools-test-data/core'; -import type { TCustomView } from '../../custom-view'; -import type { TCustomViewInstallationPermission } from '../../custom-view-installation-permission/types'; - -// TODO: generate graphql types and use those -type ProjectExtension = { - projectKey: string; -}; - -export type TRestrictedCustomViewInstallationForOrganization = { - acceptedPermissions: TCustomViewInstallationPermission[]; - createdAt: string; - customView: TCustomView; - id: string; - installInAllProjects: boolean; - projects: ProjectExtension[]; - updatedAt: string; -}; +import type { TMcSettingsRestrictedCustomViewInstallationForOrganization } from '../../../../../graphql-types'; export type TRestrictedCustomViewInstallationForOrganizationGraphql = - TRestrictedCustomViewInstallationForOrganization & { - __typename: 'RestrictedCustomViewInstallationForOrganization'; - }; + TMcSettingsRestrictedCustomViewInstallationForOrganization; + +export type TRestrictedCustomViewInstallationForOrganization = Omit< + TMcSettingsRestrictedCustomViewInstallationForOrganization, + '__typename' +>; export type TRestrictedCustomViewInstallationForOrganizationBuilder = TBuilder; diff --git a/models/custom-view/src/custom-view-installation/types.ts b/models/custom-view/src/custom-view-installation/types.ts index 4e2bbc669..0ad0feb2e 100644 --- a/models/custom-view/src/custom-view-installation/types.ts +++ b/models/custom-view/src/custom-view-installation/types.ts @@ -1,2 +1,3 @@ // Export types +export * from './custom-view-installation/types'; export * from './restricted-custom-view-installation-for-organization/types'; diff --git a/models/custom-view/src/custom-view/types.ts b/models/custom-view/src/custom-view/types.ts index 26af9d266..985aa8618 100644 --- a/models/custom-view/src/custom-view/types.ts +++ b/models/custom-view/src/custom-view/types.ts @@ -23,25 +23,6 @@ type CustomViewPermission = { oAuthScopes: string[]; }; -export type CustomViewInstallationPermission = { - createdAt: string; - id: string; - name: string; - oAuthScopes: string[]; - updatedAt: string; -}; - -export type CustomViewInstallation = { - acceptedPermissions: CustomViewInstallationPermission[]; - createdAt: string; - id: string; - installInAllProjects: boolean; - // owner: OrganizationExtension; - ownerId: string; - // projects: ProjectExtension[]; - updatedAt: string; -}; - export type TCustomView = { id: string; // owner: OrganizationExtension; diff --git a/models/custom-view/src/index.ts b/models/custom-view/src/index.ts index 76c55e652..68415577a 100644 --- a/models/custom-view/src/index.ts +++ b/models/custom-view/src/index.ts @@ -17,5 +17,8 @@ export * as CustomViewPermission from './custom-view-permission'; export * as CustomViewPermissionDraft from './custom-view-permission-draft'; export * as CustomViewTypeSettingsForCustomPanel from './custom-view-type-settings-for-custom-panel'; -export { RestrictedCustomViewInstallationForOrganization } from './custom-view-installation'; +export { + RestrictedCustomViewInstallationForOrganization, + CustomViewInstallation, +} from './custom-view-installation'; export * as CustomViewInstallationPermission from './custom-view-installation-permission';