Skip to content

Commit 2e685d1

Browse files
committed
add integration test to customerCard
1 parent 43e2b35 commit 2e685d1

File tree

5 files changed

+492
-0
lines changed

5 files changed

+492
-0
lines changed

e2e/customerCard/create.spec.ts

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import MercadoPago, { Customer, CustomerCard } from '@src/index';
2+
import fetch from 'node-fetch';
3+
import { config } from '../e2e.config';
4+
5+
describe('Testing customer cards, create', () => {
6+
test('should create customer card and match response object', async () => {
7+
const client = new MercadoPago({ accessToken: config.test_access_token, options: { timeout: 5000 } });
8+
const customerCard = new CustomerCard(client);
9+
const customer = new Customer(client);
10+
11+
const email = createEmailTestUser();
12+
const emailBody = {
13+
'email': email,
14+
};
15+
const createCustomer = await customer.create({ body: emailBody });
16+
expect(createCustomer).toHaveProperty('id');
17+
18+
const createToken = await createCardToken();
19+
const customerBody = {
20+
'token': createToken.id
21+
};
22+
23+
const createCustomerCard = await customerCard.create({ customerId: createCustomer.id, body: customerBody });
24+
25+
expect(createCustomerCard).toEqual(expect.objectContaining({
26+
id: expect.any(String),
27+
customer_id: expect.any(String),
28+
expiration_month: expect.any(Number),
29+
expiration_year: expect.any(Number),
30+
first_six_digits:expect.any(String),
31+
last_four_digits: expect.any(String),
32+
payment_method: expect.objectContaining({
33+
id: expect.any(String),
34+
name: expect.any(String),
35+
payment_type_id: expect.any(String),
36+
thumbnail: expect.any(String),
37+
secure_thumbnail: expect.any(String)
38+
}),
39+
security_code: expect.objectContaining({
40+
length: expect.any(Number),
41+
card_location: expect.any(String)
42+
}),
43+
issuer: expect.objectContaining({
44+
id: expect.any(Number),
45+
name: expect.any(String)
46+
}),
47+
cardholder: expect.objectContaining({
48+
name: expect.any(String),
49+
identification: expect.any(Object)
50+
}),
51+
date_created: expect.any(String),
52+
date_last_updated: expect.any(String),
53+
user_id: expect.any(String),
54+
live_mode: expect.any(Boolean),
55+
}));
56+
57+
const removeCard = await customerCard.remove({ customerId: createCustomer.id, cardId: createCustomerCard.id });
58+
expect(removeCard.api_response.status).toBe(200);
59+
const removeCustomer = await customer.remove({ customerId: createCustomer.id });
60+
expect(removeCustomer.api_response.status).toBe(200);
61+
});
62+
63+
function createEmailTestUser() {
64+
const random = Math.floor(Math.random() * 1000000);
65+
const email = 'test_user' + random + '@testuser.com';
66+
return email;
67+
}
68+
69+
async function createCardToken() {
70+
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', {
71+
method: 'POST',
72+
headers: {
73+
'Authorization': 'Bearer ' + config.test_access_token,
74+
'Content-Type': 'application/json',
75+
},
76+
body: JSON.stringify({
77+
site_id: 'MLB',
78+
card_number: '5031433215406351',
79+
expiration_year: '2025',
80+
expiration_month: '11',
81+
security_code: '123',
82+
cardholder: {
83+
identification: {
84+
type: 'CPF',
85+
number: '01234567890'
86+
},
87+
name: 'APRO'
88+
}
89+
})
90+
});
91+
return await response.json();
92+
}
93+
});

e2e/customerCard/get.spec.ts

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import MercadoPago, { Customer, CustomerCard } from '@src/index';
2+
import fetch from 'node-fetch';
3+
import { config } from '../e2e.config';
4+
5+
describe('Testing customer card, get', () => {
6+
test('should get customer card and match response object', async () => {
7+
const client = new MercadoPago({ accessToken: config.test_access_token, options: { timeout: 5000 } });
8+
const customerCard = new CustomerCard(client);
9+
const customer = new Customer(client);
10+
11+
const email = createEmailTestUser();
12+
const emailBody = {
13+
'email': email,
14+
};
15+
const createCustomer = await customer.create({ body: emailBody });
16+
expect(createCustomer).toHaveProperty('id');
17+
18+
const createToken = await createCardToken();
19+
const customerBody = {
20+
'token': createToken.id
21+
};
22+
23+
const createCustomerCard = await customerCard.create({ customerId: createCustomer.id, body: customerBody });
24+
expect(createCustomerCard).toHaveProperty('id');
25+
26+
const getCustomerCard = await customerCard.get({ customerId: createCustomer.id, cardId: createCustomerCard.id });
27+
expect(getCustomerCard.id).toBe(createCustomerCard.id);
28+
expect(getCustomerCard).toEqual(expect.objectContaining({
29+
id: expect.any(String),
30+
customer_id: expect.any(String),
31+
expiration_month: expect.any(Number),
32+
expiration_year: expect.any(Number),
33+
first_six_digits:expect.any(String),
34+
last_four_digits: expect.any(String),
35+
payment_method: expect.objectContaining({
36+
id: expect.any(String),
37+
name: expect.any(String),
38+
payment_type_id: expect.any(String),
39+
thumbnail: expect.any(String),
40+
secure_thumbnail: expect.any(String)
41+
}),
42+
security_code: expect.objectContaining({
43+
length: expect.any(Number),
44+
card_location: expect.any(String)
45+
}),
46+
issuer: expect.objectContaining({
47+
id: expect.any(Number),
48+
name: expect.any(String)
49+
}),
50+
cardholder: expect.objectContaining({
51+
name: expect.any(String),
52+
identification: expect.any(Object)
53+
}),
54+
date_created: expect.any(String),
55+
date_last_updated: expect.any(String),
56+
user_id: expect.any(String),
57+
live_mode: expect.any(Boolean),
58+
}));
59+
60+
const removeCard = await customerCard.remove({ customerId: createCustomer.id, cardId: createCustomerCard.id });
61+
expect(removeCard.api_response.status).toBe(200);
62+
const removeCustomer = await customer.remove({ customerId: createCustomer.id });
63+
expect(removeCustomer.api_response.status).toBe(200);
64+
});
65+
66+
function createEmailTestUser() {
67+
const random = Math.floor(Math.random() * 1000000);
68+
const email = 'test_user' + random + '@testuser.com';
69+
return email;
70+
}
71+
72+
async function createCardToken() {
73+
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', {
74+
method: 'POST',
75+
headers: {
76+
'Authorization': 'Bearer ' + config.test_access_token,
77+
'Content-Type': 'application/json',
78+
},
79+
body: JSON.stringify({
80+
site_id: 'MLB',
81+
card_number: '5031433215406351',
82+
expiration_year: '2025',
83+
expiration_month: '11',
84+
security_code: '123',
85+
cardholder: {
86+
identification: {
87+
type: 'CPF',
88+
number: '01234567890'
89+
},
90+
name: 'APRO'
91+
}
92+
})
93+
});
94+
return await response.json();
95+
}
96+
});

e2e/customerCard/list.spec.ts

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import MercadoPago, { Customer, CustomerCard } from '@src/index';
2+
import fetch from 'node-fetch';
3+
import { config } from '../e2e.config';
4+
5+
describe('Testing customer card, get', () => {
6+
test('should get list of cards and match response object', async () => {
7+
const client = new MercadoPago({ accessToken: config.test_access_token, options: { timeout: 5000 } });
8+
const customerCard = new CustomerCard(client);
9+
const customer = new Customer(client);
10+
11+
const email = createEmailTestUser();
12+
const emailBody = {
13+
'email': email,
14+
};
15+
const createCustomer = await customer.create({ body: emailBody });
16+
expect(createCustomer).toHaveProperty('id');
17+
18+
const createToken = await createCardToken();
19+
const customerBody = {
20+
'token': createToken.id
21+
};
22+
23+
const createCustomerCard = await customerCard.create({ customerId: createCustomer.id, body: customerBody });
24+
expect(createCustomerCard).toHaveProperty('id');
25+
26+
const listCard = await customerCard.list({ customerId: createCustomer.id });
27+
expect(listCard).toBeInstanceOf(Array);
28+
expect(listCard[0].id).toBe(createCustomerCard.id);
29+
expect(listCard[0]).toEqual(expect.objectContaining({
30+
id: expect.any(String),
31+
customer_id: expect.any(String),
32+
expiration_month: expect.any(Number),
33+
expiration_year: expect.any(Number),
34+
first_six_digits:expect.any(String),
35+
last_four_digits: expect.any(String),
36+
payment_method: expect.objectContaining({
37+
id: expect.any(String),
38+
name: expect.any(String),
39+
payment_type_id: expect.any(String),
40+
thumbnail: expect.any(String),
41+
secure_thumbnail: expect.any(String)
42+
}),
43+
security_code: expect.objectContaining({
44+
length: expect.any(Number),
45+
card_location: expect.any(String)
46+
}),
47+
issuer: expect.objectContaining({
48+
id: expect.any(Number),
49+
name: expect.any(String)
50+
}),
51+
cardholder: expect.objectContaining({
52+
name: expect.any(String),
53+
identification: expect.any(Object)
54+
}),
55+
date_created: expect.any(String),
56+
date_last_updated: expect.any(String),
57+
user_id: expect.any(String),
58+
live_mode: expect.any(Boolean),
59+
}));
60+
61+
const removeCard = await customerCard.remove({ customerId: createCustomer.id, cardId: createCustomerCard.id });
62+
expect(removeCard.api_response.status).toBe(200);
63+
const removeCustomer = await customer.remove({ customerId: createCustomer.id });
64+
expect(removeCustomer.api_response.status).toBe(200);
65+
});
66+
67+
function createEmailTestUser() {
68+
const random = Math.floor(Math.random() * 1000000);
69+
const email = 'test_user' + random + '@testuser.com';
70+
return email;
71+
}
72+
73+
async function createCardToken() {
74+
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', {
75+
method: 'POST',
76+
headers: {
77+
'Authorization': 'Bearer ' + config.test_access_token,
78+
'Content-Type': 'application/json',
79+
},
80+
body: JSON.stringify({
81+
site_id: 'MLB',
82+
card_number: '5031433215406351',
83+
expiration_year: '2025',
84+
expiration_month: '11',
85+
security_code: '123',
86+
cardholder: {
87+
identification: {
88+
type: 'CPF',
89+
number: '01234567890'
90+
},
91+
name: 'APRO'
92+
}
93+
})
94+
});
95+
return await response.json();
96+
}
97+
});

e2e/customerCard/remove.spec.ts

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import MercadoPago, { Customer, CustomerCard } from '@src/index';
2+
import fetch from 'node-fetch';
3+
import { config } from '../e2e.config';
4+
5+
describe('Testing customer card, get', () => {
6+
test('should remove card and match response object', async () => {
7+
const client = new MercadoPago({ accessToken: config.test_access_token, options: { timeout: 5000 } });
8+
const customerCard = new CustomerCard(client);
9+
const customer = new Customer(client);
10+
11+
const email = createEmailTestUser();
12+
const emailBody = {
13+
'email': email,
14+
};
15+
const createCustomer = await customer.create({ body: emailBody });
16+
expect(createCustomer).toHaveProperty('id');
17+
18+
const createToken = await createCardToken();
19+
const customerBody = {
20+
'token': createToken.id
21+
};
22+
23+
const createCustomerCard = await customerCard.create({ customerId: createCustomer.id, body: customerBody });
24+
expect(createCustomerCard).toHaveProperty('id');
25+
26+
const removeCard = await customerCard.remove({ customerId: createCustomer.id, cardId: createCustomerCard.id });
27+
expect(removeCard.api_response.status).toBe(200);
28+
expect(removeCard.id).toBe(createCustomerCard.id);
29+
expect(removeCard).toEqual(expect.objectContaining({
30+
id: expect.any(String),
31+
customer_id: expect.any(String),
32+
expiration_month: expect.any(Number),
33+
expiration_year: expect.any(Number),
34+
first_six_digits:expect.any(String),
35+
last_four_digits: expect.any(String),
36+
payment_method: expect.objectContaining({
37+
id: expect.any(String),
38+
name: expect.any(String),
39+
payment_type_id: expect.any(String),
40+
thumbnail: expect.any(String),
41+
secure_thumbnail: expect.any(String)
42+
}),
43+
security_code: expect.objectContaining({
44+
length: expect.any(Number),
45+
card_location: expect.any(String)
46+
}),
47+
issuer: expect.objectContaining({
48+
id: expect.any(Number),
49+
name: expect.any(String)
50+
}),
51+
cardholder: expect.objectContaining({
52+
name: expect.any(String),
53+
identification: expect.any(Object)
54+
}),
55+
date_created: expect.any(String),
56+
date_last_updated: expect.any(String),
57+
user_id: expect.any(String),
58+
live_mode: expect.any(Boolean),
59+
}));
60+
61+
const removeCustomer = await customer.remove({ customerId: createCustomer.id });
62+
expect(removeCustomer.api_response.status).toBe(200);
63+
});
64+
65+
function createEmailTestUser() {
66+
const random = Math.floor(Math.random() * 1000000);
67+
const email = 'test_user' + random + '@testuser.com';
68+
return email;
69+
}
70+
71+
async function createCardToken() {
72+
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', {
73+
method: 'POST',
74+
headers: {
75+
'Authorization': 'Bearer ' + config.test_access_token,
76+
'Content-Type': 'application/json',
77+
},
78+
body: JSON.stringify({
79+
site_id: 'MLB',
80+
card_number: '5031433215406351',
81+
expiration_year: '2025',
82+
expiration_month: '11',
83+
security_code: '123',
84+
cardholder: {
85+
identification: {
86+
type: 'CPF',
87+
number: '01234567890'
88+
},
89+
name: 'APRO'
90+
}
91+
})
92+
});
93+
return await response.json();
94+
}
95+
});

0 commit comments

Comments
 (0)