Skip to content
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 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/olive-shoes-kiss.md
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
21 changes: 21 additions & 0 deletions models/associate-role/LICENSE
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.
31 changes: 31 additions & 0 deletions models/associate-role/README.md
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>();
```
28 changes: 28 additions & 0 deletions models/associate-role/package.json
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 models/associate-role/src/associate-role-draft/builder.spec.ts
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,
})
)
);
});
13 changes: 13 additions & 0 deletions models/associate-role/src/associate-role-draft/builder.ts
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 models/associate-role/src/associate-role-draft/generator.ts
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,
},
});
Comment on lines +4 to +12
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Copy link
Contributor

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?


export default generator;
2 changes: 2 additions & 0 deletions models/associate-role/src/associate-role-draft/index.ts
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';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const presets = {};

export default presets;
80 changes: 80 additions & 0 deletions models/associate-role/src/builder.spec.ts
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,
})
)
);
});
12 changes: 12 additions & 0 deletions models/associate-role/src/builder.ts
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;
56 changes: 56 additions & 0 deletions models/associate-role/src/constants.ts
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,
};
24 changes: 24 additions & 0 deletions models/associate-role/src/generator.ts
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;
7 changes: 7 additions & 0 deletions models/associate-role/src/index.ts
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';
21 changes: 21 additions & 0 deletions models/associate-role/src/presets/index.ts
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,
};
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;
Loading
Loading