Skip to content

Commit

Permalink
PANGOLIN-3183 - New package for model: ShoppingList (#429)
Browse files Browse the repository at this point in the history
* feat(shopping-list): add shopping list module folder

* feat(shopping-list): fix broken tests

* feat(shopping-list): add PR feedback

* Update models/shopping-list/package.json

Co-authored-by: Valorie <[email protected]>

* Update models/shopping-list/src/shopping-list-draft/transformers.ts

Co-authored-by: Valorie <[email protected]>

* Update models/shopping-list/src/shopping-list-draft/builder.spec.ts

Co-authored-by: Valorie <[email protected]>

* Update models/shopping-list/src/shopping-list-draft/transformers.ts

Co-authored-by: Valorie <[email protected]>

* Update models/shopping-list/src/transformers.ts

Co-authored-by: Valorie <[email protected]>

* Update models/shopping-list/src/builder.spec.ts

Co-authored-by: Valorie <[email protected]>

* feat(shopping-list): fix build error

* feat(shopping-list): fix build error

---------

Co-authored-by: Jonathan Creasman <[email protected]>
Co-authored-by: Valorie <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2023
1 parent f21c5a1 commit d738373
Show file tree
Hide file tree
Showing 17 changed files with 595 additions and 0 deletions.
21 changes: 21 additions & 0 deletions models/shopping-list/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.
26 changes: 26 additions & 0 deletions models/shopping-list/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# @commercetools-test-data/shopping-list

This package provides data models for the commercetools platform `Shopping List` representations.

https://docs.commercetools.com/api/projects/shoppingLists#representations

# Install

```bash
$ pnpm add -D @commercetools-test-data/shopping-list
```

# Usage

```ts
import {
ShoppingList,
ShoppingListDraft,
type TShoppingList,
type TShoppingListDraft,
} from '@commercetools-test-data/shopping-list';

const shoppingList = ShoppingList.random().build<TShoppingList>();
const shoppingListDraft =
ShoppingListDraft.random().build<TShoppingListDraft>();
```
37 changes: 37 additions & 0 deletions models/shopping-list/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@commercetools-test-data/shopping-list",
"version": "6.4.1",
"description": "Data model for commercetools API Shopping List",
"bugs": "https://github.com/commercetools/test-data/issues",
"repository": {
"type": "git",
"url": "https://github.com/commercetools/test-data.git",
"directory": "models/shopping-list"
},
"keywords": [
"javascript",
"typescript",
"test-data"
],
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "dist/commercetools-test-data-shopping-list.cjs.js",
"module": "dist/commercetools-test-data-shopping-list.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.1",
"@commercetools-test-data/core": "6.4.1",
"@commercetools-test-data/utils": "6.4.1",
"@commercetools/platform-sdk": "^6.0.0",
"@faker-js/faker": "^8.0.0"
}
}
170 changes: 170 additions & 0 deletions models/shopping-list/src/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/* eslint-disable jest/no-disabled-tests */
/* eslint-disable jest/valid-title */

import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import type { TShoppingList, TShoppingListGraphql } from './types';
import * as ShoppingList from './index';

describe('builder', () => {
it(
...createBuilderSpec<TShoppingList, TShoppingList>(
'default',
ShoppingList.random(),
expect.objectContaining({
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
name: expect.objectContaining({
de: expect.any(String),
en: expect.any(String),
fr: expect.any(String),
}),
customer: expect.objectContaining({
id: expect.any(String),
typeId: 'customer',
}),
slug: expect.objectContaining({
en: expect.any(String),
de: expect.any(String),
fr: expect.any(String),
}),
description: expect.objectContaining({
en: expect.any(String),
}),
lineItems: [],
textLineItems: [],
deleteDaysAfterLastModification: null,
anonymousId: expect.any(String),
store: null,
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<TShoppingList, TShoppingList>(
'rest',
ShoppingList.random(),
expect.objectContaining({
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
name: expect.objectContaining({
de: expect.any(String),
en: expect.any(String),
fr: expect.any(String),
}),
customer: expect.objectContaining({
id: expect.any(String),
typeId: 'customer',
}),
slug: expect.objectContaining({
en: expect.any(String),
de: expect.any(String),
fr: expect.any(String),
}),
description: expect.objectContaining({
en: expect.any(String),
}),
lineItems: [],
textLineItems: [],
deleteDaysAfterLastModification: null,
anonymousId: expect.any(String),
store: null,
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' }),
}),
})
)
);
// Note that the ShoppingList graphql is provided as scaffolding only and may not be complete at this time.
it(
...createBuilderSpec<TShoppingList, TShoppingListGraphql>(
'graphql',
ShoppingList.random(),
expect.objectContaining({
id: expect.any(String),
version: expect.any(Number),
key: expect.any(String),
name: expect.arrayContaining([
expect.objectContaining({
locale: 'en',
value: expect.any(String),
}),
expect.objectContaining({
locale: 'de',
value: expect.any(String),
}),
expect.objectContaining({
locale: 'fr',
value: expect.any(String),
}),
]),
customer: expect.objectContaining({
id: expect.any(String),
typeId: 'customer',
}),
slug: expect.arrayContaining([
expect.objectContaining({
locale: 'en',
value: expect.any(String),
}),
expect.objectContaining({
locale: 'de',
value: expect.any(String),
}),
expect.objectContaining({
locale: 'fr',
value: expect.any(String),
}),
]),
description: expect.arrayContaining([
expect.objectContaining({
locale: 'en',
value: expect.any(String),
__typename: 'LocalizedString',
}),
expect.objectContaining({
locale: 'de',
value: expect.any(String),
__typename: 'LocalizedString',
}),
expect.objectContaining({
locale: 'fr',
value: expect.any(String),
__typename: 'LocalizedString',
}),
]),
lineItems: [],
textLineItems: [],
deleteDaysAfterLastModification: null,
anonymousId: expect.any(String),
store: null,
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' }),
}),
})
)
);
});
12 changes: 12 additions & 0 deletions models/shopping-list/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 { TCreateShoppingListBuilder, TShoppingList } from './types';

const Model: TCreateShoppingListBuilder = () =>
Builder<TShoppingList>({
generator,
transformers,
});

export default Model;
36 changes: 36 additions & 0 deletions models/shopping-list/src/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
ClientLogging,
LocalizedString,
Reference,
} from '@commercetools-test-data/commons';
import { sequence, fake, Generator } from '@commercetools-test-data/core';
import { createRelatedDates } from '@commercetools-test-data/utils';
import { TShoppingList } from './types';

const [getOlderDate, getNewerDate] = createRelatedDates();

// https://docs.commercetools.com/api/projects/shoppingLists#shoppingLists

const generator = Generator<TShoppingList>({
fields: {
id: fake((f) => f.string.uuid()),
version: sequence(),
key: fake((f) => f.lorem.slug(2)),
name: fake(() => LocalizedString.random()),
customer: fake(() => Reference.random().typeId('customer')),
slug: fake(() => LocalizedString.presets.ofSlugs()),
description: fake(() => LocalizedString.random()),
lineItems: [],
textLineItems: [],
deleteDaysAfterLastModification: null,
anonymousId: fake((f) => f.string.uuid()),
store: null,
custom: null,
createdAt: fake(getOlderDate),
createdBy: fake(() => ClientLogging.random()),
lastModifiedAt: fake(getNewerDate),
lastModifiedBy: fake(() => ClientLogging.random()),
},
});

export default generator;
6 changes: 6 additions & 0 deletions models/shopping-list/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * as ShoppingListDraft from './shopping-list-draft';
export * as ShoppingList from '.';

export { default as random } from './builder';
export { default as presets } from './presets';
export * from './types';
3 changes: 3 additions & 0 deletions models/shopping-list/src/presets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const presets = {};

export default presets;
Loading

0 comments on commit d738373

Please sign in to comment.