diff --git a/models/custom-object/LICENSE b/models/custom-object/LICENSE new file mode 100644 index 000000000..e113013cb --- /dev/null +++ b/models/custom-object/LICENSE @@ -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. diff --git a/models/custom-object/README.md b/models/custom-object/README.md new file mode 100644 index 000000000..cdecc451f --- /dev/null +++ b/models/custom-object/README.md @@ -0,0 +1,26 @@ +# @commercetools-test-data/custom-object + +This package provides the data model for the commercetools platform `CustomObject` representations + +https://docs.commercetools.com/api/projects/custom-objects#representations + +# Install + +```bash +$ pnpm add -D @commercetools-test-data/custom-object +``` + +# Usage + +```ts +import { + CustomObject, + CustomObjectDraft, + type TCustomObject, + type TCustomObjectDraft, +} from '@commercetools-test-data/custom-object'; + +const customObject = CustomObject.random().build(); +const customObjectDraft = + CustomObjectDraft.random().build(); +``` diff --git a/models/custom-object/package.json b/models/custom-object/package.json new file mode 100644 index 000000000..713038852 --- /dev/null +++ b/models/custom-object/package.json @@ -0,0 +1,28 @@ +{ + "name": "@commercetools-test-data/custom-object", + "version": "6.7.0", + "description": "Data model for commercetools API CustomObject", + "bugs": "https://github.com/commercetools/test-data/issues", + "repository": { + "type": "git", + "url": "https://github.com/commercetools/test-data.git", + "directory": "models/custom-object" + }, + "keywords": ["javascript", "typescript", "test-data"], + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "dist/commercetools-test-data-custom-object.cjs.js", + "module": "dist/commercetools-test-data-custom-object.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.6.0", + "@commercetools-test-data/core": "6.6.0", + "@commercetools-test-data/utils": "6.6.0", + "@commercetools/platform-sdk": "^6.0.0", + "@faker-js/faker": "^8.0.0" + } +} diff --git a/models/custom-object/src/builder.spec.ts b/models/custom-object/src/builder.spec.ts new file mode 100644 index 000000000..764f1ffdf --- /dev/null +++ b/models/custom-object/src/builder.spec.ts @@ -0,0 +1,74 @@ +/* eslint-disable jest/no-disabled-tests */ +/* eslint-disable jest/valid-title */ +import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; +import type { TCustomObject, TCustomObjectGraphql } from './types'; +import * as CustomObject from './index'; + +describe('builder', () => { + it( + ...createBuilderSpec( + 'default', + CustomObject.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), + container: expect.any(String), + value: expect.any(Object), + }) + ) + ); + + it( + ...createBuilderSpec( + 'rest', + CustomObject.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), + container: expect.any(String), + value: expect.any(Object), + }) + ) + ); + + it( + ...createBuilderSpec( + 'graphql', + CustomObject.random(), + expect.objectContaining({ + __typename: 'CustomObject', + 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), + container: expect.any(String), + value: expect.any(Object), + }) + ) + ); +}); diff --git a/models/custom-object/src/builder.ts b/models/custom-object/src/builder.ts new file mode 100644 index 000000000..af1f89079 --- /dev/null +++ b/models/custom-object/src/builder.ts @@ -0,0 +1,12 @@ +import { Builder } from '@commercetools-test-data/core'; +import generator from './generator'; +import transformers from './transformers'; +import { TCustomObject, TCreateCustomObjectBuilder } from './types'; + +const Model: TCreateCustomObjectBuilder = () => + Builder({ + generator, + transformers, + }); + +export default Model; diff --git a/models/custom-object/src/constants.ts b/models/custom-object/src/constants.ts new file mode 100644 index 000000000..e69de29bb diff --git a/models/custom-object/src/custom-object-draft/builder.spec.ts b/models/custom-object/src/custom-object-draft/builder.spec.ts new file mode 100644 index 000000000..08a8a47ec --- /dev/null +++ b/models/custom-object/src/custom-object-draft/builder.spec.ts @@ -0,0 +1,46 @@ +/* eslint-disable jest/no-disabled-tests */ +/* eslint-disable jest/valid-title */ +import { createBuilderSpec } from '@commercetools-test-data/core/test-utils'; +import type { TCustomObjectDraft } from '../types'; +import * as AssociateRoleDraft from './index'; + +describe('builder', () => { + it( + ...createBuilderSpec( + 'default', + AssociateRoleDraft.random(), + expect.objectContaining({ + version: expect.any(Number), + key: expect.any(String), + container: expect.any(String), + value: expect.any(Object), + }) + ) + ); + + it( + ...createBuilderSpec( + 'rest', + AssociateRoleDraft.random(), + expect.objectContaining({ + version: expect.any(Number), + key: expect.any(String), + container: expect.any(String), + value: expect.any(Object), + }) + ) + ); + + it( + ...createBuilderSpec( + 'graphql', + AssociateRoleDraft.random(), + expect.objectContaining({ + version: expect.any(Number), + key: expect.any(String), + container: expect.any(String), + value: expect.any(Object), + }) + ) + ); +}); diff --git a/models/custom-object/src/custom-object-draft/builder.ts b/models/custom-object/src/custom-object-draft/builder.ts new file mode 100644 index 000000000..458a8b630 --- /dev/null +++ b/models/custom-object/src/custom-object-draft/builder.ts @@ -0,0 +1,10 @@ +import { Builder } from '@commercetools-test-data/core'; +import { TCustomObjectDraft, TCustomObjectDraftBuilder } from '../types'; +import generator from './generator'; + +const CustomObjectDraft: TCustomObjectDraftBuilder = () => + Builder({ + generator, + }); + +export default CustomObjectDraft; diff --git a/models/custom-object/src/custom-object-draft/generator.ts b/models/custom-object/src/custom-object-draft/generator.ts new file mode 100644 index 000000000..66eb9fdad --- /dev/null +++ b/models/custom-object/src/custom-object-draft/generator.ts @@ -0,0 +1,17 @@ +import { fake, Generator, sequence } from '@commercetools-test-data/core'; +import { TCustomObjectDraft } from '../types'; + +const generator = Generator({ + fields: { + version: sequence(), + key: fake((f) => f.string.alphanumeric(10)), + container: fake((f) => f.string.alphanumeric(10)), + value: { + [fake((f) => f.string.alpha(5))]: { + [fake((f) => f.string.alpha(6))]: fake((f) => f.string.alpha(7)), + }, + }, + }, +}); + +export default generator; diff --git a/models/custom-object/src/custom-object-draft/index.ts b/models/custom-object/src/custom-object-draft/index.ts new file mode 100644 index 000000000..96e2519e1 --- /dev/null +++ b/models/custom-object/src/custom-object-draft/index.ts @@ -0,0 +1,2 @@ +export { default as random } from './builder'; +export { default as presets } from './presets'; diff --git a/models/custom-object/src/custom-object-draft/presets/index.ts b/models/custom-object/src/custom-object-draft/presets/index.ts new file mode 100644 index 000000000..763e57fe0 --- /dev/null +++ b/models/custom-object/src/custom-object-draft/presets/index.ts @@ -0,0 +1,3 @@ +const presets = {}; + +export default presets; diff --git a/models/custom-object/src/generator.ts b/models/custom-object/src/generator.ts new file mode 100644 index 000000000..b683baf48 --- /dev/null +++ b/models/custom-object/src/generator.ts @@ -0,0 +1,26 @@ +import { ClientLogging } from '@commercetools-test-data/commons'; +import { fake, Generator, sequence } from '@commercetools-test-data/core'; +import { createRelatedDates } from '@commercetools-test-data/utils'; +import { TCustomObject } from './types'; + +const [getOlderDate, getNewerDate] = createRelatedDates(); + +const generator = Generator({ + fields: { + id: fake((f) => f.string.uuid()), + version: sequence(), + key: fake((f) => f.string.alphanumeric(10)), + container: fake((f) => f.string.alphanumeric(10)), + value: { + [fake((f) => f.string.alpha(5))]: { + [fake((f) => f.string.alpha(6))]: fake((f) => f.string.alpha(7)), + }, + }, + createdAt: fake(getOlderDate), + createdBy: fake(() => ClientLogging.random()), + lastModifiedAt: fake(getNewerDate), + lastModifiedBy: fake(() => ClientLogging.random()), + }, +}); + +export default generator; diff --git a/models/custom-object/src/index.ts b/models/custom-object/src/index.ts new file mode 100644 index 000000000..3e11d93be --- /dev/null +++ b/models/custom-object/src/index.ts @@ -0,0 +1,7 @@ +export * as CustomObjectDraft from './custom-object-draft'; +export * as CustomObject from '.'; + +export { default as random } from './builder'; +export * as presets from './presets'; +export * as constants from './constants'; +export * from './types'; diff --git a/models/custom-object/src/presets/index.ts b/models/custom-object/src/presets/index.ts new file mode 100644 index 000000000..763e57fe0 --- /dev/null +++ b/models/custom-object/src/presets/index.ts @@ -0,0 +1,3 @@ +const presets = {}; + +export default presets; diff --git a/models/custom-object/src/transformers.ts b/models/custom-object/src/transformers.ts new file mode 100644 index 000000000..0d80436f8 --- /dev/null +++ b/models/custom-object/src/transformers.ts @@ -0,0 +1,19 @@ +import { Transformer } from '@commercetools-test-data/core'; +import type { TCustomObject, TCustomObjectGraphql } from './types'; + +const transformers = { + default: Transformer('default', { + buildFields: ['createdBy', 'lastModifiedBy'], + }), + rest: Transformer('rest', { + buildFields: ['createdBy', 'lastModifiedBy'], + }), + graphql: Transformer('graphql', { + buildFields: ['createdBy', 'lastModifiedBy'], + addFields: () => ({ + __typename: 'CustomObject', + }), + }), +}; + +export default transformers; diff --git a/models/custom-object/src/types.ts b/models/custom-object/src/types.ts new file mode 100644 index 000000000..68d998828 --- /dev/null +++ b/models/custom-object/src/types.ts @@ -0,0 +1,21 @@ +import type { + CustomObject, + CustomObjectDraft, +} from '@commercetools/platform-sdk'; +import type { TBuilder } from '@commercetools-test-data/core'; + +//CustomObjectDraft +export type TCustomObjectDraft = CustomObjectDraft; +export type TCustomObjectDraftBuilder = TBuilder; +export type TCreateCustomObjectDraftBuilder = () => TCustomObjectDraftBuilder; +export type TCustomObjectDraftGraphql = TCustomObjectDraft & { + __typename: 'CustomObjectDraft'; +}; + +//CustomObject +export type TCustomObject = CustomObject; +export type TCustomObjectBuilder = TBuilder; +export type TCreateAssociateRoleBuilder = () => TCustomObjectBuilder; +export type TCustomObjectGraphql = TCustomObject & { + __typename: 'CustomObject'; +}; diff --git a/package.json b/package.json index f0267b7fd..9dcd3c674 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,12 @@ "description": "Modules to generate test data for commercetools APIs", "private": true, "preconstruct": { - "packages": ["core", "graphql-types", "models/*", "utils"] + "packages": [ + "core", + "graphql-types", + "models/*", + "utils" + ] }, "scripts": { "preinstall": "npx only-allow pnpm", @@ -57,5 +62,8 @@ "tsc-files": "^1.1.3", "typescript": "4.9.5" }, - "packageManager": "pnpm@8.10.2" + "packageManager": "pnpm@8.10.2", + "devDependencies": { + "@commercetools-test-data/core": "workspace:6.6.0" + } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1b978c1f7..91b111107 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,9 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + importers: .: @@ -106,6 +110,10 @@ importers: typescript: specifier: 4.9.5 version: 4.9.5 + devDependencies: + '@commercetools-test-data/core': + specifier: workspace:6.6.0 + version: link:core core: dependencies: @@ -328,6 +336,30 @@ importers: specifier: ^4.17.21 version: 4.17.21 + models/custom-object: + dependencies: + '@babel/runtime': + specifier: ^7.17.9 + version: 7.23.4 + '@babel/runtime-corejs3': + specifier: ^7.17.9 + version: 7.23.4 + '@commercetools-test-data/commons': + specifier: 6.6.0 + version: link:../commons + '@commercetools-test-data/core': + specifier: 6.6.0 + version: link:../../core + '@commercetools-test-data/utils': + specifier: 6.6.0 + version: link:../../utils + '@commercetools/platform-sdk': + specifier: ^6.0.0 + version: 6.0.0 + '@faker-js/faker': + specifier: ^8.0.0 + version: 8.3.1 + models/custom-view: dependencies: '@babel/runtime': @@ -3029,13 +3061,13 @@ packages: deprecated: Use the @commercetools-test-data/product-type package instead dependencies: '@babel/runtime': 7.23.4 - '@babel/runtime-corejs3': 7.23.1 + '@babel/runtime-corejs3': 7.23.4 '@commercetools-test-data/attribute-type': 5.11.2 '@commercetools-test-data/commons': 5.11.2 '@commercetools-test-data/core': 5.11.2 '@commercetools-test-data/utils': 5.11.2 '@commercetools/platform-sdk': 4.11.0 - '@faker-js/faker': 8.0.0 + '@faker-js/faker': 8.3.1 transitivePeerDependencies: - encoding dev: false @@ -3045,12 +3077,12 @@ packages: deprecated: Use the @commercetools-test-data/product-type package instead dependencies: '@babel/runtime': 7.23.4 - '@babel/runtime-corejs3': 7.23.1 + '@babel/runtime-corejs3': 7.23.4 '@commercetools-test-data/commons': 5.11.2 '@commercetools-test-data/core': 5.11.2 '@commercetools-test-data/utils': 5.11.2 '@commercetools/platform-sdk': 4.11.0 - '@faker-js/faker': 8.0.0 + '@faker-js/faker': 8.3.1 transitivePeerDependencies: - encoding dev: false @@ -3059,11 +3091,11 @@ packages: resolution: {integrity: sha512-AxcUby9NOEmil3kJKrNVa7Lz94UHOeW+nFgsmn5I3CLKrt/Q5VI0et+6Ls1UJh57buxbTQRK15O/Gd/hRMYwSA==} dependencies: '@babel/runtime': 7.23.4 - '@babel/runtime-corejs3': 7.23.1 + '@babel/runtime-corejs3': 7.23.4 '@commercetools-test-data/core': 5.11.2 '@commercetools-test-data/utils': 5.11.2 '@commercetools/platform-sdk': 4.11.0 - '@faker-js/faker': 8.0.0 + '@faker-js/faker': 8.3.1 '@types/lodash': 4.14.202 lodash: 4.17.21 transitivePeerDependencies: @@ -3074,8 +3106,8 @@ packages: resolution: {integrity: sha512-iz++zEBengERwg3REm51RsEFmiUeNPQz1K9K2kZjH1sAkFxOf1ydmpM0Tt4Awmi/OHQ+G2tGKKdJewm8AQyHNg==} dependencies: '@babel/runtime': 7.23.4 - '@babel/runtime-corejs3': 7.23.1 - '@faker-js/faker': 8.0.0 + '@babel/runtime-corejs3': 7.23.4 + '@faker-js/faker': 8.3.1 '@types/lodash': 4.14.202 lodash: 4.17.21 dev: false @@ -3084,13 +3116,13 @@ packages: resolution: {integrity: sha512-7VT0Iez2bi8fhpqJOzVx/WfmLV+mAXlc5SOxZoTeP1JyUyY07GiujI0ctKAh8Q3/0qzVyJ08RFV1BLtYxLWeKA==} dependencies: '@babel/runtime': 7.23.4 - '@babel/runtime-corejs3': 7.23.1 + '@babel/runtime-corejs3': 7.23.4 '@commercetools-test-data/attribute-definition': 5.11.2 '@commercetools-test-data/commons': 5.11.2 '@commercetools-test-data/core': 5.11.2 '@commercetools-test-data/utils': 5.11.2 '@commercetools/platform-sdk': 4.11.0 - '@faker-js/faker': 8.0.0 + '@faker-js/faker': 8.3.1 transitivePeerDependencies: - encoding dev: false @@ -3099,8 +3131,8 @@ packages: resolution: {integrity: sha512-7CU08wvYiQJ+tltvnEDunX/QtVgHimnMtNmwXBicL6/7OsiN/QHtW3pIuN8Sb/OQva6zUPLgOQe/6UbVHB+WpA==} dependencies: '@babel/runtime': 7.23.4 - '@babel/runtime-corejs3': 7.23.1 - '@faker-js/faker': 8.0.0 + '@babel/runtime-corejs3': 7.23.4 + '@faker-js/faker': 8.3.1 dev: false /@commercetools/platform-sdk@4.11.0: @@ -9825,7 +9857,7 @@ packages: resolution: {integrity: sha512-rqEprmXZ0CaOcY7vtCdRLm7QPrmyst30GN4WWsUwcbvosHF55cszEZ6Gg9SNnVIiXC91luURcSp+xChg2ymjkA==} dependencies: '@babel/runtime': 7.23.4 - '@babel/runtime-corejs3': 7.23.1 + '@babel/runtime-corejs3': 7.23.4 dev: false /once@1.4.0: @@ -11834,7 +11866,3 @@ packages: /zod@3.22.3: resolution: {integrity: sha512-EjIevzuJRiRPbVH4mGc8nApb/lVLKVpmUhAaR5R5doKGfAnGJ6Gr3CViAVjP+4FWSxCsybeWQdcgCtbX+7oZug==} dev: false - -settings: - autoInstallPeers: true - excludeLinksFromLockfile: false