Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brunacamposxx committed Oct 10, 2023
1 parent 3248865 commit 48edc37
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 65 deletions.
2 changes: 1 addition & 1 deletion e2e/example.e2e.config.ts
Original file line number Diff line number Diff line change
@@ -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.
*/

Expand Down
48 changes: 20 additions & 28 deletions e2e/preference/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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),
Expand All @@ -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),
}));
});

});
29 changes: 13 additions & 16 deletions e2e/preference/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,17 @@ 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
}
], }
};
const request = await preference.create(preferenceRequest);

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),
Expand All @@ -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),
}));
});

});
38 changes: 18 additions & 20 deletions e2e/preference/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
],
}
Expand All @@ -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
}
],
}
Expand All @@ -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),
Expand All @@ -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),
}));
});

});

0 comments on commit 48edc37

Please sign in to comment.