Skip to content

Commit

Permalink
Merge 641ebe3 into 0f544d5
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejewsky committed Feb 24, 2021
2 parents 0f544d5 + 641ebe3 commit a4c0efb
Show file tree
Hide file tree
Showing 64 changed files with 362 additions and 664 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('[commercetools-api-client] addToCart', () => {
id: 1,
version: 1
})
}
},
createQuery: (args) => args
};
const product = { id: 1,
sku: '123' } as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('[commercetools-api-client] applyCartCoupon', () => {
id: 1,
version: 1
})
}
},
createQuery: (args) => args
};

const response = await applyCartCoupon(context, cart, 'coupon');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ describe('[commercetools-api-client] createCart', () => {
}
};
}
}
},
createQuery: (args) => args
};

const { data } = await createCart(context, {
Expand Down Expand Up @@ -69,7 +70,8 @@ describe('[commercetools-api-client] createCart', () => {
data: {}
};
}
}
},
createQuery: (args) => args
};

const { data } = await createCart(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,11 @@ describe('[commercetools-api-client] createMyOrderFromCart', () => {
expect(mutation).toEqual(defaultMutation);
return { data: 'order response' };
}
}
};

const { data } = await createMyOrderFromCart(context, { id: '123123', version: 2 });
expect(data).toBe('order response');
});

it('creates new order with custom query', async () => {
const customQuery = defaultMutation;
const customVariables = {
locale: 'de'
};

const context = {
config: {
locale: 'en',
acceptLanguage: ['en', 'de'],
currency: 'USD'
},
client: {
mutate: ({ variables, mutation }) => {
expect(variables).toEqual({ ...givenVariables, ...customVariables });
expect(mutation).toEqual(defaultMutation);
return { data: 'order response' };
}
}
createQuery: (args) => args
};

const { data } = await createMyOrderFromCart(context, { id: '123123', version: 2 }, (query, variables) => {
return {
query: customQuery,
variables: {
...variables,
...customVariables
}
};
});
const { data } = await createMyOrderFromCart(context, { id: '123123', version: 2 });
expect(data).toBe('order response');
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gql from 'graphql-tag';
import getCategory from '../../src/api/getCategory';
import defaultQuery from '../../src/api/getCategory/defaultQuery';

Expand All @@ -21,7 +20,8 @@ describe('[commercetools-api-client] getCategory', () => {

return { data: 'category response' };
}
}
},
createQuery: (args) => args
};

const { data } = await getCategory(context, null);
Expand All @@ -48,62 +48,12 @@ describe('[commercetools-api-client] getCategory', () => {

return { data: 'category response' };
}
}
},
createQuery: (args) => args
};

const { data } = await getCategory(context, { catId: '724b250d-9805-4657-ae73-3c02a63a9a13' });

expect(data).toBe('category response');
});

it('fetches categories with customized query', async () => {
const newQuery = gql`
query categories($where: String, $sort: [String!], $limit: Int, $offset: Int, $acceptLanguage: [Locale!]) {
categories(where: $where, sort: $sort, limit: $limit, offset: $offset) {
offset
count
total
results {
id
name(acceptLanguage: $acceptLanguage)
}
}
}
`;

const newVariables = { id: 1 };

const customQuery = (currentQuery, currentVariables) => {
expect(currentQuery).toEqual(defaultQuery);
expect(currentVariables).toEqual({
acceptLanguage: ['en', 'de'],
where: 'id="724b250d-9805-4657-ae73-3c02a63a9a13"',
limit: undefined,
offset: undefined
});

return {
query: newQuery,
variables: newVariables
};
};

const context = {
config: {
locale: 'en',
acceptLanguage: ['en', 'de'],
currency: 'USD'
},
client: {
query: ({ query, variables }) => {
return { query, variables };
}
}
};

const data: any = await getCategory(context, { catId: '724b250d-9805-4657-ae73-3c02a63a9a13' }, customQuery);

expect(data.query).toBe(newQuery);
expect(data.variables).toBe(newVariables);
});
});
46 changes: 2 additions & 44 deletions packages/commercetools/api-client/__tests__/api/getMe.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getMe from '../../src/api/getMe';
import { basicProfile } from '../../src/api/getMe/defaultQuery';
import gql from 'graphql-tag';

describe('[commercetools-api-client] getMe', () => {
it('fetches current user data', async () => {
Expand All @@ -22,53 +21,12 @@ describe('[commercetools-api-client] getMe', () => {

return { data: 'me response' };
}
}
},
createQuery: (args) => args
};

const { data } = await getMe(context);

expect(data).toBe('me response');
});

it('fetches current user with custom query', async () => {
const givenVariables = {
acceptLanguage: ['en', 'de'],
locale: 'en'
};

const newQuery = gql`
query someQuery {
someQuery { id }
}
`;
const newVariables = { id: 1 };

const customQuery = (defaultQuery, defaultVariables) => {
expect(defaultQuery).toEqual(basicProfile);
expect(defaultVariables).toEqual(givenVariables);

return {
query: newQuery,
variables: newVariables
};
};

const context = {
config: {
locale: 'en',
acceptLanguage: ['en', 'de'],
currency: 'USD'
},
client: {
query: ({ query, variables }) => {
return { query, variables };
}
}
};

const data: any = await getMe(context, { customer: false }, customQuery);

expect(data.query).toBe(newQuery);
expect(data.variables).toBe(newVariables);
});
});
22 changes: 2 additions & 20 deletions packages/commercetools/api-client/__tests__/api/getOrders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,11 @@ describe('[commercetools-api-client] getOrders', () => {
expect(query).toEqual(defaultQuery);
return { data: 'me response' };
}
}
},
createQuery: (args) => args
};

const { data } = await getOrders(context, params);
expect(data).toBe('me response');
});

it('fetches current user orders data with custom variables', async () => {
const context = {
config: {
locale: 'en',
acceptLanguage: ['en', 'de'],
currency: 'USD'
},
client: {
query: ({ variables, query }) => {
expect({ ...variables, where: 'id="fvdrt8gaw4r"' }).toEqual(givenVariables);
expect(query).toEqual(defaultQuery);
return { data: 'me response' };
}
}
};
const { data } = await getOrders(context, params, (query = defaultQuery, variables = givenVariables) => ({ query, variables }));
expect(data).toBe('me response');
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gql from 'graphql-tag';
import getProduct from '../../src/api/getProduct';
import defaultQuery from '../../src/api/getProduct/defaultQuery';

Expand Down Expand Up @@ -26,71 +25,12 @@ describe('[commercetools-api-client] getProduct', () => {

return { data: 'product response' };
}
}
},
createQuery: (args) => args
};

const { data } = await getProduct(context, { catId: ['724b250d-9805-4657-ae73-3c02a63a9a13'] });

expect(data).toBe('product response');
});

it('fetches product with customized query', async () => {
const newQuery = gql`
query products(
$where: String
$sort: [String!]
$limit: Int
$offset: Int
$skus: [String!]
$acceptLanguage: [Locale!]
$currency: Currency!
) {
products(where: $where, sort: $sort, limit: $limit, offset: $offset, skus: $skus) {
results {
id
}
}
}
`;

const newVariables = { id: 1 };

const customQuery = (currentQuery, currentVariables) => {
expect(currentQuery).toEqual(defaultQuery);
expect(currentVariables).toEqual({
acceptLanguage: ['en', 'de'],
country: 'UK',
currency: 'USD',
locale: 'en',
offset: undefined,
skus: undefined,
limit: undefined,
where: 'masterData(current(categories(id in ("724b250d-9805-4657-ae73-3c02a63a9a13"))))'
});

return {
query: newQuery,
variables: newVariables
};
};

const context = {
config: {
locale: 'en',
acceptLanguage: ['en', 'de'],
currency: 'USD',
country: 'UK'
},
client: {
query: ({ query, variables }) => {
return { query, variables };
}
}
};

const data: any = await getProduct(context, { catId: ['724b250d-9805-4657-ae73-3c02a63a9a13'] }, customQuery);

expect(data.query).toEqual(newQuery);
expect(data.variables).toEqual(newVariables);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ describe('[commercetools-api-client] getShippingMethods', () => {

return { data: 'shipping response' };
}
}
},
createQuery: (args) => args
};

const { data } = await getShippingMethods(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('[commercetools-api-client] removeCartCoupon', () => {
id: 1,
version: 1
})
}
},
createQuery: (args) => args
};

const response = await removeCartCoupon(context, cart, { typeId: '123', id: '123'});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('[commercetools-api-client] removeFromCart', () => {
id: 1,
version: 1
})
}
},
createQuery: (args) => args
};

const product = {
Expand Down
Loading

0 comments on commit a4c0efb

Please sign in to comment.