Skip to content

Commit 0c1fc58

Browse files
authored
Merge pull request mercadopago#269 from lucmkz/feature/preference-integration-test
IT Preference
2 parents 544b3e6 + cbf6a36 commit 0c1fc58

File tree

11 files changed

+212
-9
lines changed

11 files changed

+212
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# ============= Config e2e =============
2+
/e2e/e2e.config.ts
3+
14
# ============= Lint =============
25
# Cache eslint
36
.eslintcache

e2e/demo/demo.spec.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

e2e/example.e2e.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* This is an example configuration file for e2e tests, where you must add your credentials and other personal settings.
3+
* Inside the e2e directory, create a file with the name: e2e.config.ts.
4+
* Copy the contents of the example file, add it to the e2e.config.ts file and add your personal settings.
5+
*/
6+
7+
const config = {
8+
access_token: '',
9+
};
10+
11+
export {
12+
config,
13+
};

e2e/jest.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import jestConfig from '../jest.config';
22

3+
jestConfig.rootDir = '../';
34
jestConfig.testPathIgnorePatterns = [
4-
'/node_modules/',
5-
'/src/'
5+
'src'
66
];
77

88
export default jestConfig;

e2e/preference/create.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import MercadoPago, { Preference } from '@src/index';
2+
import { config } from '../e2e.config';
3+
import type { PreferenceCreateData } from '@src/clients/preference/create/types';
4+
5+
describe('Preference IT, create', () => {
6+
test('should create Preference and match response object', async () => {
7+
8+
const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } });
9+
const preference = new Preference(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+
picture_url: 'https://http2.mlstatic.com/D_NQ_NP_887467-MLA71526269815_092023-F.jpg',
20+
title: 'Dummy Title',
21+
quantity: 1,
22+
unit_price: 10
23+
}
24+
],
25+
}
26+
};
27+
28+
const response = await preference.create(preferenceRequest);
29+
expect(response.items[0].title).toBe(preferenceRequest.body.items[0].title);
30+
expect(response).toEqual(expect.objectContaining({
31+
init_point: expect.any(String),
32+
client_id: expect.any(String),
33+
collector_id: expect.any(Number),
34+
date_created: expect.any(String),
35+
id: expect.any(String),
36+
sandbox_init_point: expect.any(String),
37+
site_id: expect.any(String),
38+
}));
39+
expect(response.items[0]).toEqual(expect.objectContaining({
40+
id: expect.any(String),
41+
category_id: expect.any(String),
42+
currency_id: expect.any(String),
43+
description: expect.any(String),
44+
picture_url: expect.any(String),
45+
title: expect.any(String),
46+
quantity: expect.any(Number),
47+
unit_price: expect.any(Number),
48+
}));
49+
});
50+
});

e2e/preference/get.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import MercadoPago, { Preference } from '@src/index';
2+
import { config } from '../e2e.config';
3+
import type { PreferenceCreateData } from '@src/clients/preference/create/types';
4+
5+
describe('Preference IT, get', () => {
6+
test('should get preference and match response object', async () => {
7+
const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } });
8+
const preference = new Preference(client);
9+
10+
const preferenceRequest: PreferenceCreateData = {
11+
body: {
12+
items: [
13+
{
14+
id: '4567',
15+
title: 'Dummy Title Create',
16+
quantity: 1,
17+
unit_price: 10
18+
}
19+
], }
20+
};
21+
const request = await preference.create(preferenceRequest);
22+
23+
const response = await preference.get({ preferenceId: request.id });
24+
expect(response).toHaveProperty('id', request.id);
25+
expect(response).toEqual(expect.objectContaining({
26+
init_point: expect.any(String),
27+
client_id: expect.any(String),
28+
collector_id: expect.any(Number),
29+
date_created: expect.any(String),
30+
id: expect.any(String),
31+
sandbox_init_point: expect.any(String),
32+
site_id: expect.any(String),
33+
}));
34+
expect(response.items[0]).toEqual(expect.objectContaining({
35+
id: expect.any(String),
36+
category_id: expect.any(String),
37+
currency_id: expect.any(String),
38+
description: expect.any(String),
39+
title: expect.any(String),
40+
quantity: expect.any(Number),
41+
unit_price: expect.any(Number),
42+
}));
43+
});
44+
45+
});

e2e/preference/search.spec.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import MercadoPago, { Preference } from '@src/index';
2+
import { config } from '../e2e.config';
3+
4+
describe('Preference IT, search', () => {
5+
test('should search a request and match response object', async () => {
6+
const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } });
7+
const preference = new Preference(client);
8+
9+
const searched = await preference.search();
10+
11+
expect(searched).toEqual(expect.objectContaining({
12+
elements: expect.any(Array),
13+
next_offset: expect.any(Number),
14+
total: expect.any(Number),
15+
}));
16+
expect(searched.elements.length).toBeGreaterThan(0);
17+
expect(searched.elements[0]).toEqual(expect.objectContaining({
18+
id: expect.any(String),
19+
client_id: expect.any(String),
20+
collector_id: expect.any(Number),
21+
date_created: expect.any(String),
22+
expires: expect.any(Boolean),
23+
live_mode: expect.any(Boolean),
24+
marketplace: expect.any(String),
25+
operation_type: expect.any(String),
26+
site_id: expect.any(String),
27+
sponsor_id: expect.any(Number),
28+
shipping_mode: expect.any(String),
29+
}));
30+
});
31+
});

e2e/preference/update.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
});

jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const jestConfig: JestConfigWithTsJest = {
1212
'text-summary'
1313
],
1414
testMatch: [
15-
'**/?(*.)+(spec|test).[tj]s?(x)'
15+
'**/?(*.)spec.ts'
1616
],
1717
transform: { '^.+\\.(ts|tsx)$': 'ts-jest' },
1818
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>' }),

src/clients/payment/search/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export declare type PaymentSearchResult = {
4545
merchant_account_id: string;
4646
acquirer: string;
4747
merchant_number: string;
48+
external_reference: string;
4849
};
4950

5051
export declare type Payer = {

0 commit comments

Comments
 (0)