diff --git a/e2e/merchantOrder/create.spec.ts b/e2e/merchantOrder/create.spec.ts new file mode 100644 index 00000000..a776a7ee --- /dev/null +++ b/e2e/merchantOrder/create.spec.ts @@ -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 pass forward request options from create to RestClient.fetch', async () => { + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + 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), + })); + }); +}); diff --git a/e2e/merchantOrder/get.spec.ts b/e2e/merchantOrder/get.spec.ts new file mode 100644 index 00000000..a458a815 --- /dev/null +++ b/e2e/merchantOrder/get.spec.ts @@ -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, create', () => { + test('should pass forward request options from create to RestClient.fetch', async () => { + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + 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: String(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), + })); + }); +}); diff --git a/e2e/merchantOrder/search.spec.ts b/e2e/merchantOrder/search.spec.ts new file mode 100644 index 00000000..713ba92d --- /dev/null +++ b/e2e/merchantOrder/search.spec.ts @@ -0,0 +1,61 @@ +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 pass forward request options from create to RestClient.fetch', async () => { + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + 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 options = { + preferente_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]).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), + })); + }); +}); diff --git a/src/clients/merchantOrder/search/types.ts b/src/clients/merchantOrder/search/types.ts index 44a8d2a7..92339dde 100644 --- a/src/clients/merchantOrder/search/types.ts +++ b/src/clients/merchantOrder/search/types.ts @@ -30,8 +30,9 @@ export declare interface MerchantOrderSearchOptions extends SearchOptions { } export declare type MerchantOrderSearchResultsPage = { - results?: MerchantOrderResponse[]; - paging?: Paging; + elements?: MerchantOrderResponse[]; + next_offset?: number; + total: number; }; export declare type Paging = {