-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new model for Merchant Center CustomView
entity
#384
Merged
Merged
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
935ebe6
feat: add new model for merchant center custom views
CarlosCortizasCT d7d9017
refactor: update dependencies lock file
CarlosCortizasCT e47d046
refactor: improce tests names
CarlosCortizasCT 9dcc7d0
refactor(custom-view): create new internal model for custom views per…
CarlosCortizasCT d146911
refactor(custom-view): refactor draft model
CarlosCortizasCT 7582606
fix(custom-views): models setup and tests
emmenko f8b6907
docs: changesets
emmenko 39462a7
refactor(custom-views): rename model to CustomViewTypeSettingsForCust…
emmenko fb48612
refactor(custom-views): minor improvements
emmenko 1c6e74d
fix(models): fix custom view draft model import
CarlosCortizasCT 6055940
chore: update app-kit dependencies
CarlosCortizasCT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,14 @@ | ||
--- | ||
'@commercetools-test-data/custom-view': minor | ||
--- | ||
|
||
New package to generate test data for Custom Views. | ||
|
||
```ts | ||
import { | ||
CustomView, | ||
type TCustomViewGraphql, | ||
} from '@commercetools-test-data/custom-view'; | ||
|
||
const customView = CustomView.random().buildGraphql<TCustomViewGraphql>(); | ||
``` |
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,5 @@ | ||
--- | ||
'@commercetools-test-data/commons': minor | ||
--- | ||
|
||
Add new model `LocalizedField` |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/valid-title */ | ||
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; | ||
import type { TLocalizedField, TLocalizedFieldGraphql } from './types'; | ||
import * as LocalizedField from './index'; | ||
|
||
describe('builder', () => { | ||
it( | ||
...createBuilderSpec<TLocalizedField, TLocalizedField>( | ||
'default', | ||
LocalizedField.random(), | ||
expect.objectContaining({ | ||
locale: expect.stringMatching(/^(de|en|es)$/), | ||
value: expect.any(String), | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TLocalizedField, TLocalizedFieldGraphql>( | ||
'graphql', | ||
LocalizedField.random(), | ||
expect.objectContaining({ | ||
__typename: 'LocalizedField', | ||
locale: expect.stringMatching(/^(de|en|es)$/), | ||
value: expect.any(String), | ||
}) | ||
) | ||
); | ||
}); |
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,12 @@ | ||
import { Builder } from '@commercetools-test-data/core'; | ||
import generator from './generator'; | ||
import transformers from './transformers'; | ||
import type { TCreateLocalizedFieldBuilder, TLocalizedField } from './types'; | ||
|
||
const Model: TCreateLocalizedFieldBuilder = () => | ||
Builder<TLocalizedField>({ | ||
generator, | ||
transformers, | ||
}); | ||
|
||
export default Model; |
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,16 @@ | ||
import { Generator, fake } from '@commercetools-test-data/core'; | ||
import type { TLocalizedField } from './types'; | ||
|
||
const generator = Generator<TLocalizedField>({ | ||
fields: { | ||
locale: fake((f) => f.helpers.arrayElement(['en', 'de', 'es'])), | ||
value: fake((f) => | ||
f.lorem.words({ | ||
min: 1, | ||
max: 4, | ||
}) | ||
), | ||
}, | ||
}); | ||
|
||
export default generator; |
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,2 @@ | ||
export { default as random } from './builder'; | ||
export { default as presets } from './presets'; |
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; |
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 { Transformer } from '@commercetools-test-data/core'; | ||
import type { TLocalizedField, TLocalizedFieldGraphql } from './types'; | ||
|
||
const transformers = { | ||
default: Transformer<TLocalizedField, TLocalizedField>('default', {}), | ||
graphql: Transformer<TLocalizedField, TLocalizedFieldGraphql>('graphql', { | ||
addFields: () => ({ | ||
__typename: 'LocalizedField', | ||
}), | ||
}), | ||
}; | ||
|
||
export default transformers; |
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,12 @@ | ||
import type { TBuilder } from '@commercetools-test-data/core'; | ||
|
||
export type TLocalizedField = { | ||
locale: string; | ||
value: string; | ||
}; | ||
export type TLocalizedFieldGraphql = TLocalizedField & { | ||
__typename: 'LocalizedField'; | ||
}; | ||
|
||
export type TLocalizedFieldBuilder = TBuilder<TLocalizedField>; | ||
export type TCreateLocalizedFieldBuilder = () => TLocalizedFieldBuilder; |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) commercetools GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 @@ | ||
# @commercetools-test-data/custom-view | ||
|
||
This package provides the data model for the commercetools internal API `CustomView` type | ||
|
||
# Install | ||
|
||
```bash | ||
$ pnpm add -D @commercetools-test-data/custom-view | ||
``` | ||
|
||
# Usage | ||
|
||
```ts | ||
import { | ||
CustomView, | ||
CustomViewDraft, | ||
type TCustomViewGraphql, | ||
type TCustomViewDraftGraphql, | ||
} from '@commercetools-test-data/custom-view'; | ||
|
||
const customView = CustomView.random().buildGraphql<TCustomViewGraphql>(); | ||
const customViewDraft = | ||
CustomViewDraft.random().buildGraphql<TCustomViewDraftGraphql>(); | ||
``` |
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,32 @@ | ||
{ | ||
"name": "@commercetools-test-data/custom-view", | ||
"version": "6.0.0", | ||
"description": "Data model for internal Merchan Center API Custom View", | ||
"bugs": "https://github.com/commercetools/test-data/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/commercetools/test-data.git", | ||
"directory": "models/custom-view" | ||
}, | ||
"keywords": ["javascript", "typescript", "test-data"], | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "dist/commercetools-test-data-custom-view.cjs.js", | ||
"module": "dist/commercetools-test-data-custom-view.esm.js", | ||
"files": ["dist", "package.json", "LICENSE", "README.md"], | ||
"dependencies": { | ||
"@babel/runtime": "^7.17.9", | ||
"@babel/runtime-corejs3": "^7.17.9", | ||
"@commercetools-frontend/application-config": "^22.9.1", | ||
"@commercetools-frontend/constants": "^22.9.1", | ||
"@commercetools-test-data/commons": "6.3.8", | ||
"@commercetools-test-data/core": "6.3.8", | ||
"@commercetools-test-data/utils": "6.3.8", | ||
"@commercetools/platform-sdk": "^6.0.0", | ||
"@faker-js/faker": "^8.0.0", | ||
"@types/lodash": "^4.14.182", | ||
"lodash": "^4.17.21" | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
models/custom-view/src/custom-view-permission/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,47 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/valid-title */ | ||
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; | ||
import type { | ||
TCustomViewPermission, | ||
TCustomViewPermissionGraphql, | ||
} from './types'; | ||
import * as CustomViewPermissionModel from './index'; | ||
|
||
describe('CustomView model builder', () => { | ||
it( | ||
...createBuilderSpec<TCustomViewPermission, TCustomViewPermission>( | ||
'default', | ||
CustomViewPermissionModel.random(), | ||
expect.objectContaining({ | ||
name: 'view', | ||
oAuthScopes: expect.arrayContaining([expect.stringMatching(/^view_/)]), | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TCustomViewPermission, TCustomViewPermissionGraphql>( | ||
'graphql', | ||
CustomViewPermissionModel.presets.ViewOnlyPermissions(), | ||
expect.objectContaining({ | ||
__typename: 'CustomViewPermission', | ||
name: 'view', | ||
oAuthScopes: expect.arrayContaining([expect.stringMatching(/^view_/)]), | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TCustomViewPermission, TCustomViewPermissionGraphql>( | ||
'graphql', | ||
CustomViewPermissionModel.presets.ManageOnlyPermissions(), | ||
expect.objectContaining({ | ||
__typename: 'CustomViewPermission', | ||
name: 'manage', | ||
oAuthScopes: expect.arrayContaining([ | ||
expect.stringMatching(/^manage_/), | ||
]), | ||
}) | ||
) | ||
); | ||
}); |
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 { | ||
TCustomViewPermission, | ||
TCreateCustomViewPermissionBuilder, | ||
} from './types'; | ||
|
||
const Model: TCreateCustomViewPermissionBuilder = () => | ||
Builder<TCustomViewPermission>({ | ||
generator, | ||
transformers, | ||
}); | ||
|
||
export default Model; |
54 changes: 54 additions & 0 deletions
54
models/custom-view/src/custom-view-permission/constants.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,54 @@ | ||
export const supportedViewOAuthScopes = [ | ||
'view_api_clients', | ||
'view_audit_log', | ||
'view_cart_discounts', | ||
'view_categories', | ||
'view_customer_groups', | ||
'view_customers', | ||
'view_discount_codes', | ||
'view_import_containers', | ||
'view_key_value_documents', | ||
'view_messages', | ||
'view_order_edits', | ||
'view_orders', | ||
'view_payments', | ||
'view_products', | ||
'view_project_settings', | ||
'view_published_products', | ||
'view_shipping_methods', | ||
'view_shopping_lists', | ||
'view_states', | ||
'view_stores', | ||
'view_tax_categories', | ||
'view_types', | ||
]; | ||
|
||
export const supportedManageOAuthScopes = [ | ||
'manage_api_clients', | ||
'manage_audit_log', | ||
'manage_cart_discounts', | ||
'manage_categories', | ||
'manage_customer_groups', | ||
'manage_customers', | ||
'manage_discount_codes', | ||
'manage_extensions', | ||
'manage_import_containers', | ||
'manage_key_value_documents', | ||
'manage_order_edits', | ||
'manage_orders', | ||
'manage_payments', | ||
'manage_products', | ||
'manage_project_settings', | ||
'manage_shipping_methods', | ||
'manage_shopping_lists', | ||
'manage_states', | ||
'manage_stores', | ||
'manage_subscriptions', | ||
'manage_tax_categories', | ||
'manage_types', | ||
]; | ||
|
||
export const supportedOAuthScopes = [ | ||
...supportedViewOAuthScopes, | ||
...supportedManageOAuthScopes, | ||
]; |
13 changes: 13 additions & 0 deletions
13
models/custom-view/src/custom-view-permission/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,13 @@ | ||
import { Generator } from '@commercetools-test-data/core'; | ||
import sampleSize from 'lodash/sampleSize'; | ||
import { supportedViewOAuthScopes } from './constants'; | ||
import type { TCustomViewPermission } from './types'; | ||
|
||
const generator = Generator<TCustomViewPermission>({ | ||
fields: { | ||
name: 'view', | ||
oAuthScopes: sampleSize(supportedViewOAuthScopes, 2), | ||
}, | ||
}); | ||
|
||
export default generator; |
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'; |
4 changes: 4 additions & 0 deletions
4
models/custom-view/src/custom-view-permission/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,4 @@ | ||
import ManageOnlyPermissions from './manage-only-permissions'; | ||
import ViewOnlyPermissions from './view-only-permissions'; | ||
|
||
export { ViewOnlyPermissions, ManageOnlyPermissions }; |
26 changes: 26 additions & 0 deletions
26
models/custom-view/src/custom-view-permission/presets/manage-only-permissions.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,26 @@ | ||
import { entryPointUriPathToResourceAccesses } from '@commercetools-frontend/application-config/ssr'; | ||
import { CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH } from '@commercetools-frontend/constants'; | ||
import camelCase from 'lodash/camelCase'; | ||
import sampleSize from 'lodash/sampleSize'; | ||
import upperFirst from 'lodash/upperFirst'; | ||
import CustomApplicationPermission from '../builder'; | ||
import { supportedManageOAuthScopes } from '../constants'; | ||
|
||
const preset = (additionalPermission = '') => { | ||
const resourceAccesses = entryPointUriPathToResourceAccesses( | ||
CUSTOM_VIEW_HOST_ENTRY_POINT_URI_PATH, | ||
[additionalPermission] | ||
); | ||
return CustomApplicationPermission() | ||
.name( | ||
!additionalPermission | ||
? resourceAccesses.manage | ||
: // @ts-ignore | ||
resourceAccesses[ | ||
`manage${upperFirst(camelCase(additionalPermission))}` | ||
] | ||
) | ||
.oAuthScopes(sampleSize(supportedManageOAuthScopes, 1)); | ||
}; | ||
|
||
export default preset; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℹ️ This requires the change in App Kit to be released: commercetools/merchant-center-application-kit#3272