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

Pangolin 3184: staged quote model #433

Merged
merged 8 commits into from
Nov 21, 2023
6 changes: 6 additions & 0 deletions .changeset/rude-colts-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@commercetools-test-data/quote-request': minor
'@commercetools-test-data/staged-quote': patch
---

feat(staged quote) add test data package for staged quote model
9 changes: 4 additions & 5 deletions models/quote-request/src/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('builder', () => {
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
quoteRequestState: expect.any(String),
comment: null,
customer: expect.objectContaining({
email: expect.any(String),
Expand Down Expand Up @@ -70,9 +71,8 @@ describe('builder', () => {
directDiscounts: expect.arrayContaining([]),
state: null,
cart: expect.objectContaining({
cartState: expect.any(String),
typeId: 'cart',
}),

businessUnit: expect.objectContaining({
id: expect.any(String),
key: expect.any(String),
Expand All @@ -98,6 +98,7 @@ describe('builder', () => {
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
quoteRequestState: expect.any(String),
comment: null,
customer: expect.objectContaining({
id: expect.any(String),
Expand Down Expand Up @@ -174,6 +175,7 @@ describe('builder', () => {
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
quoteRequestState: expect.any(String),
comment: null,
customer: expect.objectContaining({
email: expect.any(String),
Expand Down Expand Up @@ -238,9 +240,6 @@ describe('builder', () => {
directDiscounts: expect.arrayContaining([]),
state: null,
stateRef: undefined,
cart: expect.objectContaining({
cartState: expect.any(String),
}),
cartRef: expect.objectContaining({
typeId: 'cart',
__typename: 'Reference',
Expand Down
5 changes: 3 additions & 2 deletions models/quote-request/src/generator.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Company } from '@commercetools-test-data/business-unit';
import { Cart, LineItem } from '@commercetools-test-data/cart';
import { LineItem } from '@commercetools-test-data/cart';
import {
CentPrecisionMoney,
ClientLogging,
Address,
Reference,
} from '@commercetools-test-data/commons';
import {
sequence,
Expand Down Expand Up @@ -56,7 +57,7 @@ const generator = Generator<TQuoteRequest>({
directDiscounts: [],
state: null,
purchaseOrderNumber: null,
cart: fake(() => Cart.random()),
cart: fake(() => Reference.random().typeId('cart')),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This fixes an error I made in building the graphql data for QuoteRequest, cart is the only field that only returns a Reference, and not the full data, i.e. the graphql api returns a cartRef field, but does not return cart
Screenshot 2023-11-21 at 10 28 05 AM

businessUnit: fake(() => Company.random()),
custom: null,
createdAt: fake(getOlderDate),
Expand Down
4 changes: 2 additions & 2 deletions models/quote-request/src/quote-request-draft/generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Reference } from '@commercetools-test-data/commons';
import { fake, Generator } from '@commercetools-test-data/core';
import { fake, Generator, sequence } from '@commercetools-test-data/core';
import { TQuoteRequestDraft } from '../types';

// https://docs.commercetools.com/api/projects/quote-requests#quoterequestdraft
Expand All @@ -8,7 +8,7 @@ const generator = Generator<TQuoteRequestDraft>({
fields: {
key: fake((f) => f.lorem.slug(2)),
cart: fake(() => Reference.random().typeId('cart')),
cartVersion: fake((f) => f.number.int()),
cartVersion: sequence(),
comment: null,
state: null,
purchaseOrderNumber: null,
Expand Down
15 changes: 5 additions & 10 deletions models/quote-request/src/transformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ const transformers = {
.id(fields.state?.id)
.build<TReference<'state'>>();

const cart = Reference.presets.cartReference
.cartReference()
.id(fields.cart?.id)
.build<TReference<'cart'>>();

const businessUnit = KeyReference.random()
.typeId('business-unit')
.key(fields.businessUnit?.key)
Expand All @@ -89,7 +84,6 @@ const transformers = {
customerGroup: fields.customerGroup ? customerGroup : undefined,
store: fields.store ? store : undefined,
state: fields.state ? state : undefined,
cart: fields.cart ? cart : undefined,
businessUnit: fields.businessUnit ? businessUnit : undefined,
};
},
Expand Down Expand Up @@ -152,14 +146,15 @@ const transformers = {

return {
customerRef,
customerGroupRef,
storeRef,
customerGroupRef: fields.customerGroup ? customerGroupRef : undefined,
storeRef: fields.store ? storeRef : undefined,
stateRef: fields.state ? stateRef : undefined,
cartRef,
businessUnitRef,
cartRef: fields.cart ? cartRef : undefined,
businessUnitRef: fields.businessUnit ? businessUnitRef : undefined,
__typename: 'QuoteRequest',
};
},
removeFields: ['cart'],
}),
};

Expand Down
3 changes: 1 addition & 2 deletions models/quote-request/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ import type { TBuilder } from '@commercetools-test-data/core';
// Default
export type TQuoteRequest = Omit<
QuoteRequest,
'customer' | 'customerGroup' | 'store' | 'state' | 'cart' | 'businessUnit'
'customer' | 'customerGroup' | 'store' | 'state' | 'businessUnit'
> & {
customer: Customer;
customerGroup: CustomerGroup;
store: Store;
state: State;
cart: Cart;
businessUnit: BusinessUnit;
};

Expand Down
21 changes: 21 additions & 0 deletions models/staged-quote/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.
25 changes: 25 additions & 0 deletions models/staged-quote/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @commercetools-test-data/quote

This package provides the data model for the commercetools platform `StagedQuote` type

https://docs.commercetools.com/api/projects/staged-quotes

# Install

```bash
$ pnpm add -D @commercetools-test-data/staged-quote
```

# Usage

```ts
import {
StagedQuote,
StagedQuoteDraft,
type TStagedQuote,
type TStagedQuoteDraft,
} from '@commercetools-test-data/quote-request';

const stagedQuote = StagedQuote.random().build<TStagedQuote>();
const stagedQuoteDraft = StagedQuoteDraft.random().build<TStagedQuoteDraft>();
```
34 changes: 34 additions & 0 deletions models/staged-quote/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "@commercetools-test-data/staged-quote",
"version": "6.5.0",
"description": "Data model for commercetools API StagedQuote",
"bugs": "https://github.com/commercetools/test-data/issues",
"repository": {
"type": "git",
"url": "https://github.com/commercetools/test-data.git",
"directory": "models/quote"
},
"keywords": ["javascript", "typescript", "test-data"],
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "dist/commercetools-test-data-staged-quote.cjs.js",
"module": "dist/commercetools-test-data-staged-quote.esm.js",
"files": ["dist", "package.json", "LICENSE", "README.md"],
"dependencies": {
"@babel/runtime": "^7.17.9",
"@babel/runtime-corejs3": "^7.17.9",
"@commercetools-test-data/business-unit": "6.5.0",
"@commercetools-test-data/cart": "6.5.0",
"@commercetools-test-data/commons": "6.5.0",
"@commercetools-test-data/core": "6.5.0",
"@commercetools-test-data/customer": "6.5.0",
"@commercetools-test-data/customer-group": "6.5.0",
"@commercetools-test-data/quote-request": "6.5.0",
"@commercetools-test-data/store": "6.5.0",
"@commercetools-test-data/utils": "6.5.0",
"@commercetools/platform-sdk": "^6.0.0",
"@faker-js/faker": "^8.0.0"
}
}
149 changes: 149 additions & 0 deletions models/staged-quote/src/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/* eslint-disable jest/valid-title */
/* eslint-disable jest/no-disabled-tests */

import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import type {
TStagedQuote,
TStagedQuoteRest,
TStagedQuoteGraphql,
} from './types';
import * as StagedQuote from './index';

describe('builder', () => {
it(
...createBuilderSpec<TStagedQuote, TStagedQuote>(
'default',
StagedQuote.random(),
expect.objectContaining({
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
stagedQuoteState: expect.any(String),
customer: expect.objectContaining({
email: expect.any(String),
}),
quoteRequest: expect.objectContaining({
quoteRequestState: expect.any(String),
}),
quotationCart: expect.objectContaining({
cartState: expect.any(String),
}),
validTo: expect.any(String),
sellerComment: expect.any(String),
state: null,
purchaseOrderNumber: null,
businessUnit: expect.objectContaining({
id: expect.any(String),
key: expect.any(String),
associateMode: expect.any(String),
}),
custom: null,
createdAt: expect.any(String),
createdBy: expect.objectContaining({
customer: expect.objectContaining({ typeId: 'customer' }),
}),
lastModifiedAt: expect.any(String),
lastModifiedBy: expect.objectContaining({
customer: expect.objectContaining({ typeId: 'customer' }),
}),
})
)
);
it(
...createBuilderSpec<TStagedQuote, TStagedQuoteRest>(
'rest',
StagedQuote.random(),
expect.objectContaining({
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
stagedQuoteState: expect.any(String),
customer: expect.objectContaining({
id: expect.any(String),
typeId: 'customer',
}),
quoteRequest: expect.objectContaining({
typeId: 'quote-request',
}),
quotationCart: expect.objectContaining({
typeId: 'cart',
}),
validTo: expect.any(String),
sellerComment: expect.any(String),
state: undefined,
purchaseOrderNumber: null,
businessUnit: expect.objectContaining({
typeId: 'business-unit',
}),
custom: null,
createdAt: expect.any(String),
createdBy: expect.objectContaining({
customer: expect.objectContaining({ typeId: 'customer' }),
}),
lastModifiedAt: expect.any(String),
lastModifiedBy: expect.objectContaining({
customer: expect.objectContaining({ typeId: 'customer' }),
}),
})
)
);
it(
...createBuilderSpec<TStagedQuote, TStagedQuoteGraphql>(
'graphql',
StagedQuote.random(),
expect.objectContaining({
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
stagedQuoteState: expect.any(String),
customer: expect.objectContaining({
email: expect.any(String),
}),
customerRef: expect.objectContaining({
typeId: 'customer',
__typename: 'Reference',
}),
quoteRequest: expect.objectContaining({
quoteRequestState: expect.any(String),
}),
quoteRequestRef: expect.objectContaining({
typeId: 'quote-request',
__typename: 'Reference',
}),
quotationCart: expect.objectContaining({
cartState: expect.any(String),
}),
quotationCartRef: expect.objectContaining({
typeId: 'cart',
__typename: 'Reference',
}),
validTo: expect.any(String),
sellerComment: expect.any(String),
state: null,
stateRef: undefined,
purchaseOrderNumber: null,
businessUnit: expect.objectContaining({
id: expect.any(String),
key: expect.any(String),
associateMode: expect.any(String),
}),
businessUnitRef: expect.objectContaining({
typeId: 'business-unit',
__typename: 'Reference',
}),
custom: null,
createdAt: expect.any(String),
createdBy: expect.objectContaining({
customerRef: expect.objectContaining({ typeId: 'customer' }),
userRef: expect.objectContaining({ typeId: 'user' }),
}),
lastModifiedAt: expect.any(String),
lastModifiedBy: expect.objectContaining({
customerRef: expect.objectContaining({ typeId: 'customer' }),
userRef: expect.objectContaining({ typeId: 'user' }),
}),
__typename: 'StagedQuote',
})
)
);
});
12 changes: 12 additions & 0 deletions models/staged-quote/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 type { TStagedQuote, TCreateStagedQuoteBuilder } from './types';

const Model: TCreateStagedQuoteBuilder = () =>
Builder<TStagedQuote>({
generator,
transformers,
});

export default Model;
5 changes: 5 additions & 0 deletions models/staged-quote/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const STAGED_QUOTE_STATE = {
inProgress: 'InProgress',
sent: 'Sent',
closed: 'Closed',
} as const;
Loading