Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
114 changes: 86 additions & 28 deletions standalone/src/models/platform-limits/customers/builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<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', () => {
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',
})
)
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TCustomerLimitsProjection } from './types';
*/
const generator = Generator<TCustomerLimitsProjection>({
fields: {
maxGroupsPerCustomer: null,
total: null,
},
});
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
};
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ const transformers = {
default: Transformer<TCustomerLimitsProjection, TCustomerLimitsProjection>(
'default',
{
buildFields: ['total'],
buildFields: ['total', 'maxGroupsPerCustomer'],
}
),
rest: Transformer<TCustomerLimitsProjection, TCustomerLimitsProjection>(
'rest',
{
buildFields: ['total'],
buildFields: ['total', 'maxGroupsPerCustomer'],
}
),
graphql: Transformer<
TCustomerLimitsProjection,
TCustomerLimitsProjectionGraphql
>('graphql', {
buildFields: ['total'],
buildFields: ['total', 'maxGroupsPerCustomer'],
addFields: () => ({
__typename: 'CustomerLimitsProjection',
}),
Expand Down
2 changes: 2 additions & 0 deletions standalone/src/models/platform-limits/customers/types.ts
Original file line number Diff line number Diff line change
@@ -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;
};

Expand Down