-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PANGOLIN-3193 - New package for model:
Type
(#453)
* 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
1 parent
203eff0
commit 60490aa
Showing
129 changed files
with
2,579 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}) | ||
) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const presets = {}; | ||
|
||
export default presets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
models/type/src/custom-field-date-time-type/builder.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}) | ||
) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
models/type/src/custom-field-date-time-type/transformers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.