Skip to content

Commit

Permalink
Pangolin 3184: staged quote model (#433)
Browse files Browse the repository at this point in the history
* feat(staged quote model): yakshaving for staged quote model package

* feat(staged quote model): implement model for StagedQuote, begin on StagedQuoteDraft

* feat(staged quote model): implement model for StagedQuoteDraft

* feat(staged quote model): add changeset

* feat(quote request model): update types, builder, and transformers to reflect that there is only a cartRef returned by the graphql api, it does not return the full cart data, also update staged quote types to reflect that quotationCartRef and quoteRequestRef are non-nullable

* feat(quote request model): more fun with arcane typescript warnings and the things we do to silence them

* feat(staged quote model): actually export the draft in src/index.ts

* feat(quote request model): even more fun with types and how to make them happy
  • Loading branch information
ByronDWall authored Nov 21, 2023
1 parent eacafc8 commit 3622e5d
Show file tree
Hide file tree
Showing 24 changed files with 715 additions and 46 deletions.
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')),
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
25 changes: 11 additions & 14 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 @@ -137,11 +131,13 @@ const transformers = {
.typeId('state')
.buildGraphql();

const cartRef: TReferenceGraphql = Reference.presets.cartReference
.cartReference()
.id(fields.cart?.id)
.typeId('cart')
.buildGraphql();
const cartRef: TReferenceGraphql | null = fields.cart
? Reference.presets.cartReference
.cartReference()
.id(fields.cart.id)
.typeId('cart')
.buildGraphql()
: null;

const businessUnitRef: TReferenceGraphql =
Reference.presets.businessUnitReference
Expand All @@ -152,14 +148,15 @@ const transformers = {

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

Expand Down
5 changes: 2 additions & 3 deletions models/quote-request/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
BusinessUnit,
Cart,
CartReference,
Customer,
CustomerGroup,
State,
Expand All @@ -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"
}
}
Loading

0 comments on commit 3622e5d

Please sign in to comment.