-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #269 from lucmkz/feature/preference-integration-test
IT Preference
- Loading branch information
Showing
11 changed files
with
212 additions
and
9 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
This file was deleted.
Oops, something went wrong.
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,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, | ||
}; |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import jestConfig from '../jest.config'; | ||
|
||
jestConfig.rootDir = '../'; | ||
jestConfig.testPathIgnorePatterns = [ | ||
'/node_modules/', | ||
'/src/' | ||
'src' | ||
]; | ||
|
||
export default jestConfig; |
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,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), | ||
})); | ||
}); | ||
}); |
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,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), | ||
})); | ||
}); | ||
|
||
}); |
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,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), | ||
})); | ||
}); | ||
}); |
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,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), | ||
})); | ||
}); | ||
|
||
}); |
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
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
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