Skip to content

Commit

Permalink
fix(core): Add constraints to Channel currencyCode settings
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Nov 13, 2023
1 parent c8361d9 commit 0ebf0fb
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 29 deletions.
3 changes: 2 additions & 1 deletion packages/admin-ui/src/lib/core/src/common/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3988,6 +3988,7 @@ export type OrderLine = Node & {
proratedUnitPrice: Scalars['Money']['output'];
/** The proratedUnitPrice including tax */
proratedUnitPriceWithTax: Scalars['Money']['output'];
/** The quantity of items purchased */
quantity: Scalars['Int']['output'];
taxLines: Array<TaxLine>;
taxRate: Scalars['Float']['output'];
Expand Down Expand Up @@ -4731,7 +4732,7 @@ export type ProductVariantListOptions = {
export type ProductVariantPrice = {
__typename?: 'ProductVariantPrice';
currencyCode: CurrencyCode;
price: Scalars['Int']['output'];
price: Scalars['Money']['output'];
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3823,6 +3823,7 @@ export type OrderLine = Node & {
proratedUnitPrice: Scalars['Money']['output'];
/** The proratedUnitPrice including tax */
proratedUnitPriceWithTax: Scalars['Money']['output'];
/** The quantity of items purchased */
quantity: Scalars['Int']['output'];
taxLines: Array<TaxLine>;
taxRate: Scalars['Float']['output'];
Expand Down Expand Up @@ -4536,7 +4537,7 @@ export type ProductVariantListOptions = {

export type ProductVariantPrice = {
currencyCode: CurrencyCode;
price: Scalars['Int']['output'];
price: Scalars['Money']['output'];
};

/**
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2086,6 +2086,7 @@ export type OrderLine = Node & {
proratedUnitPrice: Scalars['Money']['output'];
/** The proratedUnitPrice including tax */
proratedUnitPriceWithTax: Scalars['Money']['output'];
/** The quantity of items purchased */
quantity: Scalars['Int']['output'];
taxLines: Array<TaxLine>;
taxRate: Scalars['Float']['output'];
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3914,6 +3914,7 @@ export type OrderLine = Node & {
proratedUnitPrice: Scalars['Money']['output'];
/** The proratedUnitPrice including tax */
proratedUnitPriceWithTax: Scalars['Money']['output'];
/** The quantity of items purchased */
quantity: Scalars['Int']['output'];
taxLines: Array<TaxLine>;
taxRate: Scalars['Float']['output'];
Expand Down Expand Up @@ -4656,7 +4657,7 @@ export type ProductVariantListOptions = {
export type ProductVariantPrice = {
__typename?: 'ProductVariantPrice';
currencyCode: CurrencyCode;
price: Scalars['Int']['output'];
price: Scalars['Money']['output'];
};

/**
Expand Down
111 changes: 98 additions & 13 deletions packages/core/e2e/channel.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,19 @@ describe('Channels', () => {
});
});

it('update currencyCode', async () => {
const { updateChannel } = await adminClient.query<
Codegen.UpdateChannelMutation,
Codegen.UpdateChannelMutationVariables
>(UPDATE_CHANNEL, {
input: {
id: 'T_1',
currencyCode: CurrencyCode.MYR,
},
});
channelGuard.assertSuccess(updateChannel);
expect(updateChannel.currencyCode).toBe('MYR');
});
// it('update currencyCode', async () => {
// const { updateChannel } = await adminClient.query<
// Codegen.UpdateChannelMutation,
// Codegen.UpdateChannelMutationVariables
// >(UPDATE_CHANNEL, {
// input: {
// id: 'T_1',
// currencyCode: CurrencyCode.MYR,
// },
// });
// channelGuard.assertSuccess(updateChannel);
// expect(updateChannel.currencyCode).toBe('MYR');
// });

it('superadmin has all permissions on new channel', async () => {
const { me } = await adminClient.query<Codegen.MeQuery>(ME);
Expand Down Expand Up @@ -368,6 +368,75 @@ describe('Channels', () => {
});
expect(product!.channels.map(c => c.id)).toEqual(['T_1']);
});

describe('currencyCode support', () => {
beforeAll(async () => {
await adminClient.asSuperAdmin();
adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
});

it('initial currencyCode values', async () => {
const { channel } = await adminClient.query<
Codegen.GetChannelQuery,
Codegen.GetChannelQueryVariables
>(GET_CHANNEL, {
id: 'T_1',
});

expect(channel?.defaultCurrencyCode).toBe('USD');
expect(channel?.availableCurrencyCodes).toEqual(['USD']);
});

it('setting defaultCurrencyCode adds it to availableCurrencyCodes', async () => {
const { updateChannel } = await adminClient.query<
Codegen.UpdateChannelMutation,
Codegen.UpdateChannelMutationVariables
>(UPDATE_CHANNEL, {
input: {
id: 'T_1',
defaultCurrencyCode: CurrencyCode.MYR,
},
});
channelGuard.assertSuccess(updateChannel);
expect(updateChannel.defaultCurrencyCode).toBe('MYR');
expect(updateChannel.currencyCode).toBe('MYR');
expect(updateChannel.availableCurrencyCodes).toEqual(['USD', 'MYR']);
});

it('setting defaultCurrencyCode adds it to availableCurrencyCodes 2', async () => {
// As above, but this time we set the availableCurrencyCodes explicitly
// to exclude the defaultCurrencyCode
const { updateChannel } = await adminClient.query<
Codegen.UpdateChannelMutation,
Codegen.UpdateChannelMutationVariables
>(UPDATE_CHANNEL, {
input: {
id: 'T_1',
defaultCurrencyCode: CurrencyCode.AUD,
availableCurrencyCodes: [CurrencyCode.GBP],
},
});
channelGuard.assertSuccess(updateChannel);
expect(updateChannel.defaultCurrencyCode).toBe('AUD');
expect(updateChannel.currencyCode).toBe('AUD');
expect(updateChannel.availableCurrencyCodes).toEqual(['GBP', 'AUD']);
});

it(
'cannot remove the defaultCurrencyCode from availableCurrencyCodes',
assertThrowsWithMessage(async () => {
await adminClient.query<
Codegen.UpdateChannelMutation,
Codegen.UpdateChannelMutationVariables
>(UPDATE_CHANNEL, {
input: {
id: 'T_1',
availableCurrencyCodes: [CurrencyCode.GBP],
},
});
}, 'availableCurrencyCodes must include the defaultCurrencyCode (AUD)'),
);
});
});

const DELETE_CHANNEL = gql`
Expand All @@ -379,6 +448,22 @@ const DELETE_CHANNEL = gql`
}
`;

const GET_CHANNEL = gql`
query GetChannel($id: ID!) {
channel(id: $id) {
id
code
token
defaultCurrencyCode
availableCurrencyCodes
defaultLanguageCode
availableLanguageCodes
outOfStockThreshold
pricesIncludeTax
}
}
`;

const UPDATE_GLOBAL_LANGUAGES = gql`
mutation UpdateGlobalLanguages($input: UpdateGlobalSettingsInput!) {
updateGlobalSettings(input: $input) {
Expand Down
Loading

0 comments on commit 0ebf0fb

Please sign in to comment.