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

fix: color selection error #36

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion packages/api-client/__tests__/api/configureProduct.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ describe('[kibo-api-client] configureProduct', () => {

const product = { productCode: 'ACC1' } as any;

const productResponse = await configureProduct(context, { product, attributes: { color: 'Green' } });
const productResponse = await configureProduct(context, {
product,
attributes: { 'tenant~color': 'Green' }
});

expect(productResponse.data).toEqual('config response');
});
Expand Down
40 changes: 32 additions & 8 deletions packages/api-client/__tests__/api/logInUser.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import logInUser from '../../src/api/logInUser';
import defaultMutation from '../../src/api/logInUser/defaultMutation';

const loginResponse = {
accessToken: 'access token',
accessTokenExpiration: 'access token expiration',
refreshToken: 'refresh token',
userId: 'userId',
refreshTokenExpiration: 'refresh token expiration'
};

describe('[kibo-api-client] logInUser', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('creates user session', async () => {

const givenVariables = {
username: '[email protected]',
password: '12345'
loginInput: {
username: '[email protected]',
password: '12345'
}
};
const context = {
config: {
Expand All @@ -18,14 +28,28 @@ describe('[kibo-api-client] logInUser', () => {
currency: 'USD'
},
client: {
loginCustomerAndSetAuthTicket: (params) =>{
expect(params).toEqual(givenVariables);
return { data: 'user response' };
mutate: ({ variables, mutation }) => {
expect(variables).toStrictEqual(givenVariables);
expect(mutation).toEqual(defaultMutation);

return {
data: {
account: loginResponse
}
};
},
shopperAuthManager: {
setTicket: (data) => {
expect(data).toStrictEqual(loginResponse);
}
}
}
};

const { data } = await logInUser(context, givenVariables) as any;
expect(data).toBe('user response');
const { data } = (await logInUser(
context,
givenVariables.loginInput
)) as any;
expect(data).toStrictEqual({ account: loginResponse });
});
});
14 changes: 10 additions & 4 deletions packages/api-client/src/api/configureProduct/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Context } from '@vue-storefront/core';
import defaultMutation from './defaultMutation';
import { ConfigureProductResponse, InternalConfigureProductParams } from '../../types/Api';
import {
ConfigureProductResponse,
InternalConfigureProductParams
} from '../../types/Api';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export default async function configureProduct(context: Context, params: InternalConfigureProductParams): Promise<ConfigureProductResponse> {
const attributes = Object.keys(params.attributes).map(a => ({
attributeFQN: `tenant~${a}`,
export default async function configureProduct(
context: Context,
params: InternalConfigureProductParams
): Promise<ConfigureProductResponse> {
const attributes = Object.keys(params.attributes).map((a) => ({
attributeFQN: a,
value: params.attributes[a]
}));
const product = params.product;
Expand Down
38 changes: 34 additions & 4 deletions packages/api-client/src/api/logInUser/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
/* eslint camelcase: "warn"*/
import { Context } from '@vue-storefront/core';
import { KiboApolloClient } from '@kibocommerce/graphql-client';
import loginMutation from './defaultMutation';
import { LogInUserParams, LogInUserResponse } from '../../types/Api';
import { KiboApolloClient } from '@kibocommerce/graphql-client';

const loginUser = async (context:Context, params:LogInUserParams): Promise<LogInUserResponse> => {
const client = context.client as KiboApolloClient;
const loginUser = async (
context: Context,
params: LogInUserParams
): Promise<LogInUserResponse> => {
const { username, password } = params;
const loginResponse = await client.loginCustomerAndSetAuthTicket({ username, password }) as any;
const client = context.client as KiboApolloClient;
const loginResponse = await context.client.mutate({
mutation: loginMutation,
variables: {
loginInput: {
username,
password
}
},
fetchPolicy: 'no-cache'
});

const {
accessToken,
accessTokenExpiration,
refreshToken,
userId,
refreshTokenExpiration
} = loginResponse.data.account;

client.shopperAuthManager.setTicket({
accessToken,
accessTokenExpiration,
refreshToken,
userId,
refreshTokenExpiration
});

return loginResponse;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/composables/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"dependencies": {
"@vue-storefront/core": "~2.5.0",
"@vue-storefront/kibocommerce-api": "^1.0.0-beta.4",
"@vue-storefront/kibocommerce-api": "^1.0.3-beta.7",
"vue": "^2.6.12",
"@vue/composition-api": "^1.3.3",
"vue-demi": "^0.12.1",
Expand Down
Loading