From 39aaf3f501fc6475266ea5a74cd316d8de0e6e9a Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Tue, 28 Nov 2023 13:58:37 -0300 Subject: [PATCH 1/8] Add address to payer object and add point of interaction to the root of payment requests --- src/clients/payment/create/types.ts | 54 +++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/src/clients/payment/create/types.ts b/src/clients/payment/create/types.ts index 794b425d..e95fc771 100644 --- a/src/clients/payment/create/types.ts +++ b/src/clients/payment/create/types.ts @@ -1,6 +1,6 @@ -import type { Items, Shipments } from '@src/clients/commonTypes'; +import type { Address, Items, Shipments } from '@src/clients/commonTypes'; import type { MercadoPagoConfig } from '@src/mercadoPagoConfig'; -import type { Payer } from '../commonTypes'; +import type { Identification, Payer, Phone } from '../commonTypes'; import type { Options } from '@src/types'; export declare type PaymentCreateClient = { @@ -34,7 +34,55 @@ export declare type PaymentCreateRequest = { statement_descriptor?: string, token?: string, transaction_amount?: number, - payer?: Payer, + payer?: PayerRequest, + point_of_interaction?: PointOfInteractionRequest, +}; + +export declare type PayerRequest = { + type?: string, + id?: string, + email?: string, + identification?: Identification, + phone?: Phone, + first_name?: string, + last_name?: string, + entity_type?: string, + address?: AddressRequest, +} + +export declare interface AddressRequest extends Address { + neighborhood?: string, + city?: string, + federal_unit?: string, +} + +export declare type PointOfInteractionRequest = { + linkedTo?: string, + type?: string, + transaction_data?: TransactionDataRequest, +}; + +export declare type TransactionDataRequest = { + first_time_use?: boolean, + subscription_sequence?: SubscriptionSequenceRequest, + subscription_id?: string, + invoice_period?: InvoicePeriodRequest, + payment_reference?: PaymentReferenceRequest, + billing_date?: string, +}; + +export declare type SubscriptionSequenceRequest = { + number?: number, + total?: number, +}; + +export declare type InvoicePeriodRequest = { + period?: number; + type?: string; +}; + +export declare type PaymentReferenceRequest = { + id?: string; }; export declare type AdditionalInfo = { From cb4bb88af041bad553c8ab7fac41457d35c363a1 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Tue, 28 Nov 2023 15:02:58 -0300 Subject: [PATCH 2/8] turn emails into dynamic --- e2e/cardToken/create.spec.ts | 1 + e2e/payment/cancel.spec.ts | 10 ++++- e2e/payment/capture.spec.ts | 12 +++++- e2e/payment/create.spec.ts | 78 +++++++++++++++++++++++++++++++++++- e2e/payment/get.spec.ts | 10 ++++- 5 files changed, 106 insertions(+), 5 deletions(-) diff --git a/e2e/cardToken/create.spec.ts b/e2e/cardToken/create.spec.ts index b7dac8a1..57d3ad74 100644 --- a/e2e/cardToken/create.spec.ts +++ b/e2e/cardToken/create.spec.ts @@ -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 () => { diff --git a/e2e/payment/cancel.spec.ts b/e2e/payment/cancel.spec.ts index 7965c73f..29a90eb7 100644 --- a/e2e/payment/cancel.spec.ts +++ b/e2e/payment/cancel.spec.ts @@ -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: { @@ -19,7 +21,7 @@ describe('IT, cancel', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email: email, }, transaction_amount: 110.00, installments: 1, @@ -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; + } }); diff --git a/e2e/payment/capture.spec.ts b/e2e/payment/capture.spec.ts index ae87504a..c40e15ce 100644 --- a/e2e/payment/capture.spec.ts +++ b/e2e/payment/capture.spec.ts @@ -10,6 +10,7 @@ describe('IT, capture', () => { const cardToken = await createCardToken(); expect(cardToken).toHaveProperty('id'); + const email = createEmailTestUser(); const paymentBody = { body: { additional_info: { @@ -23,7 +24,7 @@ describe('IT, capture', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email: email, }, transaction_amount: 110.00, installments: 1, @@ -82,6 +83,7 @@ describe('IT, capture', () => { const cardToken = await createCardToken(); expect(cardToken).toHaveProperty('id'); + const email = createEmailTestUser(); const paymentBody = { body: { additional_info: { @@ -95,7 +97,7 @@ describe('IT, capture', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email: email, }, transaction_amount: 110.00, installments: 1, @@ -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; + } }); diff --git a/e2e/payment/create.spec.ts b/e2e/payment/create.spec.ts index 3cfd8a1a..a2719be2 100644 --- a/e2e/payment/create.spec.ts +++ b/e2e/payment/create.spec.ts @@ -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: { @@ -20,7 +22,7 @@ describe('IT, create', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email: email, }, transaction_amount: 110.00, installments: 1, @@ -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; + } }); diff --git a/e2e/payment/get.spec.ts b/e2e/payment/get.spec.ts index f8752bd2..4159f7a2 100644 --- a/e2e/payment/get.spec.ts +++ b/e2e/payment/get.spec.ts @@ -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: { @@ -20,7 +22,7 @@ describe('IT, get', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email: email, }, transaction_amount: 110.00, installments: 1, @@ -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; + } }); From 47923c5c6a17061ad3551c89817111b8fe346936 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Tue, 28 Nov 2023 15:39:56 -0300 Subject: [PATCH 3/8] omit the name of the email variable --- e2e/cardToken/create.spec.ts | 2 +- e2e/customer/create.spec.ts | 4 ++-- e2e/customer/get.spec.ts | 2 +- e2e/customer/remove.spec.ts | 2 +- e2e/customer/update.spec.ts | 2 +- e2e/customerCard/create.spec.ts | 2 +- e2e/customerCard/get.spec.ts | 2 +- e2e/customerCard/list.spec.ts | 2 +- e2e/customerCard/remove.spec.ts | 2 +- e2e/customerCard/update.spec.ts | 2 +- e2e/payment/cancel.spec.ts | 2 +- e2e/payment/capture.spec.ts | 4 ++-- e2e/payment/create.spec.ts | 4 ++-- e2e/payment/get.spec.ts | 2 +- 14 files changed, 17 insertions(+), 17 deletions(-) diff --git a/e2e/cardToken/create.spec.ts b/e2e/cardToken/create.spec.ts index 57d3ad74..75c4a431 100644 --- a/e2e/cardToken/create.spec.ts +++ b/e2e/cardToken/create.spec.ts @@ -10,7 +10,7 @@ describe('IT, create card token', () => { const email = createEmailTestUser(); const emailBody = { - email: email, + email, }; const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); diff --git a/e2e/customer/create.spec.ts b/e2e/customer/create.spec.ts index 7f839d84..2d829c69 100644 --- a/e2e/customer/create.spec.ts +++ b/e2e/customer/create.spec.ts @@ -9,7 +9,7 @@ describe('IT customer, create', () => { const email = createEmailTestUser(); const body = { - email: email, + email, first_name: 'Jhon', last_name: 'Doe', phone: { @@ -36,7 +36,7 @@ describe('IT customer, create', () => { const createCustomer = await customer.create({ body }); expect(createCustomer).toHaveProperty('status', 'active'); expect(createCustomer).toEqual(expect.objectContaining({ - email: email, + email, first_name: 'Jhon', last_name: 'Doe', date_registered: '2023-10-20T11:37:30.000-04:00', diff --git a/e2e/customer/get.spec.ts b/e2e/customer/get.spec.ts index b787f170..2bc9c4e0 100644 --- a/e2e/customer/get.spec.ts +++ b/e2e/customer/get.spec.ts @@ -9,7 +9,7 @@ describe('IT customer, get', () => { const email = createEmailTestUser(); const body = { - email: email, + email, }; const createCustomer = await customer.create({ body }); diff --git a/e2e/customer/remove.spec.ts b/e2e/customer/remove.spec.ts index 9ea2b84e..2f40eb15 100644 --- a/e2e/customer/remove.spec.ts +++ b/e2e/customer/remove.spec.ts @@ -9,7 +9,7 @@ describe('IT customer, remove', () => { const email = createEmailTestUser(); const body = { - email: email, + email, }; const createCustomer = await customer.create({ body }); diff --git a/e2e/customer/update.spec.ts b/e2e/customer/update.spec.ts index 719fb75c..0b017d21 100644 --- a/e2e/customer/update.spec.ts +++ b/e2e/customer/update.spec.ts @@ -8,7 +8,7 @@ describe('IT customer, update', () => { const email = createEmailTestUser(); const body = { - email: email, + email, }; const createCustomer = await customer.create({ body }); diff --git a/e2e/customerCard/create.spec.ts b/e2e/customerCard/create.spec.ts index 77e45d31..f050fd5b 100644 --- a/e2e/customerCard/create.spec.ts +++ b/e2e/customerCard/create.spec.ts @@ -10,7 +10,7 @@ describe('Testing customer cards, create', () => { const email = createEmailTestUser(); const emailBody = { - email: email, + email, }; const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); diff --git a/e2e/customerCard/get.spec.ts b/e2e/customerCard/get.spec.ts index 7b480650..f7e4b083 100644 --- a/e2e/customerCard/get.spec.ts +++ b/e2e/customerCard/get.spec.ts @@ -10,7 +10,7 @@ describe('Testing customer card, get', () => { const email = createEmailTestUser(); const emailBody = { - email: email, + email, }; const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); diff --git a/e2e/customerCard/list.spec.ts b/e2e/customerCard/list.spec.ts index 6ab75ca6..ab897949 100644 --- a/e2e/customerCard/list.spec.ts +++ b/e2e/customerCard/list.spec.ts @@ -10,7 +10,7 @@ describe('Testing customer card, get', () => { const email = createEmailTestUser(); const emailBody = { - email: email, + email, }; const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); diff --git a/e2e/customerCard/remove.spec.ts b/e2e/customerCard/remove.spec.ts index 96b486ef..86deb35c 100644 --- a/e2e/customerCard/remove.spec.ts +++ b/e2e/customerCard/remove.spec.ts @@ -10,7 +10,7 @@ describe('Testing customer card, get', () => { const email = createEmailTestUser(); const emailBody = { - email: email, + email, }; const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); diff --git a/e2e/customerCard/update.spec.ts b/e2e/customerCard/update.spec.ts index 1a9ab780..bf1127a1 100644 --- a/e2e/customerCard/update.spec.ts +++ b/e2e/customerCard/update.spec.ts @@ -10,7 +10,7 @@ describe('Testing customer card, get', () => { const email = createEmailTestUser(); const emailBody = { - email: email, + email, }; const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); diff --git a/e2e/payment/cancel.spec.ts b/e2e/payment/cancel.spec.ts index 29a90eb7..2a5fd4b3 100644 --- a/e2e/payment/cancel.spec.ts +++ b/e2e/payment/cancel.spec.ts @@ -21,7 +21,7 @@ describe('IT, cancel', () => { ] }, payer: { - email: email, + email, }, transaction_amount: 110.00, installments: 1, diff --git a/e2e/payment/capture.spec.ts b/e2e/payment/capture.spec.ts index c40e15ce..8570fa10 100644 --- a/e2e/payment/capture.spec.ts +++ b/e2e/payment/capture.spec.ts @@ -24,7 +24,7 @@ describe('IT, capture', () => { ] }, payer: { - email: email, + email, }, transaction_amount: 110.00, installments: 1, @@ -97,7 +97,7 @@ describe('IT, capture', () => { ] }, payer: { - email: email, + email, }, transaction_amount: 110.00, installments: 1, diff --git a/e2e/payment/create.spec.ts b/e2e/payment/create.spec.ts index a2719be2..66be8b63 100644 --- a/e2e/payment/create.spec.ts +++ b/e2e/payment/create.spec.ts @@ -22,7 +22,7 @@ describe('IT, create', () => { ] }, payer: { - email: email, + email, }, transaction_amount: 110.00, installments: 1, @@ -82,7 +82,7 @@ describe('IT, create', () => { ] }, payer: { - email: email, + email, address: { zip_code: '06233200', street_name: 'street_name', diff --git a/e2e/payment/get.spec.ts b/e2e/payment/get.spec.ts index 4159f7a2..e225f422 100644 --- a/e2e/payment/get.spec.ts +++ b/e2e/payment/get.spec.ts @@ -22,7 +22,7 @@ describe('IT, get', () => { ] }, payer: { - email: email, + email, }, transaction_amount: 110.00, installments: 1, From ef6dd25022a97a33e579c53dd41a36df5988cda9 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Tue, 28 Nov 2023 19:31:45 -0300 Subject: [PATCH 4/8] create mock diretory and move createEmailTestUser function --- e2e/payment/cancel.spec.ts | 7 +------ e2e/payment/capture.spec.ts | 8 ++------ e2e/payment/create.spec.ts | 7 +------ e2e/payment/get.spec.ts | 7 +------ src/mocks/createEmailTestUser.ts | 10 ++++++++++ tsconfig.production.json | 2 +- 6 files changed, 16 insertions(+), 25 deletions(-) create mode 100644 src/mocks/createEmailTestUser.ts diff --git a/e2e/payment/cancel.spec.ts b/e2e/payment/cancel.spec.ts index 2a5fd4b3..733db1a6 100644 --- a/e2e/payment/cancel.spec.ts +++ b/e2e/payment/cancel.spec.ts @@ -1,5 +1,6 @@ import MercadoPago, { Payment } from '@src/index'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT, cancel', () => { test('should cancel Payment and match response object', async () => { @@ -35,10 +36,4 @@ 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; - } }); diff --git a/e2e/payment/capture.spec.ts b/e2e/payment/capture.spec.ts index 8570fa10..a9f2ea2d 100644 --- a/e2e/payment/capture.spec.ts +++ b/e2e/payment/capture.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Payment } from '@src/index'; import fetch from 'node-fetch'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT, capture', () => { test('should capture, return partial transaction_amount passed at the request and match response object', async () => { @@ -84,6 +85,7 @@ describe('IT, capture', () => { expect(cardToken).toHaveProperty('id'); const email = createEmailTestUser(); + const paymentBody = { body: { additional_info: { @@ -172,10 +174,4 @@ 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; - } }); diff --git a/e2e/payment/create.spec.ts b/e2e/payment/create.spec.ts index 66be8b63..da05c948 100644 --- a/e2e/payment/create.spec.ts +++ b/e2e/payment/create.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Payment } from '@src/index'; import { config } from '../e2e.config'; import type { PaymentCreateData } from '@src/clients/payment/create/types'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT, create', () => { test('should create Payment and match response object', async () => { @@ -130,11 +131,5 @@ describe('IT, create', () => { }), })); }); - - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } }); diff --git a/e2e/payment/get.spec.ts b/e2e/payment/get.spec.ts index e225f422..cbe3a6f1 100644 --- a/e2e/payment/get.spec.ts +++ b/e2e/payment/get.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Payment } from '@src/index'; import { config } from '../e2e.config'; import type { PaymentCreateData } from '@src/clients/payment/create/types'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT, get', () => { test('should get Payment and match response object', async () => { @@ -63,10 +64,4 @@ describe('IT, get', () => { }), })); }); - - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } }); diff --git a/src/mocks/createEmailTestUser.ts b/src/mocks/createEmailTestUser.ts new file mode 100644 index 00000000..9ccd7953 --- /dev/null +++ b/src/mocks/createEmailTestUser.ts @@ -0,0 +1,10 @@ +function createEmailTestUser() { + const random = Math.floor(Math.random() * 1000000); + const email = 'test_user' + random + '@testuser.com'; + return email; +} + +export { + createEmailTestUser +}; + diff --git a/tsconfig.production.json b/tsconfig.production.json index 2b8c2ed8..8ead8d5a 100644 --- a/tsconfig.production.json +++ b/tsconfig.production.json @@ -1,4 +1,4 @@ { "extends": "./tsconfig", - "exclude": ["node_modules", "**/*spec.ts", "src/examples", "e2e"] + "exclude": ["node_modules", "**/*spec.ts", "src/examples", "e2e", "src/mocks"] } From 65011d3ccbba360dc0cb4ed2497862ff73269a42 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Tue, 28 Nov 2023 19:41:02 -0300 Subject: [PATCH 5/8] update createEmailTestUser imports --- e2e/cardToken/create.spec.ts | 8 ++------ e2e/customer/create.spec.ts | 7 +------ e2e/customer/get.spec.ts | 7 +------ e2e/customer/remove.spec.ts | 8 +------- e2e/customer/update.spec.ts | 7 +------ e2e/customerCard/create.spec.ts | 7 +------ e2e/customerCard/get.spec.ts | 7 +------ e2e/customerCard/list.spec.ts | 7 +------ e2e/customerCard/remove.spec.ts | 7 +------ e2e/customerCard/update.spec.ts | 7 +------ 10 files changed, 11 insertions(+), 61 deletions(-) diff --git a/e2e/cardToken/create.spec.ts b/e2e/cardToken/create.spec.ts index 75c4a431..796cec36 100644 --- a/e2e/cardToken/create.spec.ts +++ b/e2e/cardToken/create.spec.ts @@ -1,6 +1,8 @@ import MercadoPago, { CardToken, Customer, CustomerCard } from '@src/index'; import fetch from 'node-fetch'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; + describe('IT, create card token', () => { test('should make a request and return created card token id', async () => { const client = new MercadoPago({ accessToken: config.test_access_token }); @@ -44,12 +46,6 @@ describe('IT, create card token', () => { })); }); - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } - async function createCardToken() { const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { method: 'POST', diff --git a/e2e/customer/create.spec.ts b/e2e/customer/create.spec.ts index 2d829c69..aa12f66a 100644 --- a/e2e/customer/create.spec.ts +++ b/e2e/customer/create.spec.ts @@ -1,5 +1,6 @@ import MercadoPago, { Customer } from '@src/index'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT customer, create', () => { test('should create a client and match response object', async () => { @@ -77,10 +78,4 @@ describe('IT customer, create', () => { const removeCustomer = await customer.remove({ customerId: createCustomer.id }); expect(removeCustomer).toHaveProperty('id', removeCustomer.id); }); - - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } }); diff --git a/e2e/customer/get.spec.ts b/e2e/customer/get.spec.ts index 2bc9c4e0..2b737f36 100644 --- a/e2e/customer/get.spec.ts +++ b/e2e/customer/get.spec.ts @@ -1,5 +1,6 @@ import MercadoPago, { Customer } from '@src/index'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT customer, get', () => { test('should get a client and match response object', async () => { @@ -23,10 +24,4 @@ describe('IT customer, get', () => { const removeCustomer = await customer.remove({ customerId: customerGet.id }); expect(removeCustomer).toHaveProperty('id', removeCustomer.id); }); - - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } }); diff --git a/e2e/customer/remove.spec.ts b/e2e/customer/remove.spec.ts index 2f40eb15..1ecd29ac 100644 --- a/e2e/customer/remove.spec.ts +++ b/e2e/customer/remove.spec.ts @@ -1,5 +1,6 @@ import MercadoPago, { Customer } from '@src/index'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT customer, remove', () => { test('should delete a customer and match response object', async () => { @@ -30,12 +31,5 @@ describe('IT customer, remove', () => { address: expect.any(Object), date_last_updated: expect.any(String), })); - }); - - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } }); diff --git a/e2e/customer/update.spec.ts b/e2e/customer/update.spec.ts index 0b017d21..84012ba1 100644 --- a/e2e/customer/update.spec.ts +++ b/e2e/customer/update.spec.ts @@ -1,5 +1,6 @@ import MercadoPago, { Customer } from '@src/index'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('IT customer, update', () => { test('should update a customer and match response object', async () => { @@ -40,10 +41,4 @@ describe('IT customer, update', () => { const removeCustomer = await customer.remove({ customerId: createCustomer.id }); expect(removeCustomer).toHaveProperty('id', removeCustomer.id); }); - - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } }); diff --git a/e2e/customerCard/create.spec.ts b/e2e/customerCard/create.spec.ts index f050fd5b..e8bebf6a 100644 --- a/e2e/customerCard/create.spec.ts +++ b/e2e/customerCard/create.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; import fetch from 'node-fetch'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('Testing customer cards, create', () => { test('should create customer card and match response object', async () => { @@ -60,12 +61,6 @@ describe('Testing customer cards, create', () => { expect(removeCustomer.api_response.status).toBe(200); }); - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } - async function createCardToken() { const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { method: 'POST', diff --git a/e2e/customerCard/get.spec.ts b/e2e/customerCard/get.spec.ts index f7e4b083..ae21b7fe 100644 --- a/e2e/customerCard/get.spec.ts +++ b/e2e/customerCard/get.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; import fetch from 'node-fetch'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('Testing customer card, get', () => { test('should get customer card and match response object', async () => { @@ -63,12 +64,6 @@ describe('Testing customer card, get', () => { expect(removeCustomer.api_response.status).toBe(200); }); - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } - async function createCardToken() { const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { method: 'POST', diff --git a/e2e/customerCard/list.spec.ts b/e2e/customerCard/list.spec.ts index ab897949..05aaa03e 100644 --- a/e2e/customerCard/list.spec.ts +++ b/e2e/customerCard/list.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; import fetch from 'node-fetch'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('Testing customer card, get', () => { test('should get list of cards and match response object', async () => { @@ -64,12 +65,6 @@ describe('Testing customer card, get', () => { expect(removeCustomer.api_response.status).toBe(200); }); - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } - async function createCardToken() { const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { method: 'POST', diff --git a/e2e/customerCard/remove.spec.ts b/e2e/customerCard/remove.spec.ts index 86deb35c..e4b30a20 100644 --- a/e2e/customerCard/remove.spec.ts +++ b/e2e/customerCard/remove.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; import fetch from 'node-fetch'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('Testing customer card, get', () => { test('should remove card and match response object', async () => { @@ -62,12 +63,6 @@ describe('Testing customer card, get', () => { expect(removeCustomer.api_response.status).toBe(200); }); - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } - async function createCardToken() { const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { method: 'POST', diff --git a/e2e/customerCard/update.spec.ts b/e2e/customerCard/update.spec.ts index bf1127a1..c24417ad 100644 --- a/e2e/customerCard/update.spec.ts +++ b/e2e/customerCard/update.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; import fetch from 'node-fetch'; import { config } from '../e2e.config'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; describe('Testing customer card, get', () => { test('should update card and match response object', async () => { @@ -78,12 +79,6 @@ describe('Testing customer card, get', () => { expect(removeCustomer.api_response.status).toBe(200); }); - function createEmailTestUser() { - const random = Math.floor(Math.random() * 1000000); - const email = 'test_user' + random + '@testuser.com'; - return email; - } - async function createCardToken() { const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { method: 'POST', From 65094316e4bff6dcc2868cf551698d5336d5dafa Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Tue, 28 Nov 2023 20:22:56 -0300 Subject: [PATCH 6/8] move createCardToken function to mock directory --- e2e/cardToken/create.spec.ts | 29 ++--------------------------- e2e/customerCard/create.spec.ts | 29 ++--------------------------- e2e/customerCard/get.spec.ts | 29 ++--------------------------- e2e/customerCard/list.spec.ts | 29 ++--------------------------- e2e/customerCard/remove.spec.ts | 29 ++--------------------------- e2e/customerCard/update.spec.ts | 29 ++--------------------------- e2e/payment/capture.spec.ts | 30 +++--------------------------- e2e/paymentRefund/create.spec.ts | 28 ++-------------------------- e2e/paymentRefund/get.spec.ts | 28 ++-------------------------- e2e/paymentRefund/list.spec.ts | 28 ++-------------------------- e2e/paymentRefund/total.spec.ts | 28 ++-------------------------- src/mocks/createCardToken.ts | 30 ++++++++++++++++++++++++++++++ 12 files changed, 53 insertions(+), 293 deletions(-) create mode 100644 src/mocks/createCardToken.ts diff --git a/e2e/cardToken/create.spec.ts b/e2e/cardToken/create.spec.ts index 796cec36..4ae7330a 100644 --- a/e2e/cardToken/create.spec.ts +++ b/e2e/cardToken/create.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { CardToken, Customer, CustomerCard } from '@src/index'; -import fetch from 'node-fetch'; import { config } from '../e2e.config'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('IT, create card token', () => { test('should make a request and return created card token id', async () => { @@ -17,7 +17,7 @@ describe('IT, create card token', () => { const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); - const createToken = await createCardToken(); + const createToken = await createCardToken(client.accessToken); const customerBody = { token: createToken.id }; @@ -45,29 +45,4 @@ describe('IT, create card token', () => { security_code_length: expect.any(Number), })); }); - - async function createCardToken() { - const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { - method: 'POST', - headers: { - 'Authorization': 'Bearer ' + config.test_access_token, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - site_id: 'MLB', - card_number: '5031433215406351', - expiration_year: '2025', - expiration_month: '11', - security_code: '123', - cardholder: { - identification: { - type: 'CPF', - number: '01234567890' - }, - name: 'APRO' - } - }) - }); - return await response.json(); - } }); diff --git a/e2e/customerCard/create.spec.ts b/e2e/customerCard/create.spec.ts index e8bebf6a..b2dde142 100644 --- a/e2e/customerCard/create.spec.ts +++ b/e2e/customerCard/create.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; -import fetch from 'node-fetch'; import { config } from '../e2e.config'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('Testing customer cards, create', () => { test('should create customer card and match response object', async () => { @@ -16,7 +16,7 @@ describe('Testing customer cards, create', () => { const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); - const createToken = await createCardToken(); + const createToken = await createCardToken(client.accessToken); const customerBody = { token: createToken.id }; @@ -60,29 +60,4 @@ describe('Testing customer cards, create', () => { const removeCustomer = await customer.remove({ customerId: createCustomer.id }); expect(removeCustomer.api_response.status).toBe(200); }); - - async function createCardToken() { - const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { - method: 'POST', - headers: { - 'Authorization': 'Bearer ' + config.test_access_token, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - site_id: 'MLB', - card_number: '5031433215406351', - expiration_year: '2025', - expiration_month: '11', - security_code: '123', - cardholder: { - identification: { - type: 'CPF', - number: '01234567890' - }, - name: 'APRO' - } - }) - }); - return await response.json(); - } }); diff --git a/e2e/customerCard/get.spec.ts b/e2e/customerCard/get.spec.ts index ae21b7fe..80e71fb0 100644 --- a/e2e/customerCard/get.spec.ts +++ b/e2e/customerCard/get.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; -import fetch from 'node-fetch'; import { config } from '../e2e.config'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('Testing customer card, get', () => { test('should get customer card and match response object', async () => { @@ -16,7 +16,7 @@ describe('Testing customer card, get', () => { const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); - const createToken = await createCardToken(); + const createToken = await createCardToken(client.accessToken); const customerBody = { token: createToken.id }; @@ -63,29 +63,4 @@ describe('Testing customer card, get', () => { const removeCustomer = await customer.remove({ customerId: createCustomer.id }); expect(removeCustomer.api_response.status).toBe(200); }); - - async function createCardToken() { - const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { - method: 'POST', - headers: { - 'Authorization': 'Bearer ' + config.test_access_token, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - site_id: 'MLB', - card_number: '5031433215406351', - expiration_year: '2025', - expiration_month: '11', - security_code: '123', - cardholder: { - identification: { - type: 'CPF', - number: '01234567890' - }, - name: 'APRO' - } - }) - }); - return await response.json(); - } }); diff --git a/e2e/customerCard/list.spec.ts b/e2e/customerCard/list.spec.ts index 05aaa03e..273a2f0d 100644 --- a/e2e/customerCard/list.spec.ts +++ b/e2e/customerCard/list.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; -import fetch from 'node-fetch'; import { config } from '../e2e.config'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('Testing customer card, get', () => { test('should get list of cards and match response object', async () => { @@ -16,7 +16,7 @@ describe('Testing customer card, get', () => { const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); - const createToken = await createCardToken(); + const createToken = await createCardToken(client.accessToken); const customerBody = { token: createToken.id }; @@ -64,29 +64,4 @@ describe('Testing customer card, get', () => { const removeCustomer = await customer.remove({ customerId: createCustomer.id }); expect(removeCustomer.api_response.status).toBe(200); }); - - async function createCardToken() { - const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { - method: 'POST', - headers: { - 'Authorization': 'Bearer ' + config.test_access_token, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - site_id: 'MLB', - card_number: '5031433215406351', - expiration_year: '2025', - expiration_month: '11', - security_code: '123', - cardholder: { - identification: { - type: 'CPF', - number: '01234567890' - }, - name: 'APRO' - } - }) - }); - return await response.json(); - } }); diff --git a/e2e/customerCard/remove.spec.ts b/e2e/customerCard/remove.spec.ts index e4b30a20..dd7a2d72 100644 --- a/e2e/customerCard/remove.spec.ts +++ b/e2e/customerCard/remove.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; -import fetch from 'node-fetch'; import { config } from '../e2e.config'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('Testing customer card, get', () => { test('should remove card and match response object', async () => { @@ -16,7 +16,7 @@ describe('Testing customer card, get', () => { const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); - const createToken = await createCardToken(); + const createToken = await createCardToken(client.accessToken); const customerBody = { token: createToken.id }; @@ -62,29 +62,4 @@ describe('Testing customer card, get', () => { const removeCustomer = await customer.remove({ customerId: createCustomer.id }); expect(removeCustomer.api_response.status).toBe(200); }); - - async function createCardToken() { - const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { - method: 'POST', - headers: { - 'Authorization': 'Bearer ' + config.test_access_token, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - site_id: 'MLB', - card_number: '5031433215406351', - expiration_year: '2025', - expiration_month: '11', - security_code: '123', - cardholder: { - identification: { - type: 'CPF', - number: '01234567890' - }, - name: 'APRO' - } - }) - }); - return await response.json(); - } }); diff --git a/e2e/customerCard/update.spec.ts b/e2e/customerCard/update.spec.ts index c24417ad..5ae91564 100644 --- a/e2e/customerCard/update.spec.ts +++ b/e2e/customerCard/update.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Customer, CustomerCard } from '@src/index'; -import fetch from 'node-fetch'; import { config } from '../e2e.config'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('Testing customer card, get', () => { test('should update card and match response object', async () => { @@ -16,7 +16,7 @@ describe('Testing customer card, get', () => { const createCustomer = await customer.create({ body: emailBody }); expect(createCustomer).toHaveProperty('id'); - const createToken = await createCardToken(); + const createToken = await createCardToken(client.accessToken); const customerBody = { token: createToken.id }; @@ -78,29 +78,4 @@ describe('Testing customer card, get', () => { const removeCustomer = await customer.remove({ customerId: createCustomer.id }); expect(removeCustomer.api_response.status).toBe(200); }); - - async function createCardToken() { - const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { - method: 'POST', - headers: { - 'Authorization': 'Bearer ' + config.test_access_token, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - site_id: 'MLB', - card_number: '5031433215406351', - expiration_year: '2025', - expiration_month: '11', - security_code: '123', - cardholder: { - identification: { - type: 'CPF', - number: '01234567890' - }, - name: 'APRO' - } - }) - }); - return await response.json(); - } }); diff --git a/e2e/payment/capture.spec.ts b/e2e/payment/capture.spec.ts index a9f2ea2d..14bfee96 100644 --- a/e2e/payment/capture.spec.ts +++ b/e2e/payment/capture.spec.ts @@ -1,14 +1,14 @@ import MercadoPago, { Payment } from '@src/index'; -import fetch from 'node-fetch'; import { config } from '../e2e.config'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('IT, capture', () => { test('should capture, return partial transaction_amount passed at the request and match response object', async () => { const client = new MercadoPago({ accessToken: config.access_token }); const payment = new Payment(client); - const cardToken = await createCardToken(); + const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); const email = createEmailTestUser(); @@ -81,7 +81,7 @@ describe('IT, capture', () => { const client = new MercadoPago({ accessToken: config.access_token }); const payment = new Payment(client); - const cardToken = await createCardToken(); + const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); const email = createEmailTestUser(); @@ -150,28 +150,4 @@ describe('IT, capture', () => { transaction_amount_refunded: expect.any(Number), })); }); - - 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(); - } }); diff --git a/e2e/paymentRefund/create.spec.ts b/e2e/paymentRefund/create.spec.ts index 0ba48e58..f8b05d49 100644 --- a/e2e/paymentRefund/create.spec.ts +++ b/e2e/paymentRefund/create.spec.ts @@ -1,7 +1,7 @@ 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 { createCardToken } from '@src/mocks/createCardToken'; describe('IT refunds, create', () => { test('should make a request with partial amount and match response object', async () => { @@ -9,7 +9,7 @@ describe('IT refunds, create', () => { const refund = new PaymentRefund(client); const payment = new Payment(client); try { - const cardToken = await createCardToken(); + const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); const paymentBody = { @@ -66,28 +66,4 @@ describe('IT refunds, create', () => { console.error(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(); - } }); diff --git a/e2e/paymentRefund/get.spec.ts b/e2e/paymentRefund/get.spec.ts index f43fc4eb..32ccd27d 100644 --- a/e2e/paymentRefund/get.spec.ts +++ b/e2e/paymentRefund/get.spec.ts @@ -1,8 +1,8 @@ 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'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('IT refunds, get', () => { test('should make a request and match response object', async () => { @@ -10,7 +10,7 @@ describe('IT refunds, get', () => { const refund = new PaymentRefund(client); const payment = new Payment(client); try { - const cardToken = await createCardToken(); + const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); const paymentBody = { @@ -74,28 +74,4 @@ describe('IT refunds, get', () => { console.error(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(); - } }); diff --git a/e2e/paymentRefund/list.spec.ts b/e2e/paymentRefund/list.spec.ts index 634c68bf..45e233e1 100644 --- a/e2e/paymentRefund/list.spec.ts +++ b/e2e/paymentRefund/list.spec.ts @@ -1,8 +1,8 @@ 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'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('IT refunds, list', () => { test('should make a request, return a list and match response object', async () => { @@ -10,7 +10,7 @@ describe('IT refunds, list', () => { const refund = new PaymentRefund(client); const payment = new Payment(client); try { - const cardToken = await createCardToken(); + const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); const paymentBody = { @@ -74,28 +74,4 @@ describe('IT refunds, list', () => { console.error(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(); - } }); diff --git a/e2e/paymentRefund/total.spec.ts b/e2e/paymentRefund/total.spec.ts index 64eee565..7e0d2646 100644 --- a/e2e/paymentRefund/total.spec.ts +++ b/e2e/paymentRefund/total.spec.ts @@ -1,8 +1,8 @@ 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'; +import { createCardToken } from '@src/mocks/createCardToken'; describe('IT refunds, total', () => { test('should make a request, refund total amount and match response object', async () => { @@ -10,7 +10,7 @@ describe('IT refunds, total', () => { const refund = new PaymentRefund(client); const payment = new Payment(client); try { - const cardToken = await createCardToken(); + const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); const paymentBody = createPayment(cardToken.id); @@ -70,28 +70,4 @@ describe('IT refunds, total', () => { }; 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(); - } }); diff --git a/src/mocks/createCardToken.ts b/src/mocks/createCardToken.ts new file mode 100644 index 00000000..30780b37 --- /dev/null +++ b/src/mocks/createCardToken.ts @@ -0,0 +1,30 @@ +import fetch from 'node-fetch'; + +async function createCardToken(token: string) { + const response = await fetch('https://api.mercadopago.com/v1/card_tokens', { + method: 'POST', + headers: { + 'Authorization': 'Bearer ' + token, + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + site_id: 'MLB', + card_number: '5031433215406351', + expiration_year: '2025', + expiration_month: '11', + security_code: '123', + cardholder: { + identification: { + type: 'CPF', + number: '01234567890' + }, + name: 'APRO' + } + }) + }); + return await response.json(); +} + +export { + createCardToken +}; From 4b8bcbb61405683ea26ed50909a05f10e565da41 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Wed, 29 Nov 2023 09:42:29 -0300 Subject: [PATCH 7/8] organize imports --- e2e/payment/create.spec.ts | 2 +- e2e/payment/get.spec.ts | 2 +- e2e/paymentRefund/create.spec.ts | 2 +- e2e/paymentRefund/get.spec.ts | 4 ++-- e2e/paymentRefund/list.spec.ts | 2 +- e2e/paymentRefund/total.spec.ts | 2 +- src/clients/payment/cancel/index.ts | 1 - src/clients/payment/capture/index.ts | 1 - src/clients/payment/commonTypes.ts | 2 +- src/clients/payment/get/index.ts | 1 - 10 files changed, 8 insertions(+), 11 deletions(-) diff --git a/e2e/payment/create.spec.ts b/e2e/payment/create.spec.ts index da05c948..b0010f70 100644 --- a/e2e/payment/create.spec.ts +++ b/e2e/payment/create.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Payment } from '@src/index'; import { config } from '../e2e.config'; -import type { PaymentCreateData } from '@src/clients/payment/create/types'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import type { PaymentCreateData } from '@src/clients/payment/create/types'; describe('IT, create', () => { test('should create Payment and match response object', async () => { diff --git a/e2e/payment/get.spec.ts b/e2e/payment/get.spec.ts index cbe3a6f1..fc16e039 100644 --- a/e2e/payment/get.spec.ts +++ b/e2e/payment/get.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Payment } from '@src/index'; import { config } from '../e2e.config'; -import type { PaymentCreateData } from '@src/clients/payment/create/types'; import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; +import type { PaymentCreateData } from '@src/clients/payment/create/types'; describe('IT, get', () => { test('should get Payment and match response object', async () => { diff --git a/e2e/paymentRefund/create.spec.ts b/e2e/paymentRefund/create.spec.ts index f8b05d49..0acc1837 100644 --- a/e2e/paymentRefund/create.spec.ts +++ b/e2e/paymentRefund/create.spec.ts @@ -1,7 +1,7 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; -import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; import { createCardToken } from '@src/mocks/createCardToken'; +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 () => { diff --git a/e2e/paymentRefund/get.spec.ts b/e2e/paymentRefund/get.spec.ts index 32ccd27d..934c3c53 100644 --- a/e2e/paymentRefund/get.spec.ts +++ b/e2e/paymentRefund/get.spec.ts @@ -1,8 +1,8 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; -import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; -import type { PaymentRefundGetData } from '@src/clients/paymentRefund/get/types'; import { createCardToken } from '@src/mocks/createCardToken'; +import type { PaymentRefundGetData } from '@src/clients/paymentRefund/get/types'; +import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; describe('IT refunds, get', () => { test('should make a request and match response object', async () => { diff --git a/e2e/paymentRefund/list.spec.ts b/e2e/paymentRefund/list.spec.ts index 45e233e1..a0044f55 100644 --- a/e2e/paymentRefund/list.spec.ts +++ b/e2e/paymentRefund/list.spec.ts @@ -1,8 +1,8 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; +import { createCardToken } from '@src/mocks/createCardToken'; import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; import type { PaymentRefundListData } from '@src/clients/paymentRefund/list/types'; -import { createCardToken } from '@src/mocks/createCardToken'; describe('IT refunds, list', () => { test('should make a request, return a list and match response object', async () => { diff --git a/e2e/paymentRefund/total.spec.ts b/e2e/paymentRefund/total.spec.ts index 7e0d2646..706a09db 100644 --- a/e2e/paymentRefund/total.spec.ts +++ b/e2e/paymentRefund/total.spec.ts @@ -1,8 +1,8 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; +import { createCardToken } from '@src/mocks/createCardToken'; import type { PaymentCreateData } from '@src/clients/payment/create/types'; import type { PaymentRefundTotalData } from '@src/clients/paymentRefund/total/types'; -import { createCardToken } from '@src/mocks/createCardToken'; describe('IT refunds, total', () => { test('should make a request, refund total amount and match response object', async () => { diff --git a/src/clients/payment/cancel/index.ts b/src/clients/payment/cancel/index.ts index 2af68217..c3ad2db8 100644 --- a/src/clients/payment/cancel/index.ts +++ b/src/clients/payment/cancel/index.ts @@ -1,5 +1,4 @@ import { RestClient } from '@utils/restClient'; - import type { PaymentResponse } from '../commonTypes'; import type { PaymentCancelClient } from './types'; diff --git a/src/clients/payment/capture/index.ts b/src/clients/payment/capture/index.ts index 3d3a0d2c..49f677b1 100644 --- a/src/clients/payment/capture/index.ts +++ b/src/clients/payment/capture/index.ts @@ -1,5 +1,4 @@ import { RestClient } from '@utils/restClient'; - import type { PaymentResponse } from '../commonTypes'; import type { PaymentCaptureClient } from './types'; diff --git a/src/clients/payment/commonTypes.ts b/src/clients/payment/commonTypes.ts index b9935675..02ffe0c0 100644 --- a/src/clients/payment/commonTypes.ts +++ b/src/clients/payment/commonTypes.ts @@ -1,6 +1,6 @@ import { ApiResponse } from '@src/types'; -import type { Address, Items, Tax } from '../commonTypes'; import { RefundResponse } from '../paymentRefund/commonTypes'; +import type { Address, Items, Tax } from '../commonTypes'; export declare type MerchantAccount = { merchant_account_id?: string; diff --git a/src/clients/payment/get/index.ts b/src/clients/payment/get/index.ts index 2684335b..cfb59781 100644 --- a/src/clients/payment/get/index.ts +++ b/src/clients/payment/get/index.ts @@ -1,5 +1,4 @@ import { RestClient } from '@utils/restClient'; - import type { PaymentResponse } from '../commonTypes'; import type { PaymentGetClient } from './types'; From d217fb6e7c5cd4a3c51bdfdd2e3eecd07a2b0654 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Wed, 29 Nov 2023 13:38:05 -0300 Subject: [PATCH 8/8] add createEmailTestUser to paymentRefund --- e2e/paymentRefund/create.spec.ts | 5 ++++- e2e/paymentRefund/get.spec.ts | 5 ++++- e2e/paymentRefund/list.spec.ts | 5 ++++- e2e/paymentRefund/total.spec.ts | 4 +++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/e2e/paymentRefund/create.spec.ts b/e2e/paymentRefund/create.spec.ts index 0acc1837..9fa5504a 100644 --- a/e2e/paymentRefund/create.spec.ts +++ b/e2e/paymentRefund/create.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; import { createCardToken } from '@src/mocks/createCardToken'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; describe('IT refunds, create', () => { @@ -12,6 +13,8 @@ describe('IT refunds, create', () => { const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); + const email = createEmailTestUser(); + const paymentBody = { body: { additional_info: { @@ -25,7 +28,7 @@ describe('IT refunds, create', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email, }, transaction_amount: 110.00, installments: 1, diff --git a/e2e/paymentRefund/get.spec.ts b/e2e/paymentRefund/get.spec.ts index 934c3c53..8533ba05 100644 --- a/e2e/paymentRefund/get.spec.ts +++ b/e2e/paymentRefund/get.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; import { createCardToken } from '@src/mocks/createCardToken'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; import type { PaymentRefundGetData } from '@src/clients/paymentRefund/get/types'; import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; @@ -13,6 +14,8 @@ describe('IT refunds, get', () => { const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); + const email = createEmailTestUser(); + const paymentBody = { body: { additional_info: { @@ -26,7 +29,7 @@ describe('IT refunds, get', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email, }, transaction_amount: 140.00, installments: 1, diff --git a/e2e/paymentRefund/list.spec.ts b/e2e/paymentRefund/list.spec.ts index a0044f55..8f20936a 100644 --- a/e2e/paymentRefund/list.spec.ts +++ b/e2e/paymentRefund/list.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; import { createCardToken } from '@src/mocks/createCardToken'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; import type { PaymentRefundCreateData } from '@src/clients/paymentRefund/create/types'; import type { PaymentRefundListData } from '@src/clients/paymentRefund/list/types'; @@ -13,6 +14,8 @@ describe('IT refunds, list', () => { const cardToken = await createCardToken(client.accessToken); expect(cardToken).toHaveProperty('id'); + const email = createEmailTestUser(); + const paymentBody = { body: { additional_info: { @@ -26,7 +29,7 @@ describe('IT refunds, list', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email, }, transaction_amount: 110.00, installments: 1, diff --git a/e2e/paymentRefund/total.spec.ts b/e2e/paymentRefund/total.spec.ts index 706a09db..82365d95 100644 --- a/e2e/paymentRefund/total.spec.ts +++ b/e2e/paymentRefund/total.spec.ts @@ -1,6 +1,7 @@ import MercadoPago, { Payment, PaymentRefund } from '@src/index'; import { config } from '../e2e.config'; import { createCardToken } from '@src/mocks/createCardToken'; +import { createEmailTestUser } from '@src/mocks/createEmailTestUser'; import type { PaymentCreateData } from '@src/clients/payment/create/types'; import type { PaymentRefundTotalData } from '@src/clients/paymentRefund/total/types'; @@ -45,6 +46,7 @@ describe('IT refunds, total', () => { } }, 10000); + const email = createEmailTestUser(); function createPayment(token: string): PaymentCreateData { const body = { @@ -60,7 +62,7 @@ describe('IT refunds, total', () => { ] }, payer: { - email: 'test_user_123@testuser.com', + email, }, transaction_amount: 110.00, installments: 1,