-
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
feat(associate-role): create associate role package and model #435
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,6 @@ | ||
--- | ||
'@commercetools-test-data/commons': minor | ||
'@commercetools-test-data/associate-role': minor | ||
--- | ||
|
||
Add Associate Role package |
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,31 @@ | ||
# @commercetools-test-data/associate-role | ||
|
||
This package provides the data model for the commercetools platform `AssociateRole` representations | ||
|
||
https://docs.commercetools.com/api/projects/associate-roles#representations | ||
|
||
# Install | ||
|
||
```bash | ||
$ pnpm add -D @commercetools-test-data/associate-role | ||
``` | ||
|
||
# Usage | ||
|
||
```ts | ||
import { | ||
AssociateRole, | ||
AssociateRoleDraft, | ||
type TAssociateRole, | ||
type TAssociateRoleDraft, | ||
} from '@commercetools-test-data/associate-role'; | ||
|
||
const associateRole = AssociateRole.random().build<TAssociateRole>(); | ||
const AssociateRoleDraft = | ||
AssociateRoleDraft.random().build<TAssociateRoleDraft>(); | ||
|
||
// Presets | ||
const emptyCustomerDraft = AssociateRole.presets | ||
.withAllBusinessUnitPermissions() | ||
.build<TAssociateRole>(); | ||
``` |
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,28 @@ | ||
{ | ||
"name": "@commercetools-test-data/associate-role", | ||
"version": "6.5.0", | ||
"description": "Data model for commercetools API AssociateRole", | ||
"bugs": "https://github.com/commercetools/test-data/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/commercetools/test-data.git", | ||
"directory": "models/associate-role" | ||
}, | ||
"keywords": ["javascript", "typescript", "test-data"], | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "dist/commercetools-test-data-associate-role.cjs.js", | ||
"module": "dist/commercetools-test-data-associate-role.esm.js", | ||
"files": ["dist", "package.json", "LICENSE", "README.md"], | ||
"dependencies": { | ||
"@babel/runtime": "^7.17.9", | ||
"@babel/runtime-corejs3": "^7.17.9", | ||
"@commercetools-test-data/commons": "6.4.2", | ||
"@commercetools-test-data/core": "6.4.2", | ||
"@commercetools-test-data/utils": "6.4.2", | ||
"@commercetools/platform-sdk": "^6.0.0", | ||
"@faker-js/faker": "^8.0.0" | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
models/associate-role/src/associate-role-draft/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,49 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/valid-title */ | ||
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; | ||
import type { TAssociateRoleDraft } from '../types'; | ||
import * as AssociateRoleDraft from './index'; | ||
|
||
describe('builder', () => { | ||
it( | ||
...createBuilderSpec<TAssociateRoleDraft, TAssociateRoleDraft>( | ||
'default', | ||
AssociateRoleDraft.random(), | ||
expect.objectContaining({ | ||
key: expect.any(String), | ||
name: expect.any(String), | ||
buyerAssignable: expect.any(Boolean), | ||
permissions: expect.any(Array), | ||
custom: null, | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TAssociateRoleDraft, TAssociateRoleDraft>( | ||
'rest', | ||
AssociateRoleDraft.random(), | ||
expect.objectContaining({ | ||
key: expect.any(String), | ||
name: expect.any(String), | ||
buyerAssignable: expect.any(Boolean), | ||
permissions: expect.any(Array), | ||
custom: null, | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TAssociateRoleDraft, TAssociateRoleDraft>( | ||
'graphql', | ||
AssociateRoleDraft.random(), | ||
expect.objectContaining({ | ||
key: expect.any(String), | ||
name: expect.any(String), | ||
buyerAssignable: expect.any(Boolean), | ||
permissions: expect.any(Array), | ||
custom: null, | ||
}) | ||
) | ||
); | ||
}); |
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 { Builder } from '@commercetools-test-data/core'; | ||
import { | ||
TAssociateRoleDraft, | ||
TCreateAssociateRoleDraftBuilder, | ||
} from '../types'; | ||
import generator from './generator'; | ||
|
||
const AssociateRoleDraft: TCreateAssociateRoleDraftBuilder = () => | ||
Builder<TAssociateRoleDraft>({ | ||
generator, | ||
}); | ||
|
||
export default AssociateRoleDraft; |
14 changes: 14 additions & 0 deletions
14
models/associate-role/src/associate-role-draft/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,14 @@ | ||
import { fake, Generator } from '@commercetools-test-data/core'; | ||
import { TAssociateRoleDraft } from '../types'; | ||
|
||
const generator = Generator<TAssociateRoleDraft>({ | ||
fields: { | ||
key: fake((f) => f.string.alphanumeric(10)), | ||
name: fake((f) => f.string.alphanumeric(15)), | ||
buyerAssignable: fake((f) => f.datatype.boolean()), | ||
permissions: [], | ||
custom: null, | ||
}, | ||
}); | ||
|
||
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'; |
3 changes: 3 additions & 0 deletions
3
models/associate-role/src/associate-role-draft/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; |
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,80 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/valid-title */ | ||
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; | ||
import type { TAssociateRole, TAssociateRoleGraphql } from './types'; | ||
import * as AssociateRole from './index'; | ||
|
||
describe('builder', () => { | ||
it( | ||
...createBuilderSpec<TAssociateRole, TAssociateRole>( | ||
'default', | ||
AssociateRole.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
createdAt: expect.any(String), | ||
createdBy: expect.objectContaining({ | ||
customer: expect.objectContaining({ typeId: 'customer' }), | ||
}), | ||
lastModifiedAt: expect.any(String), | ||
lastModifiedBy: expect.objectContaining({ | ||
customer: expect.objectContaining({ typeId: 'customer' }), | ||
}), | ||
key: expect.any(String), | ||
name: expect.any(String), | ||
buyerAssignable: expect.any(Boolean), | ||
permissions: expect.any(Array), | ||
custom: null, | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TAssociateRole, TAssociateRole>( | ||
'rest', | ||
AssociateRole.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
createdAt: expect.any(String), | ||
createdBy: expect.objectContaining({ | ||
customer: expect.objectContaining({ typeId: 'customer' }), | ||
}), | ||
lastModifiedAt: expect.any(String), | ||
lastModifiedBy: expect.objectContaining({ | ||
customer: expect.objectContaining({ typeId: 'customer' }), | ||
}), | ||
key: expect.any(String), | ||
name: expect.any(String), | ||
buyerAssignable: expect.any(Boolean), | ||
permissions: expect.any(Array), | ||
custom: null, | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TAssociateRole, TAssociateRoleGraphql>( | ||
'graphql', | ||
AssociateRole.random(), | ||
expect.objectContaining({ | ||
__typename: 'AssociateRole', | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
createdAt: expect.any(String), | ||
createdBy: expect.objectContaining({ | ||
customerRef: expect.objectContaining({ typeId: 'customer' }), | ||
}), | ||
lastModifiedAt: expect.any(String), | ||
lastModifiedBy: expect.objectContaining({ | ||
customerRef: expect.objectContaining({ typeId: 'customer' }), | ||
}), | ||
key: expect.any(String), | ||
name: expect.any(String), | ||
buyerAssignable: expect.any(Boolean), | ||
permissions: expect.any(Array), | ||
custom: null, | ||
}) | ||
) | ||
); | ||
}); |
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 { TAssociateRole, TCreateAssociateRoleBuilder } from './types'; | ||
|
||
const Model: TCreateAssociateRoleBuilder = () => | ||
Builder<TAssociateRole>({ | ||
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,56 @@ | ||
const BUSINESS_UNIT_PERMISSIONS = { | ||
ADD_CHILD_UNITS: 'AddChildUnits', | ||
UPDATE_ASSOCIATES: 'UpdateAssociates', | ||
UPDATE_BUSINESS_UNIT_DETAILS: 'UpdateBusinessUnitDetails', | ||
UPDATE_PARENT_UNIT: 'UpdateParentUnit', | ||
}; | ||
|
||
const CART_PERMISSIONS = { | ||
VIEW_MY_CARTS: 'ViewMyCarts', | ||
CREATE_MY_CARTS: 'CreateMyCarts', | ||
UPDATE_MY_CARTS: 'UpdateMyCarts', | ||
DELETE_MY_CARTS: 'DeleteMyCarts', | ||
VIEW_OTHERS_CARTS: 'ViewOthersCarts', | ||
CREATE_OTHERS_CARTS: 'CreateOthersCarts', | ||
UPDATE_OTHERS_CARTS: 'UpdateOthersCarts', | ||
DELETE_OTHERS_CARTS: 'DeleteOthersCarts', | ||
}; | ||
|
||
const ORDER_PERMISSIONS = { | ||
CREATE_MY_ORDERS_FROM_MY_CARTS: 'CreateMyOrdersFromMyCarts', | ||
CREATE_MY_ORDERS_FROM_MY_QUOTES: 'CreateMyOrdersFromMyQuotes', | ||
UPDATE_MY_ORDERS: 'UpdateMyOrders', | ||
VIEW_MY_ORDERS: 'ViewMyOrders', | ||
CREATE_ORDERS_FROM_OTHERS_CARTS: 'CreateOrdersFromOthersCarts', | ||
CREATE_ORDERS_FROM_OTHERS_QUOTES: 'CreateOrdersFromOthersQuotes', | ||
VIEW_OTHERS_ORDERS: 'ViewOthersOrders', | ||
UPDATE_OTHERS_ORDERS: 'UpdateOthersOrders', | ||
}; | ||
|
||
const QUOTE_PERMISSIONS = { | ||
VIEW_MY_QUOTES: 'ViewMyQuotes', | ||
ACCEPT_MY_QUOTES: 'AcceptMyQuotes', | ||
DECLINE_MY_QUOTES: 'DeclineMyQuotes', | ||
RENEGOTIATE_MY_QUOTES: 'RenegotiateMyQuotes', | ||
VIEW_OTHERS_QUOTES: 'ViewOthersQuotes', | ||
ACCEPT_OTHERS_QUOTES: 'AcceptOthersQuotes', | ||
DECLINE_OTHERS_QUOTES: 'DeclineOthersQuotes', | ||
RENEGOTIATE_OTHERS_QUOTES: 'RenegotiateOthersQuotes', | ||
}; | ||
|
||
const QUOTE_REQUEST_PERMISSIONS = { | ||
CREATE_MY_QUOTE_REQUESTS_FROM_MY_CARTS: 'CreateMyQuoteRequestsFromMyCarts', | ||
VIEW_MY_QUOTE_REQUESTS: 'ViewMyQuoteRequests', | ||
UPDATE_MY_QUOTE_REQUESTS: 'UpdateMyQuoteRequests', | ||
CREATE_QUOTE_REQUESTS_FROM_OTHERS_CARTS: 'CreateQuoteRequestsFromOthersCarts', | ||
VIEW_OTHERS_QUOTE_REQUESTS: 'ViewOthersQuoteRequests', | ||
UPDATE_OTHERS_QUOTE_REQUESTS: 'UpdateOthersQuoteRequests', | ||
}; | ||
|
||
export { | ||
BUSINESS_UNIT_PERMISSIONS, | ||
CART_PERMISSIONS, | ||
ORDER_PERMISSIONS, | ||
QUOTE_PERMISSIONS, | ||
QUOTE_REQUEST_PERMISSIONS, | ||
}; |
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 { ClientLogging } from '@commercetools-test-data/commons'; | ||
import { fake, Generator, sequence } from '@commercetools-test-data/core'; | ||
import { createRelatedDates } from '@commercetools-test-data/utils'; | ||
import { TAssociateRole } from './types'; | ||
|
||
const [getOlderDate, getNewerDate] = createRelatedDates(); | ||
|
||
const generator = Generator<TAssociateRole>({ | ||
fields: { | ||
id: fake((f) => f.string.uuid()), | ||
version: sequence(), | ||
key: fake((f) => f.string.alphanumeric(10)), | ||
buyerAssignable: fake((f) => f.datatype.boolean()), | ||
name: fake((f) => f.string.alphanumeric(15)), | ||
permissions: [], | ||
custom: null, | ||
createdAt: fake(getOlderDate), | ||
createdBy: fake(() => ClientLogging.random()), | ||
lastModifiedAt: fake(getNewerDate), | ||
lastModifiedBy: fake(() => ClientLogging.random()), | ||
}, | ||
}); | ||
|
||
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,7 @@ | ||
export * as AssociateRoleDraft from './associate-role-draft'; | ||
export * as AssociateRole from '.'; | ||
|
||
export { default as random } from './builder'; | ||
export * as presets from './presets'; | ||
export * as constants from './constants'; | ||
export * from './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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { default as withAllBusinessUnitPermissions } from './with-all-business-unit-permissions'; | ||
import { default as withAllCartPermissions } from './with-all-cart-permissions'; | ||
import { default as withAllOrderPermissions } from './with-all-order-permissions'; | ||
import { default as withAllQuotePermissions } from './with-all-quote-permissions'; | ||
import { default as withAllQuoteRequestPermissions } from './with-all-quote-request-permissions'; | ||
import { default as withMyCartPermissions } from './with-my-cart-permissions'; | ||
import { default as withMyOrderPermissions } from './with-my-order-permissions'; | ||
import { default as withMyQuotePermissions } from './with-my-quote-permissions'; | ||
import { default as withMyQuoteRequestPermissions } from './with-my-quote-request-permissions'; | ||
|
||
export { | ||
withAllBusinessUnitPermissions, | ||
withAllCartPermissions, | ||
withAllOrderPermissions, | ||
withAllQuotePermissions, | ||
withAllQuoteRequestPermissions, | ||
withMyCartPermissions, | ||
withMyOrderPermissions, | ||
withMyQuotePermissions, | ||
withMyQuoteRequestPermissions, | ||
}; |
12 changes: 12 additions & 0 deletions
12
models/associate-role/src/presets/with-all-business-unit-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,12 @@ | ||
import AssociateRole from '../builder'; | ||
import { BUSINESS_UNIT_PERMISSIONS } from '../constants'; | ||
|
||
const withAllBusinessUnitPermissions = () => | ||
AssociateRole().permissions([ | ||
BUSINESS_UNIT_PERMISSIONS.ADD_CHILD_UNITS, | ||
BUSINESS_UNIT_PERMISSIONS.UPDATE_ASSOCIATES, | ||
BUSINESS_UNIT_PERMISSIONS.UPDATE_BUSINESS_UNIT_DETAILS, | ||
BUSINESS_UNIT_PERMISSIONS.UPDATE_PARENT_UNIT, | ||
]); | ||
|
||
export default withAllBusinessUnitPermissions; |
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.
💯
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.
I think we're missing a draft transformer?