diff --git a/standalone/src/models/platform-limits/customers/builder.spec.ts b/standalone/src/models/platform-limits/customers/builder.spec.ts index 5ccd3982c0..f26a82b702 100644 --- a/standalone/src/models/platform-limits/customers/builder.spec.ts +++ b/standalone/src/models/platform-limits/customers/builder.spec.ts @@ -8,33 +8,91 @@ const expectedLimitWithCurrent = expect.objectContaining({ limit: expect.any(Number), current: expect.any(Number), }); + +const expectedLimitWithMaxGroupsPerCustomer = expect.objectContaining({ + limit: expect.any(Number), +}); + describe('building', () => { - it( - ...createBuilderSpec( - 'default', - CustomerLimitsProjection.presets.withLimitAndCurrent(), - expect.objectContaining({ - total: expectedLimitWithCurrent, - }) - ) - ); - it( - ...createBuilderSpec( - 'rest', - CustomerLimitsProjection.presets.withLimitAndCurrent(), - expect.objectContaining({ - total: expectedLimitWithCurrent, - }) - ) - ); - it( - ...createBuilderSpec( - 'graphql', - CustomerLimitsProjection.presets.withLimitAndCurrent(), - expect.objectContaining({ - total: expectedLimitWithCurrent, - __typename: 'CustomerLimitsProjection', - }) - ) - ); + describe('with total limit and current', () => { + it( + ...createBuilderSpec< + TCustomerLimitsProjection, + TCustomerLimitsProjection + >( + 'default', + CustomerLimitsProjection.presets.withLimitAndCurrent(), + expect.objectContaining({ + total: expectedLimitWithCurrent, + }) + ) + ); + it( + ...createBuilderSpec< + TCustomerLimitsProjection, + TCustomerLimitsProjection + >( + 'rest', + CustomerLimitsProjection.presets.withLimitAndCurrent(), + expect.objectContaining({ + total: expectedLimitWithCurrent, + }) + ) + ); + it( + ...createBuilderSpec< + TCustomerLimitsProjection, + TCustomerLimitsProjection + >( + 'graphql', + CustomerLimitsProjection.presets.withLimitAndCurrent(), + expect.objectContaining({ + total: expectedLimitWithCurrent, + __typename: 'CustomerLimitsProjection', + }) + ) + ); + }); + describe('with total limit and current, and max groups per customer', () => { + it( + ...createBuilderSpec< + TCustomerLimitsProjection, + TCustomerLimitsProjection + >( + 'default', + CustomerLimitsProjection.presets.withTotalLimitAndCurrentAndMaxGroupsPerCustomer(), + expect.objectContaining({ + total: expectedLimitWithCurrent, + maxGroupsPerCustomer: expectedLimitWithMaxGroupsPerCustomer, + }) + ) + ); + it( + ...createBuilderSpec< + TCustomerLimitsProjection, + TCustomerLimitsProjection + >( + 'rest', + CustomerLimitsProjection.presets.withTotalLimitAndCurrentAndMaxGroupsPerCustomer(), + expect.objectContaining({ + total: expectedLimitWithCurrent, + maxGroupsPerCustomer: expectedLimitWithMaxGroupsPerCustomer, + }) + ) + ); + it( + ...createBuilderSpec< + TCustomerLimitsProjection, + TCustomerLimitsProjection + >( + 'graphql', + CustomerLimitsProjection.presets.withTotalLimitAndCurrentAndMaxGroupsPerCustomer(), + expect.objectContaining({ + total: expectedLimitWithCurrent, + maxGroupsPerCustomer: expectedLimitWithMaxGroupsPerCustomer, + __typename: 'CustomerLimitsProjection', + }) + ) + ); + }); }); diff --git a/standalone/src/models/platform-limits/customers/generator.ts b/standalone/src/models/platform-limits/customers/generator.ts index 75c45a31ed..9624ca4a31 100644 --- a/standalone/src/models/platform-limits/customers/generator.ts +++ b/standalone/src/models/platform-limits/customers/generator.ts @@ -6,6 +6,7 @@ import { TCustomerLimitsProjection } from './types'; */ const generator = Generator({ fields: { + maxGroupsPerCustomer: null, total: null, }, }); diff --git a/standalone/src/models/platform-limits/customers/presets/index.ts b/standalone/src/models/platform-limits/customers/presets/index.ts index 39aaff2c5d..2fe2157581 100644 --- a/standalone/src/models/platform-limits/customers/presets/index.ts +++ b/standalone/src/models/platform-limits/customers/presets/index.ts @@ -1,5 +1,7 @@ import withLimitAndCurrent from './with-limit-and-current'; +import withTotalLimitAndCurrentAndMaxGroupsPerCustomer from './with-total-limit-and-current-and-max-groups-per-customer'; export default { withLimitAndCurrent, + withTotalLimitAndCurrentAndMaxGroupsPerCustomer, }; diff --git a/standalone/src/models/platform-limits/customers/presets/with-total-limit-and-current-and-max-groups-per-customer.ts b/standalone/src/models/platform-limits/customers/presets/with-total-limit-and-current-and-max-groups-per-customer.ts new file mode 100644 index 0000000000..70c07705c2 --- /dev/null +++ b/standalone/src/models/platform-limits/customers/presets/with-total-limit-and-current-and-max-groups-per-customer.ts @@ -0,0 +1,10 @@ +import * as Limit from '../../limit'; +import * as LimitWithCurrent from '../../limit-with-current'; +import CustomersPlatformLimits from '../builder'; + +const withLimitAndCurrent = () => + CustomersPlatformLimits() + .total(LimitWithCurrent.random()) + .maxGroupsPerCustomer(Limit.random()); + +export default withLimitAndCurrent; diff --git a/standalone/src/models/platform-limits/customers/transformers.ts b/standalone/src/models/platform-limits/customers/transformers.ts index 9248c79271..0d4fa708e6 100644 --- a/standalone/src/models/platform-limits/customers/transformers.ts +++ b/standalone/src/models/platform-limits/customers/transformers.ts @@ -8,20 +8,20 @@ const transformers = { default: Transformer( 'default', { - buildFields: ['total'], + buildFields: ['total', 'maxGroupsPerCustomer'], } ), rest: Transformer( 'rest', { - buildFields: ['total'], + buildFields: ['total', 'maxGroupsPerCustomer'], } ), graphql: Transformer< TCustomerLimitsProjection, TCustomerLimitsProjectionGraphql >('graphql', { - buildFields: ['total'], + buildFields: ['total', 'maxGroupsPerCustomer'], addFields: () => ({ __typename: 'CustomerLimitsProjection', }), diff --git a/standalone/src/models/platform-limits/customers/types.ts b/standalone/src/models/platform-limits/customers/types.ts index 6edf266ccf..6139f74bb8 100644 --- a/standalone/src/models/platform-limits/customers/types.ts +++ b/standalone/src/models/platform-limits/customers/types.ts @@ -1,7 +1,9 @@ import type { TBuilder } from '@/core'; +import type { TLimit } from '../limit'; import type { TLimitWithCurrent } from '../limit-with-current'; export type TCustomerLimitsProjection = { + maxGroupsPerCustomer: TLimit; total: TLimitWithCurrent; };