From 48edc3722cdf406bd481a260830b197109683071 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Tue, 10 Oct 2023 18:46:27 -0300 Subject: [PATCH] fix tests --- e2e/example.e2e.config.ts | 2 +- e2e/preference/create.spec.ts | 48 +++++++++++++++-------------------- e2e/preference/get.spec.ts | 29 ++++++++++----------- e2e/preference/update.spec.ts | 38 +++++++++++++-------------- 4 files changed, 52 insertions(+), 65 deletions(-) diff --git a/e2e/example.e2e.config.ts b/e2e/example.e2e.config.ts index 2f8133fa..df8a0864 100644 --- a/e2e/example.e2e.config.ts +++ b/e2e/example.e2e.config.ts @@ -1,6 +1,6 @@ /** * This is an example configuration file for e2e tests, where you must add your credentials and other personal settings. - * Inside the e2e directory, create a file with the name: e2e.config.ts. It is already added to gitignore. + * Inside the e2e directory, create a file with the name: e2e.config.ts. * Copy the contents of the example file, add it to the e2e.config.ts file and add your personal settings. */ diff --git a/e2e/preference/create.spec.ts b/e2e/preference/create.spec.ts index 55b628d4..46b47544 100644 --- a/e2e/preference/create.spec.ts +++ b/e2e/preference/create.spec.ts @@ -3,7 +3,7 @@ import MercadoPago, { Preference } from '@src/index'; import { config } from '../e2e.config'; describe('Preference IT, create', () => { - test('should create a request with success', async () => { + test('should create Preference and match response object', async () => { const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); const preference = new Preference(client); @@ -12,38 +12,21 @@ describe('Preference IT, create', () => { body: { items: [ { - 'id': '4567', - 'category_id': 'car_electronics', - 'currency_id': 'BRL', - 'description': 'Dummy create', - 'picture_url': 'https://http2.mlstatic.com/D_NQ_NP_887467-MLA71526269815_092023-F.jpg', - 'title': 'Dummy Title', - 'quantity': 1, - 'unit_price': 10 + id: '4567', + category_id: 'car_electronics', + currency_id: 'BRL', + description: 'Dummy create', + picture_url: 'https://http2.mlstatic.com/D_NQ_NP_887467-MLA71526269815_092023-F.jpg', + title: 'Dummy Title', + quantity: 1, + unit_price: 10 } ], } }; const response = await preference.create(preferenceRequest); - - expect(response).toEqual(expect.objectContaining({ - id: expect.any(String), - })); - expect(response).toHaveProperty('items', - [ - { - 'id': '4567', - 'category_id': 'car_electronics', - 'currency_id': 'BRL', - 'description': 'Dummy create', - 'picture_url': 'https://http2.mlstatic.com/D_NQ_NP_847188-MLB72078771649_102023-F.jpg', - 'title': 'Dummy Title', - 'quantity': 1, - 'unit_price': 10 - } - ], - ); + expect(response.items[0].title).toBe(preferenceRequest.body.items[0].title); expect(response).toEqual(expect.objectContaining({ init_point: expect.any(String), client_id: expect.any(String), @@ -53,6 +36,15 @@ describe('Preference IT, create', () => { sandbox_init_point: expect.any(String), site_id: expect.any(String), })); + expect(response.items[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + category_id: expect.any(String), + currency_id: expect.any(String), + description: expect.any(String), + picture_url: expect.any(String), + title: expect.any(String), + quantity: expect.any(Number), + unit_price: expect.any(Number), + })); }); - }); diff --git a/e2e/preference/get.spec.ts b/e2e/preference/get.spec.ts index abc9ebb9..390c9801 100644 --- a/e2e/preference/get.spec.ts +++ b/e2e/preference/get.spec.ts @@ -11,10 +11,10 @@ describe('Preference IT, get', () => { body: { items: [ { - 'id': '4567', - 'title': 'Dummy Title Create', - 'quantity': 1, - 'unit_price': 10 + id: '4567', + title: 'Dummy Title Create', + quantity: 1, + unit_price: 10 } ], } }; @@ -22,18 +22,6 @@ describe('Preference IT, get', () => { const response = await preference.get({ preferenceId: request.id }); expect(response).toHaveProperty('id', request.id); - expect(response).toHaveProperty('items', - [ - { - 'id': '4567', - 'category_id': '', - 'currency_id': 'BRL', - 'description': '', - 'title': 'Dummy Title Create', - 'quantity': 1, - 'unit_price': 10 - } - ]); expect(response).toEqual(expect.objectContaining({ init_point: expect.any(String), client_id: expect.any(String), @@ -43,6 +31,15 @@ describe('Preference IT, get', () => { sandbox_init_point: expect.any(String), site_id: expect.any(String), })); + expect(response.items[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + category_id: expect.any(String), + currency_id: expect.any(String), + description: expect.any(String), + title: expect.any(String), + quantity: expect.any(Number), + unit_price: expect.any(Number), + })); }); }); diff --git a/e2e/preference/update.spec.ts b/e2e/preference/update.spec.ts index 95e8c650..4817d053 100644 --- a/e2e/preference/update.spec.ts +++ b/e2e/preference/update.spec.ts @@ -12,10 +12,10 @@ describe('Preference IT, update', () => { body: { items: [ { - 'id': '4567', - 'title': 'Dummy Title Create', - 'quantity': 1, - 'unit_price': 10 + id: '4567', + title: 'Dummy Title Create', + quantity: 1, + unit_price: 10 } ], } @@ -27,10 +27,10 @@ describe('Preference IT, update', () => { updatePreferenceRequest: { items: [ { - 'id': '4567', - 'title': 'Dummy Title Update', - 'quantity': 1, - 'unit_price': 10 + id: '4567', + title: 'Dummy Title Update', + quantity: 1, + unit_price: 10 } ], } @@ -40,18 +40,7 @@ describe('Preference IT, update', () => { expect(response).toEqual(expect.objectContaining({ id: request.id, })); - expect(response).toHaveProperty('items', - [ - { - 'id': '4567', - 'category_id': '', - 'currency_id': 'BRL', - 'description': '', - 'title': 'Dummy Title Update', - 'quantity': 1, - 'unit_price': 10 - } - ]); + expect(response.items[0].title).toBe(updateRequest.updatePreferenceRequest.items[0].title); expect(response).toEqual(expect.objectContaining({ init_point: expect.any(String), client_id: expect.any(String), @@ -61,6 +50,15 @@ describe('Preference IT, update', () => { sandbox_init_point: expect.any(String), site_id: expect.any(String), })); + expect(response.items[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + category_id: expect.any(String), + currency_id: expect.any(String), + description: expect.any(String), + title: expect.any(String), + quantity: expect.any(Number), + unit_price: expect.any(Number), + })); }); });