-
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.
[FEC-88] Migrating test data model Inventory Entry (#703)
* feat(inventory entry): update test data model migrating to new implementation * feat(inventory entry): add changeset * feat(inventory entry): fix error * feat(inventory entry): fix TS errors * feat(inventory entry): fix TS error * feat(inventory entry): update tests * feat(inventory entry): update tests * refactor(inventory-entry): ts types adjustments and supplychannel field config updated * feat(inventory entry): remove unneeded transformer and generator files * feat(inventory entry): update with migrating the draft * feat(inventory entry): remove unused imports * feat(inventory entry): fix tests * Update .changeset/metal-mice-sit.md Co-authored-by: Carlos Cortizas <[email protected]> * feat(inventory entry): update presets with new implementation part 1 * feat(inventory entry): update presets with new implementation part 2 * feat(inventory entry): update based on PR feedback * feat(inventory entry): remove commented out code * refactor(inventory-entry): refactored sample data presets * refactor(inventory-entry): reorder presets imports in their barrel files * chore: update readmes of migrated data models --------- Co-authored-by: Carlos Cortizas <[email protected]> Co-authored-by: Carlos Cortizas <[email protected]>
- Loading branch information
1 parent
ac18883
commit a2a8f73
Showing
2,827 changed files
with
93,777 additions
and
50,157 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,10 @@ | ||
--- | ||
'@commercetools-test-data/inventory-entry': minor | ||
--- | ||
|
||
Refactored `InventoryEntry` and `InventoryEntryDraft` models to use the new implementation patterns. | ||
This means the existing models are now deprecated (though we still support them for backwards compatibility) and consumers should move to the new ones implemented: | ||
* `InventoryEntryRest` | ||
* `InventoryEntryGraphql` | ||
* `InventoryEntryDraftRest` | ||
* `InventoryEntryDraftGraphql` |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,114 @@ | ||
import { | ||
InventoryEntry, | ||
InventoryEntryRest, | ||
InventoryEntryGraphql, | ||
} from './index'; | ||
|
||
describe('InventoryEntry model builders', () => { | ||
it('builds a REST model', () => { | ||
const restModel = InventoryEntryRest.random().build(); | ||
|
||
expect(restModel).toEqual( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
key: expect.any(String), | ||
version: expect.any(Number), | ||
createdAt: expect.any(String), | ||
createdBy: expect.any(Object), | ||
lastModifiedAt: expect.any(String), | ||
lastModifiedBy: expect.any(Object), | ||
sku: expect.any(String), | ||
quantityOnStock: expect.any(Number), | ||
restockableInDays: expect.any(Number), | ||
availableQuantity: expect.any(Number), | ||
expectedDelivery: expect.any(String), | ||
supplyChannel: expect.any(Object), | ||
custom: null, | ||
}) | ||
); | ||
}); | ||
|
||
it('builds a GraphQL model', () => { | ||
const graphqlModel = InventoryEntryGraphql.random().build(); | ||
|
||
expect(graphqlModel).toMatchObject( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
key: expect.any(String), | ||
version: expect.any(Number), | ||
createdAt: expect.any(String), | ||
createdBy: expect.any(Object), | ||
lastModifiedAt: expect.any(String), | ||
lastModifiedBy: expect.any(Object), | ||
sku: expect.any(String), | ||
quantityOnStock: expect.any(Number), | ||
restockableInDays: expect.any(Number), | ||
availableQuantity: expect.any(Number), | ||
expectedDelivery: expect.any(String), | ||
supplyChannel: expect.objectContaining({ | ||
__typename: 'Channel', | ||
address: expect.objectContaining({ | ||
country: expect.any(String), | ||
}), | ||
}), | ||
supplyChannelRef: expect.objectContaining({ | ||
__typename: 'Reference', | ||
id: expect.any(String), | ||
typeId: 'channel', | ||
}), | ||
custom: null, | ||
__typename: 'InventoryEntry', | ||
}) | ||
); | ||
}); | ||
}); | ||
|
||
describe('InventoryEntry model compatibility builders', () => { | ||
it('builds a REST model', () => { | ||
const restModel = InventoryEntry.random().buildRest(); | ||
|
||
expect(restModel).toEqual( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
key: expect.any(String), | ||
version: expect.any(Number), | ||
createdAt: expect.any(String), | ||
createdBy: expect.any(Object), | ||
lastModifiedAt: expect.any(String), | ||
lastModifiedBy: expect.any(Object), | ||
sku: expect.any(String), | ||
quantityOnStock: expect.any(Number), | ||
restockableInDays: expect.any(Number), | ||
availableQuantity: expect.any(Number), | ||
expectedDelivery: expect.any(String), | ||
supplyChannel: expect.any(Object), | ||
custom: null, | ||
}) | ||
); | ||
}); | ||
|
||
it('builds a GraphQL model', () => { | ||
const graphqlModel = InventoryEntry.random().buildGraphql(); | ||
|
||
expect(graphqlModel).toMatchObject( | ||
expect.objectContaining({ | ||
id: expect.any(String), | ||
key: expect.any(String), | ||
version: expect.any(Number), | ||
createdAt: expect.any(String), | ||
createdBy: expect.any(Object), | ||
lastModifiedAt: expect.any(String), | ||
lastModifiedBy: expect.any(Object), | ||
sku: expect.any(String), | ||
availableQuantity: expect.any(Number), | ||
quantityOnStock: expect.any(Number), | ||
restockableInDays: expect.any(Number), | ||
expectedDelivery: expect.any(String), | ||
supplyChannel: expect.objectContaining({ | ||
__typename: 'Channel', | ||
}), | ||
custom: null, | ||
}) | ||
); | ||
}); | ||
}); |
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,42 @@ | ||
import { | ||
createCompatibilityBuilder, | ||
createSpecializedBuilder, | ||
TModelFieldsConfig, | ||
} from '@commercetools-test-data/core'; | ||
import { restFieldsConfig, graphqlFieldsConfig } from './fields-config'; | ||
import type { | ||
TCreateInventoryEntryBuilder, | ||
TInventoryEntryRest, | ||
TInventoryEntryGraphql, | ||
} from './types'; | ||
|
||
export const RestModelBuilder: TCreateInventoryEntryBuilder< | ||
TInventoryEntryRest | ||
> = () => | ||
createSpecializedBuilder({ | ||
name: 'InventoryEntryRestBuilder', | ||
type: 'rest', | ||
modelFieldsConfig: restFieldsConfig, | ||
}); | ||
|
||
export const GraphqlModelBuilder: TCreateInventoryEntryBuilder< | ||
TInventoryEntryGraphql | ||
> = () => | ||
createSpecializedBuilder({ | ||
name: 'InventoryEntryGraphqlBuilder', | ||
type: 'graphql', | ||
modelFieldsConfig: graphqlFieldsConfig, | ||
}); | ||
|
||
export const CompatInventoryEntryModelBuilder = < | ||
TInventoryEntryModel extends | ||
| TInventoryEntryRest | ||
| TInventoryEntryGraphql = TInventoryEntryRest, | ||
>() => | ||
createCompatibilityBuilder<TInventoryEntryModel>({ | ||
name: 'InventoryEntryCompatBuilder', | ||
modelFieldsConfig: { | ||
rest: restFieldsConfig as TModelFieldsConfig<TInventoryEntryModel>, | ||
graphql: graphqlFieldsConfig as TModelFieldsConfig<TInventoryEntryModel>, | ||
}, | ||
}); |
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,56 @@ | ||
import { ChannelGraphql } from '@commercetools-test-data/channel'; | ||
import { | ||
ClientLogging, | ||
Reference, | ||
TReferenceGraphql, | ||
} from '@commercetools-test-data/commons'; | ||
import { | ||
fake, | ||
sequence, | ||
type TModelFieldsConfig, | ||
} from '@commercetools-test-data/core'; | ||
import { createRelatedDates } from '@commercetools-test-data/utils'; | ||
import type { TInventoryEntryGraphql, TInventoryEntryRest } from './types'; | ||
|
||
const [getOlderDate, getNewerDate, getFutureDate] = createRelatedDates(); | ||
|
||
const commonFieldsConfig = { | ||
id: fake((f) => f.string.uuid()), | ||
version: sequence(), | ||
createdAt: fake(getOlderDate), | ||
createdBy: fake(() => ClientLogging.random()), | ||
lastModifiedAt: fake(getNewerDate), | ||
lastModifiedBy: fake(() => ClientLogging.random()), | ||
key: fake((f) => f.lorem.slug(2)), | ||
sku: fake((f) => f.lorem.words()), | ||
quantityOnStock: fake((f) => f.number.int()), | ||
availableQuantity: fake((f) => f.number.int()), | ||
restockableInDays: fake((f) => f.number.int()), | ||
expectedDelivery: fake(getFutureDate), | ||
custom: null, | ||
}; | ||
export const restFieldsConfig: TModelFieldsConfig<TInventoryEntryRest> = { | ||
fields: { | ||
...commonFieldsConfig, | ||
supplyChannel: fake(() => Reference.presets.channelReference()), | ||
}, | ||
}; | ||
export const graphqlFieldsConfig: TModelFieldsConfig<TInventoryEntryGraphql> = { | ||
fields: { | ||
...commonFieldsConfig, | ||
__typename: 'InventoryEntry', | ||
supplyChannel: fake(() => ChannelGraphql.random()), | ||
supplyChannelRef: fake((f) => Reference.presets.channelReference()), | ||
}, | ||
postBuild: (model) => { | ||
const supplyChannelRef = model.supplyChannel | ||
? Reference.presets | ||
.channelReference() | ||
.id(model.supplyChannel.id) | ||
.buildGraphql<TReferenceGraphql<'channel'>>() | ||
: null; | ||
return { | ||
supplyChannelRef, | ||
}; | ||
}, | ||
}; |
Oops, something went wrong.