-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/paymentMethod-integration-test
- Loading branch information
Showing
11 changed files
with
448 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import MercadoPago, { Payment, PaymentRefund } from '@src/index'; | ||
import fetch from 'node-fetch'; | ||
import { config } from '../e2e.config'; | ||
import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; | ||
|
||
describe('IT refunds, create', () => { | ||
test('should make a request with partial amount and match response object', async () => { | ||
const client = new MercadoPago({ accessToken: config.access_token }); | ||
const refund = new PaymentRefund(client); | ||
const payment = new Payment(client); | ||
try { | ||
const cardToken = await createCardToken(); | ||
expect(cardToken).toHaveProperty('id'); | ||
|
||
const paymentBody = { | ||
body: { | ||
additional_info: { | ||
items: [ | ||
{ | ||
id: 'MLB2907679857', | ||
title: 'Point Mini', | ||
quantity: 1, | ||
unit_price: 58.8 | ||
} | ||
] | ||
}, | ||
payer: { | ||
email: '[email protected]', | ||
}, | ||
transaction_amount: 110.00, | ||
installments: 1, | ||
token: cardToken.id, | ||
payment_method_id: 'master', | ||
} | ||
}; | ||
const createdPayment = await payment.create(paymentBody); | ||
expect(createdPayment).toHaveProperty('id'); | ||
|
||
const request: PaymentRefundCreateData = { | ||
payment_id: createdPayment.id, | ||
body: { | ||
amount: 5 | ||
}, | ||
}; | ||
|
||
const refunded = await refund.create(request); | ||
expect(refunded).toHaveProperty('id'); | ||
expect(refunded).toHaveProperty('payment_id', request.payment_id); | ||
expect(refunded).toHaveProperty('amount', request.body.amount); | ||
expect(refunded).toEqual(expect.objectContaining({ | ||
payment_id: expect.any(Number), | ||
date_created: expect.any(String), | ||
id: expect.any(Number), | ||
amount: expect.any(Number), | ||
source: expect.objectContaining({ | ||
id: expect.any(String), | ||
name: expect.any(String), | ||
type: expect.any(String), | ||
}), | ||
refund_mode: expect.any(String), | ||
adjustment_amount: expect.any(Number), | ||
status: expect.any(String), | ||
amount_refunded_to_payer: expect.any(Number), | ||
})); | ||
} catch(e) { | ||
console.log(e, 'error'); | ||
} | ||
}, 10000); | ||
|
||
async function createCardToken() { | ||
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { | ||
method: 'POST', | ||
headers: { | ||
'Authorization': 'Bearer ' + config.access_token, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
card_number: '5031433215406351', | ||
expiration_year: '2025', | ||
expiration_month: '11', | ||
security_code: '123', | ||
cardholder: { | ||
identification: { | ||
type: 'CPF', | ||
number: '01234567890' | ||
}, | ||
name: 'APRO' | ||
} | ||
}) | ||
}); | ||
return await response.json(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import MercadoPago, { Payment, PaymentRefund } from '@src/index'; | ||
import fetch from 'node-fetch'; | ||
import { config } from '../e2e.config'; | ||
import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; | ||
import type { PaymentRefundGetData } from '@src/clients/paymentRefund/get/types'; | ||
|
||
describe('IT refunds, get', () => { | ||
test('should make a request and match response object', async () => { | ||
const client = new MercadoPago({ accessToken: config.access_token }); | ||
const refund = new PaymentRefund(client); | ||
const payment = new Payment(client); | ||
try { | ||
const cardToken = await createCardToken(); | ||
expect(cardToken).toHaveProperty('id'); | ||
|
||
const paymentBody = { | ||
body: { | ||
additional_info: { | ||
items: [ | ||
{ | ||
id: 'MLB2907679857', | ||
title: 'Point Mini', | ||
quantity: 1, | ||
unit_price: 70 | ||
} | ||
] | ||
}, | ||
payer: { | ||
email: '[email protected]', | ||
}, | ||
transaction_amount: 140.00, | ||
installments: 1, | ||
token: cardToken.id, | ||
payment_method_id: 'master', | ||
} | ||
}; | ||
const createdPayment = await payment.create(paymentBody); | ||
expect(createdPayment).toHaveProperty('id'); | ||
|
||
const requestRefund: PaymentRefundCreateData = { | ||
payment_id: createdPayment.id, | ||
body: { | ||
amount: 5 | ||
}, | ||
}; | ||
const refunded = await refund.create(requestRefund); | ||
expect(refunded).toHaveProperty('id'); | ||
|
||
const requestRefundGet: PaymentRefundGetData = { | ||
payment_id: refunded.payment_id, | ||
refund_id: refunded.id, | ||
}; | ||
|
||
const getRefund = await refund.get(requestRefundGet); | ||
expect(getRefund).toHaveProperty('id'); | ||
expect(getRefund).toHaveProperty('payment_id', requestRefundGet.payment_id); | ||
expect(getRefund).toHaveProperty('id', requestRefundGet.refund_id); | ||
expect(getRefund).toEqual(expect.objectContaining({ | ||
payment_id: expect.any(Number), | ||
date_created: expect.any(String), | ||
id: expect.any(Number), | ||
amount: expect.any(Number), | ||
source: expect.objectContaining({ | ||
id: expect.any(String), | ||
name: expect.any(String), | ||
type: expect.any(String), | ||
}), | ||
refund_mode: expect.any(String), | ||
adjustment_amount: expect.any(Number), | ||
status: expect.any(String), | ||
amount_refunded_to_payer: expect.any(Number), | ||
})); | ||
} catch (e) { | ||
console.log(e); | ||
} | ||
}, 10000); | ||
|
||
async function createCardToken() { | ||
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { | ||
method: 'POST', | ||
headers: { | ||
'Authorization': 'Bearer ' + config.access_token, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
card_number: '5031433215406351', | ||
expiration_year: '2025', | ||
expiration_month: '11', | ||
security_code: '123', | ||
cardholder: { | ||
identification: { | ||
type: 'CPF', | ||
number: '01234567890' | ||
}, | ||
name: 'APRO' | ||
} | ||
}) | ||
}); | ||
return await response.json(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import MercadoPago, { Payment, PaymentRefund } from '@src/index'; | ||
import fetch from 'node-fetch'; | ||
import { config } from '../e2e.config'; | ||
import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; | ||
import type { PaymentRefundListData } from '@src/clients/paymentRefund/list/types'; | ||
|
||
describe('IT refunds, list', () => { | ||
test('should make a request, return a list and match response object', async () => { | ||
const client = new MercadoPago({ accessToken: config.access_token }); | ||
const refund = new PaymentRefund(client); | ||
const payment = new Payment(client); | ||
try { | ||
const cardToken = await createCardToken(); | ||
expect(cardToken).toHaveProperty('id'); | ||
|
||
const paymentBody = { | ||
body: { | ||
additional_info: { | ||
items: [ | ||
{ | ||
id: 'MLB2907679857', | ||
title: 'Point Mini', | ||
quantity: 1, | ||
unit_price: 58.8 | ||
} | ||
] | ||
}, | ||
payer: { | ||
email: '[email protected]', | ||
}, | ||
transaction_amount: 110.00, | ||
installments: 1, | ||
token: cardToken.id, | ||
payment_method_id: 'master', | ||
} | ||
}; | ||
|
||
const createdPayment = await payment.create(paymentBody); | ||
expect(createdPayment).toHaveProperty('id'); | ||
|
||
const requestRefund: PaymentRefundCreateData = { | ||
payment_id: createdPayment.id, | ||
body: { | ||
amount: 5 | ||
}, | ||
}; | ||
const refunded = await refund.create(requestRefund); | ||
expect(refunded).toHaveProperty('id'); | ||
|
||
const requestList: PaymentRefundListData = { | ||
payment_id: refunded.payment_id, | ||
}; | ||
|
||
const refundList = await refund.list(requestList); | ||
expect(refundList[0]).toHaveProperty('payment_id', requestList.payment_id); | ||
expect(Array.isArray(refundList)).toBe(true); | ||
expect(refundList[0]).toEqual(expect.objectContaining({ | ||
id: expect.any(Number), | ||
payment_id: expect.any(Number), | ||
date_created: expect.any(String), | ||
amount: expect.any(Number), | ||
source: expect.objectContaining({ | ||
id: expect.any(String), | ||
name: expect.any(String), | ||
type: expect.any(String), | ||
}), | ||
refund_mode: expect.any(String), | ||
adjustment_amount: expect.any(Number), | ||
status: expect.any(String), | ||
amount_refunded_to_payer: expect.any(Number), | ||
}) | ||
); | ||
} catch(e) { | ||
console.log(e); | ||
} | ||
}, 10000); | ||
|
||
async function createCardToken() { | ||
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { | ||
method: 'POST', | ||
headers: { | ||
'Authorization': 'Bearer ' + config.access_token, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
card_number: '5031433215406351', | ||
expiration_year: '2025', | ||
expiration_month: '11', | ||
security_code: '123', | ||
cardholder: { | ||
identification: { | ||
type: 'CPF', | ||
number: '01234567890' | ||
}, | ||
name: 'APRO' | ||
} | ||
}) | ||
}); | ||
return await response.json(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import MercadoPago, { Payment, PaymentRefund } from '@src/index'; | ||
import fetch from 'node-fetch'; | ||
import { config } from '../e2e.config'; | ||
import type { PaymentCreateData } from '@src/clients/payment/create/types'; | ||
import type { PaymentRefundTotalData } from '@src/clients/paymentRefund/total/types'; | ||
|
||
describe('IT refunds, total', () => { | ||
test('should make a request, refund total amount and match response object', async () => { | ||
const client = new MercadoPago({ accessToken: config.access_token }); | ||
const refund = new PaymentRefund(client); | ||
const payment = new Payment(client); | ||
try { | ||
const cardToken = await createCardToken(); | ||
expect(cardToken).toHaveProperty('id'); | ||
const paymentBody = createPayment(cardToken.id); | ||
|
||
const createdPayment = await payment.create(paymentBody); | ||
expect(createdPayment).toHaveProperty('id'); | ||
|
||
const request: PaymentRefundTotalData = { | ||
payment_id: createdPayment.id, | ||
}; | ||
|
||
const refunded = await refund.total(request); | ||
expect(refunded).toHaveProperty('id'); | ||
expect(refunded).toHaveProperty('payment_id', request.payment_id); | ||
expect(refunded).toHaveProperty('amount', 110.00); | ||
expect(refunded).toEqual(expect.objectContaining({ | ||
payment_id: expect.any(Number), | ||
date_created: expect.any(String), | ||
id: expect.any(Number), | ||
amount: expect.any(Number), | ||
source: expect.objectContaining({ | ||
id: expect.any(String), | ||
name: expect.any(String), | ||
type: expect.any(String), | ||
}), | ||
refund_mode: expect.any(String), | ||
adjustment_amount: expect.any(Number), | ||
status: expect.any(String), | ||
amount_refunded_to_payer: expect.any(Number), | ||
})); | ||
} catch(e) { | ||
console.error(e); | ||
} | ||
}, 10000); | ||
|
||
|
||
function createPayment(token: string): PaymentCreateData { | ||
const body = { | ||
body: { | ||
additional_info: { | ||
items: [ | ||
{ | ||
id: 'MLB2907679857', | ||
title: 'Point Mini', | ||
quantity: 1, | ||
unit_price: 58.8 | ||
} | ||
] | ||
}, | ||
payer: { | ||
email: '[email protected]', | ||
}, | ||
transaction_amount: 110.00, | ||
installments: 1, | ||
token: token, | ||
payment_method_id: 'master', | ||
} | ||
}; | ||
return body; | ||
} | ||
|
||
async function createCardToken() { | ||
const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { | ||
method: 'POST', | ||
headers: { | ||
'Authorization': 'Bearer ' + config.access_token, | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
card_number: '5031433215406351', | ||
expiration_year: '2025', | ||
expiration_month: '11', | ||
security_code: '123', | ||
cardholder: { | ||
identification: { | ||
type: 'CPF', | ||
number: '01234567890' | ||
}, | ||
name: 'APRO' | ||
} | ||
}) | ||
}); | ||
return await response.json(); | ||
} | ||
}); |
Oops, something went wrong.