Skip to content

Commit

Permalink
feat(custom-object): add custom-object and custom-object-draft mo…
Browse files Browse the repository at this point in the history
…dels/package (#441)

* feat(custom-object): added custom-object and custom-object-draft models

* fix(custom-object): fixed types naming

* fix(generator): added variable for dynamic key

* fix(builder): imported correct type

* chore(changeset): added changeset

* chore(custom-object): added transformers to associate-role-draft and custom-object-draft

* chore(pnpm-lock): updated yaml

* chore(custom-object): updated generators

* chore(custom-object): general cleanup

---------

Co-authored-by: Valorie Carli <[email protected]>
  • Loading branch information
kterry1 and valoriecarli authored Dec 4, 2023
1 parent d6ca721 commit 2285e9a
Show file tree
Hide file tree
Showing 21 changed files with 408 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-queens-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-test-data/custom-object': minor
---

custom-object and custom-object-draft models and package
2 changes: 2 additions & 0 deletions models/associate-role/src/associate-role-draft/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
TCreateAssociateRoleDraftBuilder,
} from '../types';
import generator from './generator';
import transformers from '../transformers';

const AssociateRoleDraft: TCreateAssociateRoleDraftBuilder = () =>
Builder<TAssociateRoleDraft>({
generator,
transformers,
});

export default AssociateRoleDraft;
20 changes: 20 additions & 0 deletions models/associate-role/src/associate-role-draft/transformers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Transformer } from '@commercetools-test-data/core';
import type { TAssociateRoleDraft, TAssociateRoleDraftGraphql } from '../types';

const transformers = {
default: Transformer<TAssociateRoleDraft, TAssociateRoleDraft>('default', {
buildFields: [],
}),
rest: Transformer<TAssociateRoleDraft, TAssociateRoleDraft>('rest', {
buildFields: [],
}),
//only scaffolding provided at this time
graphql: Transformer<TAssociateRoleDraft, TAssociateRoleDraftGraphql>(
'graphql',
{
buildFields: [],
}
),
};

export default transformers;
21 changes: 21 additions & 0 deletions models/custom-object/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/custom-object/README.md
Original file line number Diff line number Diff line change
@@ -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<TCustomObject>();
const customObjectDraft =
CustomObjectDraft.random().build<TCustomObjectDraft>();
```
28 changes: 28 additions & 0 deletions models/custom-object/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
75 changes: 75 additions & 0 deletions models/custom-object/src/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/* 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<TCustomObject, TCustomObject>(
'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<TCustomObject, TCustomObject>(
'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),
})
)
);

//only scaffolding provided at this time
it(
...createBuilderSpec<TCustomObject, TCustomObjectGraphql>(
'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),
})
)
);
});
12 changes: 12 additions & 0 deletions models/custom-object/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 { TCustomObject, TCreateCustomObjectBuilder } from './types';

const Model: TCreateCustomObjectBuilder = () =>
Builder<TCustomObject>({
generator,
transformers,
});

export default Model;
47 changes: 47 additions & 0 deletions models/custom-object/src/custom-object-draft/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* 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 CustomObjectDraft from './index';

describe('builder', () => {
it(
...createBuilderSpec<TCustomObjectDraft, TCustomObjectDraft>(
'default',
CustomObjectDraft.random(),
expect.objectContaining({
version: expect.any(Number),
key: expect.any(String),
container: expect.any(String),
value: expect.any(Object),
})
)
);

it(
...createBuilderSpec<TCustomObjectDraft, TCustomObjectDraft>(
'rest',
CustomObjectDraft.random(),
expect.objectContaining({
version: expect.any(Number),
key: expect.any(String),
container: expect.any(String),
value: expect.any(Object),
})
)
);

//only scaffolding provided at this time
it(
...createBuilderSpec<TCustomObjectDraft, TCustomObjectDraft>(
'graphql',
CustomObjectDraft.random(),
expect.objectContaining({
version: expect.any(Number),
key: expect.any(String),
container: expect.any(String),
value: expect.any(Object),
})
)
);
});
12 changes: 12 additions & 0 deletions models/custom-object/src/custom-object-draft/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Builder } from '@commercetools-test-data/core';
import transformers from '../transformers';
import { TCustomObjectDraft, TCreateCustomObjectDraftBuilder } from '../types';
import generator from './generator';

const CustomObjectDraft: TCreateCustomObjectDraftBuilder = () =>
Builder<TCustomObjectDraft>({
generator,
transformers,
});

export default CustomObjectDraft;
17 changes: 17 additions & 0 deletions models/custom-object/src/custom-object-draft/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { fake, Generator } from '@commercetools-test-data/core';
import { TCustomObjectDraft } from '../types';

const generator = Generator<TCustomObjectDraft>({
fields: {
version: 0,
key: fake((f) => f.string.alphanumeric(10)),
container: fake((f) => f.string.alphanumeric(10)),
value: {
valueKey: {
nestedValueKey: fake((f) => f.string.alpha(10)),
},
},
},
});

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

export default presets;
20 changes: 20 additions & 0 deletions models/custom-object/src/custom-object-draft/transformers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Transformer } from '@commercetools-test-data/core';
import type { TCustomObjectDraft, TCustomObjectDraftGraphql } from '../types';

const transformers = {
default: Transformer<TCustomObjectDraft, TCustomObjectDraft>('default', {
buildFields: [],
}),
rest: Transformer<TCustomObjectDraft, TCustomObjectDraft>('rest', {
buildFields: [],
}),
//only scaffolding provided at this time
graphql: Transformer<TCustomObjectDraft, TCustomObjectDraftGraphql>(
'graphql',
{
buildFields: [],
}
),
};

export default transformers;
26 changes: 26 additions & 0 deletions models/custom-object/src/generator.ts
Original file line number Diff line number Diff line change
@@ -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<TCustomObject>({
fields: {
id: fake((f) => f.string.uuid()),
version: sequence(),
key: fake((f) => f.string.alphanumeric(10)),
container: fake((f) => f.string.alphanumeric(10)),
value: {
valueKey: {
nestedValueKey: fake((f) => f.string.alpha(10)),
},
},
createdAt: fake(getOlderDate),
createdBy: fake(() => ClientLogging.random()),
lastModifiedAt: fake(getNewerDate),
lastModifiedBy: fake(() => ClientLogging.random()),
},
});

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

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

export default presets;
20 changes: 20 additions & 0 deletions models/custom-object/src/transformers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Transformer } from '@commercetools-test-data/core';
import type { TCustomObject, TCustomObjectGraphql } from './types';

const transformers = {
default: Transformer<TCustomObject, TCustomObject>('default', {
buildFields: ['createdBy', 'lastModifiedBy'],
}),
rest: Transformer<TCustomObject, TCustomObject>('rest', {
buildFields: ['createdBy', 'lastModifiedBy'],
}),
//only scaffolding provided at this time
graphql: Transformer<TCustomObject, TCustomObjectGraphql>('graphql', {
buildFields: ['createdBy', 'lastModifiedBy'],
addFields: () => ({
__typename: 'CustomObject',
}),
}),
};

export default transformers;
21 changes: 21 additions & 0 deletions models/custom-object/src/types.ts
Original file line number Diff line number Diff line change
@@ -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<TCustomObjectDraft>;
export type TCreateCustomObjectDraftBuilder = () => TCustomObjectDraftBuilder;
export type TCustomObjectDraftGraphql = TCustomObjectDraft & {
__typename: 'CustomObjectDraft';
};

//CustomObject
export type TCustomObject = CustomObject;
export type TCustomObjectBuilder = TBuilder<TCustomObject>;
export type TCreateCustomObjectBuilder = () => TCustomObjectBuilder;
export type TCustomObjectGraphql = TCustomObject & {
__typename: 'CustomObject';
};
Loading

0 comments on commit 2285e9a

Please sign in to comment.