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

IT Merchant Order #284

Merged
merged 6 commits into from
Oct 16, 2023
Merged
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
51 changes: 51 additions & 0 deletions e2e/merchantOrder/create.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { PreferenceCreateData } from '@src/clients/preference/create/types';
import MercadoPago, { MerchantOrder, Preference } from '@src/index';
import { config } from '../e2e.config';

describe('Testing merchantOrder, create', () => {
test('should generate an order and match with declared shape', async () => {
const client = new MercadoPago({ accessToken: config.access_token });
const preference = new Preference(client);
const merchantOrder = new MerchantOrder(client);

const preferenceRequest: PreferenceCreateData = {
body: {
items: [
{
id: '4567',
category_id: 'car_electronics',
currency_id: 'BRL',
description: 'Dummy create',
title: 'Dummy Title',
quantity: 1,
unit_price: 10
}
],
}
};

const preferenceCreate = await preference.create(preferenceRequest);

const body = {
preference_id: preferenceCreate.id,
};
const createOrder = await merchantOrder.create({ body });
expect(createOrder.preference_id).toBe(preferenceCreate.id);
expect(createOrder).toEqual(expect.objectContaining({
id: expect.any(Number),
preference_id: expect.any(String),
status: expect.any(String),
site_id: expect.any(String),
collector: expect.any(Object),
date_created: expect.any(String),
last_updated: expect.any(String),
shipping_cost: expect.any(Number),
total_amount: expect.any(Number),
paid_amount: expect.any(Number),
refunded_amount: expect.any(Number),
cancelled: expect.any(Boolean),
order_status: expect.any(String),
is_test: expect.any(Boolean),
}));
});
});
54 changes: 54 additions & 0 deletions e2e/merchantOrder/get.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { PreferenceCreateData } from '@src/clients/preference/create/types';
import MercadoPago, { MerchantOrder, Preference } from '@src/index';
import { config } from '../e2e.config';

describe('Testing merchantOrder, get', () => {
test('should get an order and match with declared shape', async () => {
const client = new MercadoPago({ accessToken: config.access_token });
const preference = new Preference(client);
const merchantOrder = new MerchantOrder(client);

const preferenceRequest: PreferenceCreateData = {
body: {
items: [
{
id: '4567',
category_id: 'car_electronics',
currency_id: 'BRL',
description: 'Dummy create',
title: 'Dummy Title',
quantity: 1,
unit_price: 10
}
],
}
};

const preferenceCreate = await preference.create(preferenceRequest);

const body = {
preference_id: preferenceCreate.id,
};
const createOrder = await merchantOrder.create({ body });
expect(createOrder).toHaveProperty('id');

const getOrder = await merchantOrder.get({ merchantOrderId: createOrder.id });
expect(getOrder.id).toBe(createOrder.id);
expect(getOrder).toEqual(expect.objectContaining({
id: expect.any(Number),
preference_id: expect.any(String),
status: expect.any(String),
site_id: expect.any(String),
collector: expect.any(Object),
date_created: expect.any(String),
last_updated: expect.any(String),
shipping_cost: expect.any(Number),
total_amount: expect.any(Number),
paid_amount: expect.any(Number),
refunded_amount: expect.any(Number),
cancelled: expect.any(Boolean),
order_status: expect.any(String),
is_test: expect.any(Boolean),
}));
});
});
67 changes: 67 additions & 0 deletions e2e/merchantOrder/search.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { PreferenceCreateData } from '@src/clients/preference/create/types';
import MercadoPago, { MerchantOrder, Preference } from '@src/index';
import { config } from '../e2e.config';

describe('Testing merchantOrder, search', () => {
test('should search an order and match with declared shape', async () => {
const client = new MercadoPago({ accessToken: config.access_token });
const preference = new Preference(client);
const merchantOrder = new MerchantOrder(client);

const preferenceRequest: PreferenceCreateData = {
body: {
items: [
{
id: '4567',
category_id: 'car_electronics',
currency_id: 'BRL',
description: 'Dummy create',
title: 'Dummy Title',
quantity: 1,
unit_price: 10
}
],
}
};

const preferenceCreate = await preference.create(preferenceRequest);

const body = {
preference_id: preferenceCreate.id,
};
const createOrder = await merchantOrder.create({ body });
expect(createOrder).toHaveProperty('id');

console.log('oi');
await new Promise(res => setTimeout(res, 10000));
console.log('oioi');

const options = {
preference_id: preferenceCreate.id,
};

const searchOrder = await merchantOrder.search({ options: options });
expect(searchOrder).toEqual(expect.objectContaining({
elements: expect.any(Array),
next_offset: expect.any(Number),
total: expect.any(Number),
}));
expect(searchOrder.elements[0].preference_id).toBe(options.preference_id);
expect(searchOrder.elements[0]).toEqual(expect.objectContaining({
id: expect.any(Number),
preference_id: expect.any(String),
status: expect.any(String),
site_id: expect.any(String),
collector: expect.any(Object),
date_created: expect.any(String),
last_updated: expect.any(String),
shipping_cost: expect.any(Number),
total_amount: expect.any(Number),
paid_amount: expect.any(Number),
refunded_amount: expect.any(Number),
cancelled: expect.any(Boolean),
order_status: expect.any(String),
is_test: expect.any(Boolean),
}));
}, 15000);
});
59 changes: 59 additions & 0 deletions e2e/merchantOrder/update.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { PreferenceCreateData } from '@src/clients/preference/create/types';
import MercadoPago, { MerchantOrder, Preference } from '@src/index';
import { config } from '../e2e.config';

describe('Testing merchantOrder, update', () => {
test('should update an order and match with declared shape', async () => {
const client = new MercadoPago({ accessToken: config.access_token });
const preference = new Preference(client);
const merchantOrder = new MerchantOrder(client);

const preferenceRequest: PreferenceCreateData = {
body: {
items: [
{
id: '4567',
category_id: 'car_electronics',
currency_id: 'BRL',
description: 'Dummy create',
title: 'Dummy Title',
quantity: 1,
unit_price: 10
}
],
}
};

const preferenceCreate = await preference.create(preferenceRequest);

const body = {
preference_id: preferenceCreate.id,
};
const createOrder = await merchantOrder.create({ body });
expect(createOrder).toHaveProperty('id');

const updateBody = {
notification_url: 'https://www.test.com'
};

const updateOrder = await merchantOrder.update({ merchantOrderId: createOrder.id, body: updateBody });
expect(updateOrder.preference_id).toBe(preferenceCreate.id);
expect(updateOrder.notification_url).toBe(updateBody.notification_url);
expect(updateOrder).toEqual(expect.objectContaining({
id: expect.any(Number),
preference_id: expect.any(String),
status: expect.any(String),
site_id: expect.any(String),
collector: expect.any(Object),
date_created: expect.any(String),
last_updated: expect.any(String),
shipping_cost: expect.any(Number),
total_amount: expect.any(Number),
paid_amount: expect.any(Number),
refunded_amount: expect.any(Number),
cancelled: expect.any(Boolean),
order_status: expect.any(String),
is_test: expect.any(Boolean),
}));
});
});
1 change: 1 addition & 0 deletions src/clients/merchantOrder/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export declare interface MerchantOrderResponse extends ApiResponse {
total_amount?: number;
order_status?: string;
last_updated?: string;
is_test: boolean;
}

export declare type MerchantOrderPayer = {
Expand Down
4 changes: 2 additions & 2 deletions src/clients/merchantOrder/get/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import type { MercadoPagoConfig } from '@src/mercadoPagoConfig';
import { Options } from '@src/types';

export declare type MerchantOrderGetClient = {
merchantOrderId: string;
merchantOrderId: string | number;
config: MercadoPagoConfig;
}

export declare type MerchantOrderGetData = {
merchantOrderId: string;
merchantOrderId: string | number;
requestOptions?: Options;
}
9 changes: 2 additions & 7 deletions src/clients/merchantOrder/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ export declare interface MerchantOrderSearchOptions extends SearchOptions {
}

export declare type MerchantOrderSearchResultsPage = {
results?: MerchantOrderResponse[];
paging?: Paging;
};

export declare type Paging = {
elements?: MerchantOrderResponse[];
next_offset?: number;
total: number;
offset: number;
limit: number;
};
4 changes: 2 additions & 2 deletions src/clients/merchantOrder/update/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import type { Collector, MerchantOrderItemRequest, MerchantOrderPayerRequest } f
import type { Options } from '@src/types';

export declare type MerchantOrderUpdateClient = {
merchantOrderId: string;
merchantOrderId: string | number;
config: MercadoPagoConfig;
body: MerchantOrderUpdateBody;
}

export declare type MerchantOrderUpdateData = {
merchantOrderId: string;
merchantOrderId: string | number;
body: MerchantOrderUpdateBody;
requestOptions?: Options;
}
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.production.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig",
"exclude": ["node_modules", "**/*spec.ts", "src/examples/**/*"]
"exclude": ["node_modules", "**/*spec.ts", "src/examples", "e2e"]
}