|
| 1 | +import MercadoPago, { Preference } from '@src/index'; |
| 2 | +import { config } from '../e2e.config'; |
| 3 | +import type { PreferenceCreateData } from '@src/clients/preference/create/types'; |
| 4 | +import type { PreferenceUpdateData } from '@src/clients/preference/update/types'; |
| 5 | + |
| 6 | +describe('Preference IT, update', () => { |
| 7 | + test('should update request and match response object', async () => { |
| 8 | + const client = new MercadoPago({ accessToken: config.access_token }); |
| 9 | + const preference = new Preference(client); |
| 10 | + |
| 11 | + const preferenceRequest: PreferenceCreateData = { |
| 12 | + body: { |
| 13 | + items: [ |
| 14 | + { |
| 15 | + id: '4567', |
| 16 | + title: 'Dummy Title Create', |
| 17 | + quantity: 1, |
| 18 | + unit_price: 10 |
| 19 | + } |
| 20 | + ], |
| 21 | + } |
| 22 | + }; |
| 23 | + const request = await preference.create(preferenceRequest); |
| 24 | + |
| 25 | + const updateRequest: PreferenceUpdateData = { |
| 26 | + id: request.id, |
| 27 | + updatePreferenceRequest: { |
| 28 | + items: [ |
| 29 | + { |
| 30 | + id: '4567', |
| 31 | + title: 'Dummy Title Update', |
| 32 | + quantity: 1, |
| 33 | + unit_price: 10 |
| 34 | + } |
| 35 | + ], |
| 36 | + } |
| 37 | + }; |
| 38 | + const response = await preference.update(updateRequest); |
| 39 | + |
| 40 | + expect(response).toEqual(expect.objectContaining({ |
| 41 | + id: request.id, |
| 42 | + })); |
| 43 | + expect(response.items[0].title).toBe(updateRequest.updatePreferenceRequest.items[0].title); |
| 44 | + expect(response).toEqual(expect.objectContaining({ |
| 45 | + init_point: expect.any(String), |
| 46 | + client_id: expect.any(String), |
| 47 | + collector_id: expect.any(Number), |
| 48 | + date_created: expect.any(String), |
| 49 | + id: expect.any(String), |
| 50 | + sandbox_init_point: expect.any(String), |
| 51 | + site_id: expect.any(String), |
| 52 | + })); |
| 53 | + expect(response.items[0]).toEqual(expect.objectContaining({ |
| 54 | + id: expect.any(String), |
| 55 | + category_id: expect.any(String), |
| 56 | + currency_id: expect.any(String), |
| 57 | + description: expect.any(String), |
| 58 | + title: expect.any(String), |
| 59 | + quantity: expect.any(Number), |
| 60 | + unit_price: expect.any(Number), |
| 61 | + })); |
| 62 | + }); |
| 63 | + |
| 64 | +}); |
0 commit comments