-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b919063
commit 0ebf7f7
Showing
13 changed files
with
435 additions
and
53 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 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 { Malga } from '../../common/malga/malga' | ||
import { AsyncTokenize } from '../async-tokenize' | ||
import { | ||
formElementsMock, | ||
formValuesMock, | ||
handleFormMock, | ||
} from './mock/async-tokenize-mock' | ||
|
||
const MalgaConfigurations = { | ||
apiKey: '17a64c8f-a387-4682-bdd8-d280493715e0', | ||
clientId: 'd1d2b51a-0446-432a-b055-034518c2660e', | ||
options: { | ||
sandbox: true, | ||
}, | ||
} | ||
|
||
vi.mock('../../common/malga/malga', async (importOriginal) => { | ||
const Malga = | ||
await importOriginal<typeof import('../../common/malga/malga')>() | ||
return { | ||
...Malga, | ||
tokenization: vi.fn(), | ||
} | ||
}) | ||
|
||
describe('handle', () => { | ||
test('askmsk', () => { | ||
const { | ||
form, | ||
holderNameInput, | ||
cvvInput, | ||
expirationDateInput, | ||
numberInput, | ||
} = handleFormMock() | ||
|
||
form.action = '/teste' | ||
form.method = 'POST' | ||
form.setAttribute(formElementsMock.form, '') | ||
|
||
holderNameInput.setAttribute(formElementsMock.holderName, '') | ||
numberInput.setAttribute(formElementsMock.number, '') | ||
cvvInput.setAttribute(formElementsMock.cvv, '') | ||
expirationDateInput.setAttribute(formElementsMock.expirationDate, '') | ||
|
||
document.body.appendChild(form) | ||
form.appendChild(holderNameInput) | ||
form.appendChild(numberInput) | ||
form.appendChild(expirationDateInput) | ||
form.appendChild(cvvInput) | ||
|
||
const inputs = document.querySelectorAll('input') | ||
inputs[0].value = formValuesMock.holderName | ||
inputs[1].value = formValuesMock.number | ||
inputs[2].value = formValuesMock.expirationDate | ||
inputs[3].value = formValuesMock.cvv | ||
|
||
const malga = new Malga(MalgaConfigurations) | ||
|
||
const asyncTokenizeObject = new AsyncTokenize(malga, formElementsMock) | ||
|
||
asyncTokenizeObject.handle() | ||
console.log(inputs.length) | ||
}) | ||
}) |
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,26 @@ | ||
import { MalgaFormElements } from 'src/common/interfaces' | ||
|
||
export const formValuesMock = { | ||
holderName: 'Taylor Swift', | ||
number: '5173000265860114', | ||
expirationDate: '05/08/2024', | ||
cvv: '114', | ||
} | ||
|
||
export const handleFormMock = () => { | ||
return { | ||
form: document.createElement('form'), | ||
holderNameInput: document.createElement('input'), | ||
numberInput: document.createElement('input'), | ||
expirationDateInput: document.createElement('input'), | ||
cvvInput: document.createElement('input'), | ||
} | ||
} | ||
|
||
export const formElementsMock: MalgaFormElements = { | ||
form: 'data-malga-tokenization-form', | ||
holderName: 'data-malga-tokenization-holder-name', | ||
number: 'data-malga-tokenization-number', | ||
expirationDate: 'data-malga-tokenization-expiration-date', | ||
cvv: 'data-malga-tokenization-cvv', | ||
} |
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,6 +1,6 @@ | ||
export interface TokenizationPayload { | ||
holderName: string | ||
number: string | ||
expirationDate: string | ||
cvv: string | ||
holderName?: string | ||
number?: string | ||
expirationDate?: string | ||
cvv?: 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { MalgaTokenization } from './tokenization' | ||
|
||
describe('Constructor', () => { | ||
test('should be possible for MalgaTokenizationObject to be an instance of the MalgaTokenization class', () => { | ||
const MalgaConfigurations = { | ||
apiKey: '44829c89-ae91-4271-b347-5024a06a3fc3', | ||
clientId: 'af1f76f7-b461-430e-abac-4f1b010a1629', | ||
options: { | ||
sandbox: true, | ||
}, | ||
} | ||
const MalgaTokenizationObject = new MalgaTokenization(MalgaConfigurations) | ||
|
||
expect(MalgaTokenizationObject).toBeInstanceOf(MalgaTokenization) | ||
}) | ||
}) | ||
|
||
describe('init', () => { | ||
test('ajsjns', () => {}) | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MalgaFormElements } from 'src/common/interfaces' | ||
|
||
export const formValuesMock = { | ||
holderName: 'Taylor Swift', | ||
number: '5173000265860114', | ||
expirationDate: '05/08/2024', | ||
cvv: '114', | ||
} | ||
|
||
export const handleFormMock = () => { | ||
return { | ||
form: document.createElement('form'), | ||
holderNameInput: document.createElement('input'), | ||
numberInput: document.createElement('input'), | ||
expirationDateInput: document.createElement('input'), | ||
cvvInput: document.createElement('input'), | ||
} | ||
} | ||
|
||
export const formElementsMock: MalgaFormElements = { | ||
form: 'data-malga-tokenization-form', | ||
holderName: 'data-malga-tokenization-holder-name', | ||
number: 'data-malga-tokenization-number', | ||
expirationDate: 'data-malga-tokenization-expiration-date', | ||
cvv: 'data-malga-tokenization-cvv', | ||
} | ||
|
||
export const formElementsMock2: MalgaFormElements = { | ||
form: 'data-tokenization-form', | ||
holderName: 'data-tokenization-holder-name', | ||
number: 'data-tokenization-number', | ||
expirationDate: 'data-tokenization-expiration-date', | ||
cvv: 'data-tokenization-cvv', | ||
} |
Oops, something went wrong.