From 86c25fc7a71359b5939eab2f7ea4a61b1e5e75db Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Thu, 5 Oct 2023 10:27:58 -0300 Subject: [PATCH 1/4] add e2e config --- .gitignore | 2 ++ e2e/demo/demo.spec.ts | 4 ---- e2e/jest.config.ts | 4 ++-- jest.config.ts | 2 +- tsconfig.json | 4 ++-- 5 files changed, 7 insertions(+), 9 deletions(-) delete mode 100644 e2e/demo/demo.spec.ts diff --git a/.gitignore b/.gitignore index 9dd76421..e7d9529d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +e2e.config.ts + # ============= Lint ============= # Cache eslint .eslintcache diff --git a/e2e/demo/demo.spec.ts b/e2e/demo/demo.spec.ts deleted file mode 100644 index 7fe8d120..00000000 --- a/e2e/demo/demo.spec.ts +++ /dev/null @@ -1,4 +0,0 @@ -test('demo', () => { - //config.access_token; - expect(true).toBeTruthy(); -}); diff --git a/e2e/jest.config.ts b/e2e/jest.config.ts index f8a77fe1..98e0ddb1 100644 --- a/e2e/jest.config.ts +++ b/e2e/jest.config.ts @@ -1,8 +1,8 @@ import jestConfig from '../jest.config'; +jestConfig.rootDir = '../'; jestConfig.testPathIgnorePatterns = [ - '/node_modules/', - '/src/' + 'src' ]; export default jestConfig; diff --git a/jest.config.ts b/jest.config.ts index 54391a15..1061b699 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -12,7 +12,7 @@ const jestConfig: JestConfigWithTsJest = { 'text-summary' ], testMatch: [ - '**/?(*.)+(spec|test).[tj]s?(x)' + '**/?(*.)spec.ts' ], transform: { '^.+\\.(ts|tsx)$': 'ts-jest' }, moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '' }), diff --git a/tsconfig.json b/tsconfig.json index 302f3b5b..f6808185 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,7 @@ "sourceMap": false, "outDir": "./dist", "baseUrl": "./", - "rootDir": "./src", + "rootDir": ".", "resolveJsonModule": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, @@ -22,5 +22,5 @@ "@clients/*": ["./src/clients/*"] } }, - "include": ["src/**/*"] + "include": ["src/**/*", "e2e/**/*"] } From 0d748033d0de3474c6b5a23e3beeb34c1ff50ba3 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Thu, 5 Oct 2023 14:24:32 -0300 Subject: [PATCH 2/4] add integration tests to paymentmethod --- e2e/paymentMethod/get.spec.ts | 49 +++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 e2e/paymentMethod/get.spec.ts diff --git a/e2e/paymentMethod/get.spec.ts b/e2e/paymentMethod/get.spec.ts new file mode 100644 index 00000000..5fd7fcd7 --- /dev/null +++ b/e2e/paymentMethod/get.spec.ts @@ -0,0 +1,49 @@ +import MercadoPago, { PaymentMethod } from '@src/index'; +import { config } from '../e2e.config'; + +describe('Testing get payment methods, get', () => { + test('should pass forward request options from get to RestClient.fetch', async () => { + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + const paymentMethod = new PaymentMethod(client); + + const paymentMethodGet = await paymentMethod.get(); + + paymentMethodGet.forEach(paymentMethod => { + expect([ + 'visa', 'elo', 'master', 'hipercard', 'pix', 'amex', 'pec', 'bolbradesco', 'account_money', 'debelo' + ]).toContain(paymentMethod.id); + }); + paymentMethodGet.forEach(paymentMethod => { + expect([ + 'account_money', 'ticket', 'bank_transfer', 'atm', 'credit_card', 'debit_card', 'prepaid_card', 'digital_currency', 'digital_wallet', 'voucher_card', 'crypto_transfer' + ]).toContain(paymentMethod.payment_type_id); + }); + paymentMethodGet.forEach(paymentMethod => { + expect([ + 'active', 'deactive', 'temporally_deactive' + ]).toContain(paymentMethod.status); + }); + paymentMethodGet.forEach(paymentMethod => { + expect([ + 'supported', 'unsupported', 'does_not_apply' + ]).toContain(paymentMethod.deferred_capture); + }); + expect(Array.isArray(paymentMethodGet)).toBe(true); + expect(paymentMethodGet[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + name: expect.any(String), + payment_type_id: expect.any(String), + status: expect.any(String), + secure_thumbnail: expect.any(String), + thumbnail: expect.any(String), + deferred_capture: expect.any(String), + settings: expect.any(Array), + additional_info_needed: expect.any(Array), + min_allowed_amount: expect.any(Number), + max_allowed_amount: expect.any(Number), + accreditation_time: expect.any(Number), + financial_institutions: expect.any(Array), + processing_modes: expect.any(Array), + })); + }); +}); From 5e817dad2304bfce88581da98c244b4b4258e54a Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Thu, 5 Oct 2023 16:40:09 -0300 Subject: [PATCH 3/4] modify test name --- e2e/paymentMethod/get.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paymentMethod/get.spec.ts b/e2e/paymentMethod/get.spec.ts index 5fd7fcd7..f27498ba 100644 --- a/e2e/paymentMethod/get.spec.ts +++ b/e2e/paymentMethod/get.spec.ts @@ -2,7 +2,7 @@ import MercadoPago, { PaymentMethod } from '@src/index'; import { config } from '../e2e.config'; describe('Testing get payment methods, get', () => { - test('should pass forward request options from get to RestClient.fetch', async () => { + test('should return all available payment methods ', async () => { const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); const paymentMethod = new PaymentMethod(client); From 0d6cb7cb5c09dada7211c20750b74051753b4275 Mon Sep 17 00:00:00 2001 From: Bruna Campos Date: Mon, 16 Oct 2023 13:32:05 -0300 Subject: [PATCH 4/4] remove options --- e2e/paymentMethod/get.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paymentMethod/get.spec.ts b/e2e/paymentMethod/get.spec.ts index f27498ba..0c90a6dd 100644 --- a/e2e/paymentMethod/get.spec.ts +++ b/e2e/paymentMethod/get.spec.ts @@ -3,7 +3,7 @@ import { config } from '../e2e.config'; describe('Testing get payment methods, get', () => { test('should return all available payment methods ', async () => { - const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + const client = new MercadoPago({ accessToken: config.access_token }); const paymentMethod = new PaymentMethod(client); const paymentMethodGet = await paymentMethod.get();