Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEC-88] Migrating test data model Inventory Entry #703

Merged
merged 20 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
986b29f
feat(inventory entry): update test data model migrating to new implem…
jmcreasman Oct 31, 2024
0ccb365
feat(inventory entry): add changeset
jmcreasman Oct 31, 2024
561d643
feat(inventory entry): fix error
jmcreasman Oct 31, 2024
7213a80
feat(inventory entry): fix TS errors
jmcreasman Nov 1, 2024
c64602d
feat(inventory entry): fix TS error
jmcreasman Nov 1, 2024
c67857a
feat(inventory entry): update tests
jmcreasman Nov 1, 2024
952ee72
feat(inventory entry): update tests
jmcreasman Nov 1, 2024
9e3eb9a
refactor(inventory-entry): ts types adjustments and supplychannel fie…
CarlosCortizasCT Nov 4, 2024
3df930b
feat(inventory entry): remove unneeded transformer and generator files
jmcreasman Nov 4, 2024
6242dd5
feat(inventory entry): update with migrating the draft
jmcreasman Nov 5, 2024
47cb2dc
feat(inventory entry): remove unused imports
jmcreasman Nov 5, 2024
f4d89be
feat(inventory entry): fix tests
jmcreasman Nov 6, 2024
4b41f56
Update .changeset/metal-mice-sit.md
jmcreasman Nov 6, 2024
cbeea9a
feat(inventory entry): update presets with new implementation part 1
jmcreasman Nov 6, 2024
a08f5d9
feat(inventory entry): update presets with new implementation part 2
jmcreasman Nov 6, 2024
f063954
feat(inventory entry): update based on PR feedback
jmcreasman Nov 6, 2024
8ea98a2
feat(inventory entry): remove commented out code
jmcreasman Nov 7, 2024
4c40fbe
refactor(inventory-entry): refactored sample data presets
CarlosCortizasCT Nov 20, 2024
9dd1d6a
refactor(inventory-entry): reorder presets imports in their barrel files
CarlosCortizasCT Nov 20, 2024
686736a
chore: update readmes of migrated data models
CarlosCortizasCT Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/metal-mice-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-test-data/inventory-entry': minor
---

feat(inventory entry): update test data model migrating to new implementation
jmcreasman marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 0 additions & 12 deletions models/inventory-entry/src/builder.ts

This file was deleted.

42 changes: 42 additions & 0 deletions models/inventory-entry/src/builders.ts
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>,
},
});
55 changes: 55 additions & 0 deletions models/inventory-entry/src/fields-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Channel } 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()),
supplyChannel: fake(() => Channel.random()),
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,
},
};
export const graphqlFieldsConfig: TModelFieldsConfig<TInventoryEntryGraphql> = {
fields: {
...commonFieldsConfig,
__typename: 'InventoryEntry',
supplyChannelRef: fake((f) => f.string.uuid()),
},
postBuild: (model) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not 100% sure if I did this part correctly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

const supply = model.supplyChannelRef
? Reference.presets
.channelReference()
.id(model.supplyChannel.id)
.buildGraphql<TReferenceGraphql<'channel'>>()
: undefined;
return {
supply,
};
},
};
29 changes: 26 additions & 3 deletions models/inventory-entry/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,29 @@
export * as InventoryEntryDraft from './inventory-entry-draft';
import {
RestModelBuilder,
GraphqlModelBuilder,
CompatInventoryEntryModelBuilder,
} from './builders';
import * as modelPresets from './presets';

export * from './inventory-entry-draft';
export * as InventoryEntry from '.';

export { default as random } from './builder';
export { default as presets } from './presets';
export * from './types';

export const InventoryEntryRest = {
random: RestModelBuilder,
presets: modelPresets.restPresets,
};

export const InventoryEntryGraphql = {
random: GraphqlModelBuilder,
presets: modelPresets.graphqlPresets,
};

/**
* @deprecated Use `InventoryEntryRest` or `InventoryEntryGraphql` exported models instead of `InventoryEntry`.
*/
export const deprecatedInventoryEntry = {
random: CompatInventoryEntryModelBuilder,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Originally I had this looking like the doc example but I was getting this error when trying to commit:

models/inventory-entry/src/index.ts:8:1
✖ 8:1 Multiple exports of name random. import/export
✖ 8:1 Multiple exports of name presets. import/export
✖ 26:14 Multiple exports of name random. import/export
✖ 27:14 Multiple exports of name presets. import/export

So I changed it to this and that made it happier. Let me know if that's not correct though.

Copy link
Contributor

@CarlosCortizasCT CarlosCortizasCT Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that was because the draft model has not been migrated yet.

presets: modelPresets.restPresets,
};
24 changes: 22 additions & 2 deletions models/inventory-entry/src/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
const presets = {};
import type { TBuilder } from '@commercetools-test-data/core';
import {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The index file of presets should export just plain objects with the presets for each representation.
In this case, we don't have any presets implemented for this model, so it would be something like this:

export const restPresets = {};
export const graphqlPresets = {};

InventoryEntry,
InventoryEntryGraphql,
InventoryEntryRest,
} from '../index';
import type {
TInventoryEntry,
TInventoryEntryGraphql,
TInventoryEntryRest,
} from '../types';

export default presets;
const populatePreset = <
TModel extends TInventoryEntryGraphql | TInventoryEntryRest,
>() => {
return;
};

export const restPreset = (): TBuilder<TInventoryEntryRest> => {};

export const graphqlPreset = (): TBuilder<TInventoryEntryGraphql> => {};

export const compatPreset = (): TBuilder<TInventoryEntry> => {};
3 changes: 3 additions & 0 deletions models/inventory-entry/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import type { TReferenceGraphql } from '@commercetools-test-data/commons';
import type { TBuilder } from '@commercetools-test-data/core';

// Default
/**
* @deprecated use `TInventoryEntryRest` instead
*/
export type TInventoryEntry = Omit<InventoryEntry, 'supplyChannel'> & {
supplyChannel: Channel;
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this PR do I need to do anything about the InventoryEntryDraft? I didn't see anything about that in the docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to migrate that model as well.

Expand Down
Loading