diff --git a/.gitignore b/.gitignore index 9dd76421..4f8507fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# ============= Config e2e ============= +/e2e/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/example.e2e.config.ts b/e2e/example.e2e.config.ts new file mode 100644 index 00000000..df8a0864 --- /dev/null +++ b/e2e/example.e2e.config.ts @@ -0,0 +1,13 @@ +/** + * This is an example configuration file for e2e tests, where you must add your credentials and other personal settings. + * Inside the e2e directory, create a file with the name: e2e.config.ts. + * Copy the contents of the example file, add it to the e2e.config.ts file and add your personal settings. + */ + +const config = { + access_token: '', +}; + +export { + config, +}; 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/e2e/preference/create.spec.ts b/e2e/preference/create.spec.ts new file mode 100644 index 00000000..f75c62b6 --- /dev/null +++ b/e2e/preference/create.spec.ts @@ -0,0 +1,50 @@ +import MercadoPago, { Preference } from '@src/index'; +import { config } from '../e2e.config'; +import type { PreferenceCreateData } from '@src/clients/preference/create/types'; + +describe('Preference IT, create', () => { + test('should create Preference and match response object', async () => { + + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + const preference = new Preference(client); + + const preferenceRequest: PreferenceCreateData = { + body: { + items: [ + { + id: '4567', + category_id: 'car_electronics', + currency_id: 'BRL', + description: 'Dummy create', + picture_url: 'https://http2.mlstatic.com/D_NQ_NP_887467-MLA71526269815_092023-F.jpg', + title: 'Dummy Title', + quantity: 1, + unit_price: 10 + } + ], + } + }; + + const response = await preference.create(preferenceRequest); + expect(response.items[0].title).toBe(preferenceRequest.body.items[0].title); + expect(response).toEqual(expect.objectContaining({ + init_point: expect.any(String), + client_id: expect.any(String), + collector_id: expect.any(Number), + date_created: expect.any(String), + id: expect.any(String), + sandbox_init_point: expect.any(String), + site_id: expect.any(String), + })); + expect(response.items[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + category_id: expect.any(String), + currency_id: expect.any(String), + description: expect.any(String), + picture_url: expect.any(String), + title: expect.any(String), + quantity: expect.any(Number), + unit_price: expect.any(Number), + })); + }); +}); diff --git a/e2e/preference/get.spec.ts b/e2e/preference/get.spec.ts new file mode 100644 index 00000000..77a66130 --- /dev/null +++ b/e2e/preference/get.spec.ts @@ -0,0 +1,45 @@ +import MercadoPago, { Preference } from '@src/index'; +import { config } from '../e2e.config'; +import type { PreferenceCreateData } from '@src/clients/preference/create/types'; + +describe('Preference IT, get', () => { + test('should get preference and match response object', async () => { + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + const preference = new Preference(client); + + const preferenceRequest: PreferenceCreateData = { + body: { + items: [ + { + id: '4567', + title: 'Dummy Title Create', + quantity: 1, + unit_price: 10 + } + ], } + }; + const request = await preference.create(preferenceRequest); + + const response = await preference.get({ preferenceId: request.id }); + expect(response).toHaveProperty('id', request.id); + expect(response).toEqual(expect.objectContaining({ + init_point: expect.any(String), + client_id: expect.any(String), + collector_id: expect.any(Number), + date_created: expect.any(String), + id: expect.any(String), + sandbox_init_point: expect.any(String), + site_id: expect.any(String), + })); + expect(response.items[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + category_id: expect.any(String), + currency_id: expect.any(String), + description: expect.any(String), + title: expect.any(String), + quantity: expect.any(Number), + unit_price: expect.any(Number), + })); + }); + +}); diff --git a/e2e/preference/search.spec.ts b/e2e/preference/search.spec.ts new file mode 100644 index 00000000..f93b5155 --- /dev/null +++ b/e2e/preference/search.spec.ts @@ -0,0 +1,31 @@ +import MercadoPago, { Preference } from '@src/index'; +import { config } from '../e2e.config'; + +describe('Preference IT, search', () => { + test('should search a request and match response object', async () => { + const client = new MercadoPago({ accessToken: config.access_token, options: { timeout: 5000 } }); + const preference = new Preference(client); + + const searched = await preference.search(); + + expect(searched).toEqual(expect.objectContaining({ + elements: expect.any(Array), + next_offset: expect.any(Number), + total: expect.any(Number), + })); + expect(searched.elements.length).toBeGreaterThan(0); + expect(searched.elements[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + client_id: expect.any(String), + collector_id: expect.any(Number), + date_created: expect.any(String), + expires: expect.any(Boolean), + live_mode: expect.any(Boolean), + marketplace: expect.any(String), + operation_type: expect.any(String), + site_id: expect.any(String), + sponsor_id: expect.any(Number), + shipping_mode: expect.any(String), + })); + }); +}); diff --git a/e2e/preference/update.spec.ts b/e2e/preference/update.spec.ts new file mode 100644 index 00000000..da139dc3 --- /dev/null +++ b/e2e/preference/update.spec.ts @@ -0,0 +1,64 @@ +import MercadoPago, { Preference } from '@src/index'; +import { config } from '../e2e.config'; +import type { PreferenceCreateData } from '@src/clients/preference/create/types'; +import type { PreferenceUpdateData } from '@src/clients/preference/update/types'; + +describe('Preference IT, update', () => { + test('should update request and match response object', async () => { + const client = new MercadoPago({ accessToken: config.access_token }); + const preference = new Preference(client); + + const preferenceRequest: PreferenceCreateData = { + body: { + items: [ + { + id: '4567', + title: 'Dummy Title Create', + quantity: 1, + unit_price: 10 + } + ], + } + }; + const request = await preference.create(preferenceRequest); + + const updateRequest: PreferenceUpdateData = { + id: request.id, + updatePreferenceRequest: { + items: [ + { + id: '4567', + title: 'Dummy Title Update', + quantity: 1, + unit_price: 10 + } + ], + } + }; + const response = await preference.update(updateRequest); + + expect(response).toEqual(expect.objectContaining({ + id: request.id, + })); + expect(response.items[0].title).toBe(updateRequest.updatePreferenceRequest.items[0].title); + expect(response).toEqual(expect.objectContaining({ + init_point: expect.any(String), + client_id: expect.any(String), + collector_id: expect.any(Number), + date_created: expect.any(String), + id: expect.any(String), + sandbox_init_point: expect.any(String), + site_id: expect.any(String), + })); + expect(response.items[0]).toEqual(expect.objectContaining({ + id: expect.any(String), + category_id: expect.any(String), + currency_id: expect.any(String), + description: expect.any(String), + title: expect.any(String), + quantity: expect.any(Number), + unit_price: expect.any(Number), + })); + }); + +}); 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/src/clients/payment/search/types.ts b/src/clients/payment/search/types.ts index 00a31220..a5720e28 100644 --- a/src/clients/payment/search/types.ts +++ b/src/clients/payment/search/types.ts @@ -45,6 +45,7 @@ export declare type PaymentSearchResult = { merchant_account_id: string; acquirer: string; merchant_number: string; + external_reference: string; }; export declare type Payer = { 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/**/*"] }