-
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-3185 - New package for model:
State
(#440)
* feat(state-model): add initial setup files * feat(state-model): add state draft model * feat(state-model): add state model * feat(state-model): update type to LineItemState * feat(state-model): update transitions key * feat(state-model): update key value for type * feat(state-model): add preset * feat(state-model): add preset test * feat(state-model): update preset * feat(state-model): update graphql in transformors --------- Co-authored-by: Jonathan Creasman <[email protected]>
- Loading branch information
1 parent
555c8da
commit 35ef55b
Showing
21 changed files
with
587 additions
and
0 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,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/state | ||
|
||
This package provides data models for the commercetools platform `State` representations. | ||
|
||
https://docs.commercetools.com/api/projects/states#representations | ||
|
||
# Install | ||
|
||
```bash | ||
$ pnpm add -D @commercetools-test-data/state | ||
``` | ||
|
||
# Usage | ||
|
||
```ts | ||
import { | ||
State, | ||
StateDraft, | ||
type TState, | ||
type TStateDraft, | ||
} from '@commercetools-test-data/state'; | ||
|
||
const state = State.random().build<TState>(); | ||
const StateDraft = StateDraft.random().build<TStateDraft>(); | ||
``` |
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,37 @@ | ||
{ | ||
"name": "@commercetools-test-data/state", | ||
"version": "6.4.1", | ||
"description": "Data model for commercetools API State", | ||
"bugs": "https://github.com/commercetools/test-data/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/commercetools/test-data.git", | ||
"directory": "models/state" | ||
}, | ||
"keywords": [ | ||
"javascript", | ||
"typescript", | ||
"test-data" | ||
], | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"main": "dist/commercetools-test-data-state.cjs.js", | ||
"module": "dist/commercetools-test-data-state.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" | ||
} | ||
} |
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,121 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/valid-title */ | ||
|
||
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( | ||
...createBuilderSpec<TState, TState>( | ||
'default', | ||
State.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
key: expect.any(String), | ||
type: expect.any(String), | ||
name: expect.objectContaining({ | ||
de: expect.any(String), | ||
en: expect.any(String), | ||
fr: expect.any(String), | ||
}), | ||
description: expect.objectContaining({ | ||
en: expect.any(String), | ||
}), | ||
initial: expect.any(Boolean), | ||
builtIn: expect.any(Boolean), | ||
roles: expect.any(Array), | ||
transitions: 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<TState, TState>( | ||
'rest', | ||
State.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
key: expect.any(String), | ||
type: expect.any(String), | ||
name: expect.objectContaining({ | ||
de: expect.any(String), | ||
en: expect.any(String), | ||
fr: expect.any(String), | ||
}), | ||
description: expect.objectContaining({ | ||
en: expect.any(String), | ||
}), | ||
initial: expect.any(Boolean), | ||
builtIn: expect.any(Boolean), | ||
roles: expect.any(Array), | ||
transitions: 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 State graphql is provided as scaffolding only and may not be complete at this time. | ||
it( | ||
...createBuilderSpec<TState, TStateGraphql>( | ||
'graphql', | ||
State.random(), | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
version: expect.any(Number), | ||
key: expect.any(String), | ||
type: 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), | ||
}), | ||
]), | ||
description: expect.arrayContaining([ | ||
expect.objectContaining({ | ||
locale: 'en', | ||
value: expect.any(String), | ||
}), | ||
]), | ||
initial: expect.any(Boolean), | ||
builtIn: expect.any(Boolean), | ||
roles: expect.any(Array), | ||
transitions: 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' }), | ||
}), | ||
}) | ||
) | ||
); | ||
}); |
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,12 @@ | ||
import { Builder } from '@commercetools-test-data/core'; | ||
import generator from './generator'; | ||
import transformers from './transformers'; | ||
import type { TCreateStateBuilder, TState } from './types'; | ||
|
||
const Model: TCreateStateBuilder = () => | ||
Builder<TState>({ | ||
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,17 @@ | ||
const roles = { | ||
ReviewIncludedInStatistics: 'ReviewIncludedInStatistics', | ||
Return: 'Return', | ||
} as const; | ||
|
||
const type = { | ||
OrderState: 'OrderState', | ||
LineItemState: 'LineItemState', | ||
ProductState: 'ProductState', | ||
ReviewState: 'ReviewState', | ||
PaymentState: 'PaymentState', | ||
QuoteRequestState: 'QuoteRequestState', | ||
StagedQuoteState: 'StagedQuoteState', | ||
QuoteState: 'QuoteState', | ||
} as const; | ||
|
||
export { roles, type }; |
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,38 @@ | ||
import { | ||
ClientLogging, | ||
LocalizedString, | ||
} from '@commercetools-test-data/commons'; | ||
import { | ||
sequence, | ||
fake, | ||
Generator, | ||
oneOf, | ||
} from '@commercetools-test-data/core'; | ||
import { createRelatedDates } from '@commercetools-test-data/utils'; | ||
import { roles, type } from './constants'; | ||
import { TState } from './types'; | ||
|
||
const [getOlderDate, getNewerDate] = createRelatedDates(); | ||
|
||
// https://docs.commercetools.com/api/projects/States#States | ||
|
||
const generator = Generator<TState>({ | ||
fields: { | ||
id: fake((f) => f.string.uuid()), | ||
version: sequence(), | ||
key: fake((f) => f.lorem.slug(2)), | ||
type: oneOf(...Object.values(type)), | ||
name: fake(() => LocalizedString.random()), | ||
description: fake(() => LocalizedString.random()), | ||
initial: fake((f) => f.datatype.boolean()), | ||
builtIn: fake((f) => f.datatype.boolean()), | ||
roles: [oneOf(...Object.values(roles))], | ||
transitions: null, | ||
createdAt: fake(getOlderDate), | ||
createdBy: fake(() => ClientLogging.random()), | ||
lastModifiedAt: fake(getNewerDate), | ||
lastModifiedBy: fake(() => ClientLogging.random()), | ||
}, | ||
}); | ||
|
||
export default generator; |
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,7 @@ | ||
export * as StateDraft from './state-draft'; | ||
export * as State from '.'; | ||
|
||
export { default as random } from './builder'; | ||
export { default as presets } from './presets'; | ||
export * from './types'; | ||
export * as constants from './constants'; |
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,98 @@ | ||
/* eslint-disable jest/no-disabled-tests */ | ||
/* eslint-disable jest/valid-title */ | ||
|
||
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( | ||
...createBuilderSpec<TStateDraft, TStateDraft>( | ||
'default', | ||
StateDraft.random(), | ||
expect.objectContaining({ | ||
key: expect.any(String), | ||
type: expect.any(String), | ||
name: expect.objectContaining({ | ||
de: expect.any(String), | ||
en: expect.any(String), | ||
fr: expect.any(String), | ||
}), | ||
description: expect.objectContaining({ | ||
en: expect.any(String), | ||
}), | ||
initial: expect.any(Boolean), | ||
roles: expect.any(Array), | ||
transitions: null, | ||
}) | ||
) | ||
); | ||
|
||
it( | ||
...createBuilderSpec<TStateDraft, TStateDraft>( | ||
'rest', | ||
StateDraft.random(), | ||
expect.objectContaining({ | ||
key: expect.any(String), | ||
type: expect.any(String), | ||
name: expect.objectContaining({ | ||
de: expect.any(String), | ||
en: expect.any(String), | ||
fr: expect.any(String), | ||
}), | ||
description: expect.objectContaining({ | ||
en: expect.any(String), | ||
}), | ||
initial: expect.any(Boolean), | ||
roles: expect.any(Array), | ||
transitions: null, | ||
}) | ||
) | ||
); | ||
// Note that the StateDraft graphql is provided as scaffolding only and may not be complete at this time. | ||
it( | ||
...createBuilderSpec<TStateDraft, TStateDraftGraphql>( | ||
'graphql', | ||
StateDraft.random(), | ||
expect.objectContaining({ | ||
key: expect.any(String), | ||
type: 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), | ||
}), | ||
]), | ||
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', | ||
}), | ||
]), | ||
initial: expect.any(Boolean), | ||
roles: expect.any(Array), | ||
transitions: null, | ||
}) | ||
) | ||
); | ||
}); |
Oops, something went wrong.