Skip to content

Commit

Permalink
PANGOLIN-3193 - New package for model: Type (#453)
Browse files Browse the repository at this point in the history
* feat(type-model): add basic setup files and folder structure

* feat(type-model): add pnpm lock file

* feat(state-model): remove unused import

* feat(type-model): add type model

* feat(type-model): add type draft model

* feat(type-model): update file structure

* feat(type-model): add CustomFieldBooleanType model

* feat(type-model): add CustomFieldNumerType CustomFieldStringType CustomFieldLocalizedStringtype models

* feat(type-model): add CustomFieldEnumType

* feat(type-model): add CustomFieldMoneyType and edit fixes to other types

* feat(type-model): add CustomFieldDateType CustomFieldTimeType and CustomFieldDateTimeType

* feat(type-model): add CustomFieldReferenceType

* feat(type-model): add CustomFieldSetType

* feat(type-model): add CustomFieldLocalizedEnumValue

* feat(type-model): add CustomFieldLocalizedEnumType

* feat(type-model): update CustomFieldEnumType

* feat(type-model): add CustomFieldEnumValue

* feat(type-model): add FielDefinition model

* feat(type-model): update Type to reflect new models

* feat(type-model): add changeset

* feat(type-model): add preset index file to custom field enum value

* feat(type-model): add preset index file to custom field localized enum type

* fix(lockfile): update pnpm-lock

* fix(files): update typos

* fix(package.json): update deps

* fix(types): update typecheck

* feat(type-model): update fieldDefinitions key in type draft

* feat(type-model): update transformer files

* feat(type-model): add basic setup files and folder structure

* feat(type-model): add pnpm lock file

* feat(state-model): remove unused import

* feat(type-model): add type model

* feat(type-model): add type draft model

* feat(type-model): update file structure

* feat(type-model): add CustomFieldBooleanType model

* feat(type-model): add CustomFieldNumerType CustomFieldStringType CustomFieldLocalizedStringtype models

* feat(type-model): add CustomFieldEnumType

* feat(type-model): add CustomFieldMoneyType and edit fixes to other types

* feat(type-model): add CustomFieldDateType CustomFieldTimeType and CustomFieldDateTimeType

* feat(type-model): add CustomFieldReferenceType

* feat(type-model): add CustomFieldSetType

* feat(type-model): add CustomFieldLocalizedEnumValue

* feat(type-model): add CustomFieldLocalizedEnumType

* feat(type-model): update CustomFieldEnumType

* feat(type-model): add CustomFieldEnumValue

* feat(type-model): add FielDefinition model

* feat(type-model): update Type to reflect new models

* feat(type-model): add changeset

* feat(type-model): add preset index file to custom field enum value

* feat(type-model): add preset index file to custom field localized enum type

* fix(lockfile): update pnpm-lock

* fix(files): update typos

* fix(package.json): update deps

* fix(types): update typecheck

* feat(type-model): update fieldDefinitions key in type draft

---------

Co-authored-by: Jonathan Creasman <[email protected]>
Co-authored-by: Valorie Carli <[email protected]>
Co-authored-by: Jonathan Creasman <[email protected]>
  • Loading branch information
4 people authored Jan 5, 2024
1 parent 203eff0 commit 60490aa
Show file tree
Hide file tree
Showing 129 changed files with 2,579 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/cool-days-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@commercetools-test-data/state': minor
'@commercetools-test-data/type': minor
---

Package introduced for draft and final Type models plus supporting models.
1 change: 0 additions & 1 deletion models/state/src/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import type { TState, TStateGraphql } from './types';
import * as State from './index';
import { roles } from './constants';

describe('builder', () => {
it(
Expand Down
2 changes: 1 addition & 1 deletion models/state/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TState } from './types';

const [getOlderDate, getNewerDate] = createRelatedDates();

// https://docs.commercetools.com/api/projects/States#States
// https://docs.commercetools.com/api/projects/states#state

const generator = Generator<TState>({
fields: {
Expand Down
1 change: 0 additions & 1 deletion models/state/src/state-draft/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import type { TStateDraft, TStateDraftGraphql } from '../types';
import * as StateDraft from './index';
import { roles } from '../constants';

describe('builder', () => {
it(
Expand Down
21 changes: 21 additions & 0 deletions models/type/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/type/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# @commercetools-test-data/type

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

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

# Install

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

# Usage

```ts
import {
Type,
TypeDraft,
type TType,
type TypeDraft,
} from '@commercetools-test-data/type';

const type = Type.random().build<TType>();
const TypeDraft = TypeDraft.random().build<TTypeDraft>();
```
28 changes: 28 additions & 0 deletions models/type/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@commercetools-test-data/type",
"version": "6.9.0",
"description": "Data model for commercetools API Type",
"bugs": "https://github.com/commercetools/test-data/issues",
"repository": {
"type": "git",
"url": "https://github.com/commercetools/test-data.git",
"directory": "models/type"
},
"keywords": ["javascript", "typescript", "test-data"],
"license": "MIT",
"publishConfig": {
"access": "public"
},
"main": "dist/commercetools-test-data-type.cjs.js",
"module": "dist/commercetools-test-data-type.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.9.0",
"@commercetools-test-data/core": "6.9.0",
"@commercetools-test-data/utils": "6.9.0",
"@commercetools/platform-sdk": "^7.0.0",
"@faker-js/faker": "^8.0.0"
}
}
44 changes: 44 additions & 0 deletions models/type/src/custom-field-boolean-type/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable jest/no-disabled-tests */
/* eslint-disable jest/valid-title */
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import {
TCustomFieldBooleanType,
TCustomFieldBooleanTypeGraphql,
} from './types';
import * as CustomFieldBooleanType from './index';

describe('builder', () => {
it(
...createBuilderSpec<TCustomFieldBooleanType, TCustomFieldBooleanType>(
'default',
CustomFieldBooleanType.random(),
expect.objectContaining({
name: 'Boolean',
})
)
);

it(
...createBuilderSpec<TCustomFieldBooleanType, TCustomFieldBooleanType>(
'rest',
CustomFieldBooleanType.random(),
expect.objectContaining({
name: 'Boolean',
})
)
);

it(
...createBuilderSpec<
TCustomFieldBooleanType,
TCustomFieldBooleanTypeGraphql
>(
'graphql',
CustomFieldBooleanType.random(),
expect.objectContaining({
name: 'Boolean',
__typename: 'BooleanCustomFieldType',
})
)
);
});
15 changes: 15 additions & 0 deletions models/type/src/custom-field-boolean-type/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Builder } from '@commercetools-test-data/core';
import { generator } from './generator';
import transformers from './transformers';
import {
TCustomFieldBooleanType,
TCreateCustomFieldBooleanTypeBuilder,
} from './types';

const Model: TCreateCustomFieldBooleanTypeBuilder = () =>
Builder<TCustomFieldBooleanType>({
generator,
transformers,
});

export default Model;
10 changes: 10 additions & 0 deletions models/type/src/custom-field-boolean-type/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Generator } from '@commercetools-test-data/core';
import { TCustomFieldBooleanType } from './types';

// https://docs.commercetools.com/api/projects/types#customfieldbooleantype

export const generator = Generator<TCustomFieldBooleanType>({
fields: {
name: 'Boolean',
},
});
3 changes: 3 additions & 0 deletions models/type/src/custom-field-boolean-type/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as random } from './builder';
export { default as presets } from './presets';
export * from './types';
3 changes: 3 additions & 0 deletions models/type/src/custom-field-boolean-type/presets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const presets = {};

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

const transformers = {
default: Transformer<TCustomFieldBooleanType, TCustomFieldBooleanType>(
'default',
{
buildFields: [],
}
),
rest: Transformer<TCustomFieldBooleanType, TCustomFieldBooleanType>('rest', {
buildFields: [],
}),
graphql: Transformer<TCustomFieldBooleanType, TCustomFieldBooleanTypeGraphql>(
'graphql',
{
buildFields: [],
addFields: () => ({
__typename: 'BooleanCustomFieldType',
}),
}
),
};

export default transformers;
23 changes: 23 additions & 0 deletions models/type/src/custom-field-boolean-type/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { CustomFieldBooleanType } from '@commercetools/platform-sdk';
import type { TBuilder } from '@commercetools-test-data/core';

export type TCustomFieldBooleanType = CustomFieldBooleanType;
export type TCustomFieldBooleanTypeDraft = CustomFieldBooleanType;

export type TCustomFieldBooleanTypeGraphql = CustomFieldBooleanType & {
__typename: 'BooleanCustomFieldType';
};
export type TCustomFieldBooleanTypeDraftGraphql = {
boolean: {
dummy: string | null;
};
};

export type TCustomFieldBooleanTypeBuilder = TBuilder<TCustomFieldBooleanType>;
export type TCustomFieldBooleanTypeDraftBuilder =
TBuilder<TCustomFieldBooleanTypeDraft>;

export type TCreateCustomFieldBooleanTypeBuilder =
() => TCustomFieldBooleanTypeBuilder;
export type TCreateCustomFieldBooleanTypeDraftBuilder =
() => TCustomFieldBooleanTypeDraftBuilder;
44 changes: 44 additions & 0 deletions models/type/src/custom-field-date-time-type/builder.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* eslint-disable jest/no-disabled-tests */
/* eslint-disable jest/valid-title */
import { createBuilderSpec } from '@commercetools-test-data/core/test-utils';
import {
TCustomFieldDateTimeType,
TCustomFieldDateTimeTypeGraphql,
} from './types';
import * as AttributeEnumType from './index';

describe('builder', () => {
it(
...createBuilderSpec<TCustomFieldDateTimeType, TCustomFieldDateTimeType>(
'default',
AttributeEnumType.random(),
expect.objectContaining({
name: 'DateTime',
})
)
);

it(
...createBuilderSpec<TCustomFieldDateTimeType, TCustomFieldDateTimeType>(
'rest',
AttributeEnumType.random(),
expect.objectContaining({
name: 'DateTime',
})
)
);

it(
...createBuilderSpec<
TCustomFieldDateTimeType,
TCustomFieldDateTimeTypeGraphql
>(
'graphql',
AttributeEnumType.random(),
expect.objectContaining({
name: 'DateTime',
__typename: 'DateTimeCustomFieldType',
})
)
);
});
15 changes: 15 additions & 0 deletions models/type/src/custom-field-date-time-type/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Builder } from '@commercetools-test-data/core';
import { generator } from './generator';
import transformers from './transformers';
import {
TCustomFieldDateTimeType,
TCreateCustomFieldDateTimeTypeBuilder,
} from './types';

const Model: TCreateCustomFieldDateTimeTypeBuilder = () =>
Builder<TCustomFieldDateTimeType>({
generator,
transformers,
});

export default Model;
10 changes: 10 additions & 0 deletions models/type/src/custom-field-date-time-type/generator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Generator } from '@commercetools-test-data/core';
import { TCustomFieldDateTimeType } from './types';

// https://docs.commercetools.com/api/projects/types#customfielddatetimetype

export const generator = Generator<TCustomFieldDateTimeType>({
fields: {
name: 'DateTime',
},
});
3 changes: 3 additions & 0 deletions models/type/src/custom-field-date-time-type/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as random } from './builder';
export { default as presets } from './presets';
export * from './types';
3 changes: 3 additions & 0 deletions models/type/src/custom-field-date-time-type/presets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const presets = {};

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

const transformers = {
default: Transformer<TCustomFieldDateTimeType, TCustomFieldDateTimeType>(
'default',
{
buildFields: [],
}
),
rest: Transformer<TCustomFieldDateTimeType, TCustomFieldDateTimeType>(
'rest',
{
buildFields: [],
}
),
graphql: Transformer<
TCustomFieldDateTimeType,
TCustomFieldDateTimeTypeGraphql
>('graphql', {
buildFields: [],
addFields: () => ({
__typename: 'DateTimeCustomFieldType',
}),
}),
};

export default transformers;
24 changes: 24 additions & 0 deletions models/type/src/custom-field-date-time-type/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { CustomFieldDateTimeType } from '@commercetools/platform-sdk';
import type { TBuilder } from '@commercetools-test-data/core';

export type TCustomFieldDateTimeType = CustomFieldDateTimeType;
export type TCustomFieldDateTimeTypeDraft = CustomFieldDateTimeType;

export type TCustomFieldDateTimeTypeGraphql = CustomFieldDateTimeType & {
__typename: 'DateTimeCustomFieldType';
};
export type TCustomFieldDateTimeTypeDraftGraphql = {
datetime: {
dummy: string | null;
};
};

export type TCustomFieldDateTimeTypeBuilder =
TBuilder<TCustomFieldDateTimeType>;
export type TCustomFieldDateTimeTypeDraftBuilder =
TBuilder<TCustomFieldDateTimeTypeDraft>;

export type TCreateCustomFieldDateTimeTypeBuilder =
() => TCustomFieldDateTimeTypeBuilder;
export type TCreateCustomFieldDateTimeTypeDraftBuilder =
() => TCustomFieldDateTimeTypeDraftBuilder;
Loading

0 comments on commit 60490aa

Please sign in to comment.