Skip to content

Commit

Permalink
turn emails into dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
brunacamposxx committed Nov 28, 2023
1 parent 39aaf3f commit cb4bb88
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 5 deletions.
1 change: 1 addition & 0 deletions e2e/cardToken/create.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import MercadoPago, { CardToken, Customer, CustomerCard } from '@src/index';
import fetch from 'node-fetch';
import { config } from '../e2e.config';
describe('IT, create card token', () => {
test('should make a request and return created card token id', async () => {
Expand Down
10 changes: 9 additions & 1 deletion e2e/payment/cancel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ describe('IT, cancel', () => {
const client = new MercadoPago({ accessToken: config.access_token });
const payment = new Payment(client);

const email = createEmailTestUser();

const paymentBody = {
body: {
additional_info: {
Expand All @@ -19,7 +21,7 @@ describe('IT, cancel', () => {
]
},
payer: {
email: '[email protected]',
email: email,
},
transaction_amount: 110.00,
installments: 1,
Expand All @@ -33,4 +35,10 @@ describe('IT, cancel', () => {
expect(cancelation).toHaveProperty('id', paymentCreate.id);
expect(cancelation).toHaveProperty('status', 'cancelled');
});

function createEmailTestUser() {
const random = Math.floor(Math.random() * 1000000);
const email = 'test_user' + random + '@testuser.com';
return email;
}
});
12 changes: 10 additions & 2 deletions e2e/payment/capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('IT, capture', () => {
const cardToken = await createCardToken();
expect(cardToken).toHaveProperty('id');

const email = createEmailTestUser();
const paymentBody = {
body: {
additional_info: {
Expand All @@ -23,7 +24,7 @@ describe('IT, capture', () => {
]
},
payer: {
email: '[email protected]',
email: email,
},
transaction_amount: 110.00,
installments: 1,
Expand Down Expand Up @@ -82,6 +83,7 @@ describe('IT, capture', () => {
const cardToken = await createCardToken();
expect(cardToken).toHaveProperty('id');

const email = createEmailTestUser();
const paymentBody = {
body: {
additional_info: {
Expand All @@ -95,7 +97,7 @@ describe('IT, capture', () => {
]
},
payer: {
email: '[email protected]',
email: email,
},
transaction_amount: 110.00,
installments: 1,
Expand Down Expand Up @@ -170,4 +172,10 @@ describe('IT, capture', () => {
});
return await response.json();
}

function createEmailTestUser() {
const random = Math.floor(Math.random() * 1000000);
const email = 'test_user' + random + '@testuser.com';
return email;
}
});
78 changes: 77 additions & 1 deletion e2e/payment/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ describe('IT, create', () => {
const client = new MercadoPago({ accessToken: config.access_token });
const payment = new Payment(client);

const email = createEmailTestUser();

const body: PaymentCreateData = {
body: {
additional_info: {
Expand All @@ -20,7 +22,7 @@ describe('IT, create', () => {
]
},
payer: {
email: '[email protected]',
email: email,
},
transaction_amount: 110.00,
installments: 1,
Expand Down Expand Up @@ -60,5 +62,79 @@ describe('IT, create', () => {
}),
}));
});

test('should create Payment when payer`s "address" field is filled', async () => {
const client = new MercadoPago({ accessToken: config.access_token });
const payment = new Payment(client);

const email = createEmailTestUser();

const body: PaymentCreateData = {
body: {
additional_info: {
items: [
{
id: 'MLB2907679857',
title: 'Point Mini',
quantity: 1,
unit_price: 58.8
}
]
},
payer: {
email: email,
address: {
zip_code: '06233200',
street_name: 'street_name',
street_number: 123,
neighborhood: 'neighborhood',
city: 'city',
federal_unit: 'federal_unit',
},
},
transaction_amount: 110.00,
installments: 1,
payment_method_id: 'pix'
}
};

const response = await payment.create(body);

expect(response).toHaveProperty('id');
expect(response.additional_info.items[0]).toEqual(expect.objectContaining({
id: 'MLB2907679857',
title: 'Point Mini',
quantity: '1',
unit_price: '58.8'
}));
expect(response.transaction_amount).toBe(110.00);

expect(response).toEqual(expect.objectContaining({
collector_id: expect.any(Number),
date_created: expect.any(String),
id: expect.any(Number),
payment_method_id: expect.any(String),
payment_type_id: expect.any(String),
status: expect.any(String),
status_detail: expect.any(String),
transaction_amount: expect.any(Number),
point_of_interaction: expect.objectContaining({
transaction_data: expect.objectContaining({
qr_code: expect.any(String),
qr_code_base64: expect.any(String),
ticket_url: expect.any(String),
})
}),
payer: expect.objectContaining({
id: expect.any(String),
}),
}));
});

function createEmailTestUser() {
const random = Math.floor(Math.random() * 1000000);
const email = 'test_user' + random + '@testuser.com';
return email;
}
});

10 changes: 9 additions & 1 deletion e2e/payment/get.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ describe('IT, get', () => {
const client = new MercadoPago({ accessToken: config.access_token });
const payment = new Payment(client);

const email = createEmailTestUser();

const body: PaymentCreateData = {
body: {
additional_info: {
Expand All @@ -20,7 +22,7 @@ describe('IT, get', () => {
]
},
payer: {
email: '[email protected]',
email: email,
},
transaction_amount: 110.00,
installments: 1,
Expand Down Expand Up @@ -61,4 +63,10 @@ describe('IT, get', () => {
}),
}));
});

function createEmailTestUser() {
const random = Math.floor(Math.random() * 1000000);
const email = 'test_user' + random + '@testuser.com';
return email;
}
});

0 comments on commit cb4bb88

Please sign in to comment.