|
| 1 | +import { PreferenceCreateData } from '@src/clients/preference/create/types'; |
| 2 | +import MercadoPago, { MerchantOrder, Preference } from '@src/index'; |
| 3 | +import { config } from '../e2e.config'; |
| 4 | + |
| 5 | +describe('Testing merchantOrder, create', () => { |
| 6 | + test('should pass forward request options from create to RestClient.fetch', async () => { |
| 7 | + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); |
| 8 | + const preference = new Preference(client); |
| 9 | + const merchantOrder = new MerchantOrder(client); |
| 10 | + |
| 11 | + const preferenceRequest: PreferenceCreateData = { |
| 12 | + body: { |
| 13 | + items: [ |
| 14 | + { |
| 15 | + id: '4567', |
| 16 | + category_id: 'car_electronics', |
| 17 | + currency_id: 'BRL', |
| 18 | + description: 'Dummy create', |
| 19 | + title: 'Dummy Title', |
| 20 | + quantity: 1, |
| 21 | + unit_price: 10 |
| 22 | + } |
| 23 | + ], |
| 24 | + } |
| 25 | + }; |
| 26 | + |
| 27 | + const preferenceCreate = await preference.create(preferenceRequest); |
| 28 | + |
| 29 | + const body = { |
| 30 | + preference_id: preferenceCreate.id, |
| 31 | + }; |
| 32 | + const createOrder = await merchantOrder.create({ body }); |
| 33 | + expect(createOrder).toHaveProperty('id'); |
| 34 | + |
| 35 | + const updateBody = { |
| 36 | + notification_url: 'https://www.test.com' |
| 37 | + }; |
| 38 | + |
| 39 | + const updateOrder = await merchantOrder.update({ merchantOrderId: String(createOrder.id), body: updateBody }); |
| 40 | + expect(updateOrder.preference_id).toBe(preferenceCreate.id); |
| 41 | + expect(updateOrder.notification_url).toBe(updateBody.notification_url); |
| 42 | + expect(updateOrder).toEqual(expect.objectContaining({ |
| 43 | + id: expect.any(Number), |
| 44 | + preference_id: expect.any(String), |
| 45 | + status: expect.any(String), |
| 46 | + site_id: expect.any(String), |
| 47 | + collector: expect.any(Object), |
| 48 | + date_created: expect.any(String), |
| 49 | + last_updated: expect.any(String), |
| 50 | + shipping_cost: expect.any(Number), |
| 51 | + total_amount: expect.any(Number), |
| 52 | + paid_amount: expect.any(Number), |
| 53 | + refunded_amount: expect.any(Number), |
| 54 | + cancelled: expect.any(Boolean), |
| 55 | + order_status: expect.any(String), |
| 56 | + is_test: expect.any(Boolean), |
| 57 | + })); |
| 58 | + }); |
| 59 | +}); |
0 commit comments