-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use generated types and add CustomViewInstallation model
- Loading branch information
Showing
13 changed files
with
160 additions
and
47 deletions.
There are no files selected for viewing
14 changes: 7 additions & 7 deletions
14
models/custom-view/src/custom-view-installation-permission/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
models/custom-view/src/custom-view-installation/custom-view-installation/builder.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TCustomViewInstallation, TCustomViewInstallation>( | ||
'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), | ||
}) | ||
) | ||
); | ||
}); |
15 changes: 15 additions & 0 deletions
15
models/custom-view/src/custom-view-installation/custom-view-installation/builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TCustomViewInstallation>({ | ||
generator, | ||
transformers, | ||
}); | ||
|
||
export default Model; |
24 changes: 24 additions & 0 deletions
24
models/custom-view/src/custom-view-installation/custom-view-installation/generator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TCustomViewInstallation>({ | ||
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; |
3 changes: 3 additions & 0 deletions
3
models/custom-view/src/custom-view-installation/custom-view-installation/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default as random } from './builder'; | ||
export * as presets from './presets'; | ||
export * from './types'; |
3 changes: 3 additions & 0 deletions
3
models/custom-view/src/custom-view-installation/custom-view-installation/presets/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const presets = {}; | ||
|
||
export default presets; |
25 changes: 25 additions & 0 deletions
25
models/custom-view/src/custom-view-installation/custom-view-installation/transformers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Transformer } from '@commercetools-test-data/core'; | ||
import type { | ||
TCustomViewInstallation, | ||
TCustomViewInstallationGraphql, | ||
} from './types'; | ||
|
||
const transformers = { | ||
default: Transformer<TCustomViewInstallation, TCustomViewInstallation>( | ||
'default', | ||
{ | ||
buildFields: ['acceptedPermissions', 'projects'], | ||
} | ||
), | ||
graphql: Transformer<TCustomViewInstallation, TCustomViewInstallationGraphql>( | ||
'graphql', | ||
{ | ||
buildFields: ['acceptedPermissions', 'projects'], | ||
addFields: () => ({ | ||
__typename: 'CustomViewInstallation', | ||
}), | ||
} | ||
), | ||
}; | ||
|
||
export default transformers; |
13 changes: 13 additions & 0 deletions
13
models/custom-view/src/custom-view-installation/custom-view-installation/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TCustomViewInstallation>; | ||
export type TCreateCustomViewInstallationBuilder = | ||
() => TCustomViewInstallationBuilder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Export models | ||
export * as CustomViewInstallation from './custom-view-installation'; | ||
export * as RestrictedCustomViewInstallationForOrganization from './restricted-custom-view-installation-for-organization'; |
27 changes: 7 additions & 20 deletions
27
...rc/custom-view-installation/restricted-custom-view-installation-for-organization/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// Export types | ||
export * from './custom-view-installation/types'; | ||
export * from './restricted-custom-view-installation-for-organization/types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters