-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
20 changed files
with
462 additions
and
453 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
sourceType: 'module' | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin', 'prettier'], | ||
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'prettier/prettier': 'error' // Added this rule to enforce Prettier | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"arrowParens": "avoid", | ||
"bracketSameLine": true, | ||
"bracketSpacing": true, | ||
"singleQuote": true, | ||
"trailingComma": "none", | ||
"semi": false, | ||
"printWidth": 120, | ||
"tabWidth": 2, | ||
"endOfLine": "auto" | ||
} |
Empty file.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 |
---|---|---|
|
@@ -2,120 +2,120 @@ import { | |
TransactionCreateInputIdPay, | ||
TransactionVerifyInputIdPay, | ||
TransactionCreateResponseIdPay, | ||
TransactionVerifyResponseIdPay, | ||
} from "../"; | ||
import axios from "axios"; | ||
import { IdPayDriver } from "../idpay"; | ||
TransactionVerifyResponseIdPay | ||
} from '../' | ||
import axios from 'axios' | ||
import { IdPayDriver } from '../idpay' | ||
|
||
jest.mock("axios"); | ||
jest.mock('axios') | ||
|
||
describe("IdPayDriver", () => { | ||
describe('IdPayDriver', () => { | ||
const createTransactionMockData: TransactionCreateInputIdPay = { | ||
token: "your_token", | ||
order_id: "12345", | ||
token: 'your_token', | ||
order_id: '12345', | ||
amount: 10000, | ||
name: "John Doe", | ||
phone: "09381234567", | ||
mail: "[email protected]", | ||
desc: "Payment for a product", | ||
callback: "https://example.com/callback", | ||
}; | ||
name: 'John Doe', | ||
phone: '09381234567', | ||
mail: '[email protected]', | ||
desc: 'Payment for a product', | ||
callback: 'https://example.com/callback' | ||
} | ||
|
||
const verifyTransactionMockData: TransactionVerifyInputIdPay = { | ||
token: "your_token", | ||
order_id: "12345", | ||
id: "987654", | ||
}; | ||
token: 'your_token', | ||
order_id: '12345', | ||
id: '987654' | ||
} | ||
|
||
const mockData = { | ||
id: "123456", | ||
link: "https://example.com/payment-link", | ||
error_code: "ERR001", | ||
error_message: "Error message", | ||
}; | ||
id: '123456', | ||
link: 'https://example.com/payment-link', | ||
error_code: 'ERR001', | ||
error_message: 'Error message' | ||
} | ||
|
||
const mockAxiosPost = jest.fn(); | ||
const mockAxiosPost = jest.fn() | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
jest.clearAllMocks() | ||
}) | ||
|
||
test("request method - success", async () => { | ||
mockAxiosPost.mockResolvedValue({ data: mockData }); | ||
axios.post = mockAxiosPost; | ||
test('request method - success', async () => { | ||
mockAxiosPost.mockResolvedValue({ data: mockData }) | ||
axios.post = mockAxiosPost | ||
|
||
const idPayDriver = new IdPayDriver(); | ||
const result = await idPayDriver.request(createTransactionMockData); | ||
const idPayDriver = new IdPayDriver() | ||
const result = await idPayDriver.request(createTransactionMockData) | ||
|
||
const expectedResponse: TransactionCreateResponseIdPay = { | ||
isError: false, | ||
data: { | ||
id: mockData.id, | ||
link: mockData.link, | ||
link: mockData.link | ||
}, | ||
error_code: null, | ||
error_message: null, | ||
}; | ||
error_message: null | ||
} | ||
|
||
expect(result).toEqual(expectedResponse); | ||
expect(result).toEqual(expectedResponse) | ||
|
||
expect(mockAxiosPost).toHaveBeenCalledWith( | ||
expect.any(String), | ||
expect.objectContaining(createTransactionMockData), | ||
expect.any(Object), | ||
); | ||
}); | ||
expect.any(Object) | ||
) | ||
}) | ||
|
||
test("request method - error", async () => { | ||
test('request method - error', async () => { | ||
mockAxiosPost.mockRejectedValue({ | ||
isAxiosError: true, | ||
response: { | ||
data: { | ||
error_code: mockData.error_code, | ||
error_message: mockData.error_message, | ||
}, | ||
}, | ||
}); | ||
axios.post = mockAxiosPost; | ||
error_message: mockData.error_message | ||
} | ||
} | ||
}) | ||
axios.post = mockAxiosPost | ||
|
||
const idPayDriver = new IdPayDriver(); | ||
const result = await idPayDriver.request(createTransactionMockData); | ||
const idPayDriver = new IdPayDriver() | ||
const result = await idPayDriver.request(createTransactionMockData) | ||
|
||
const expectedResponse: TransactionCreateResponseIdPay = { | ||
isError: true, | ||
error_code: mockData.error_code, | ||
error_message: mockData.error_message, | ||
data: {} as any, | ||
}; | ||
data: {} as any | ||
} | ||
|
||
expect(result).toEqual(expectedResponse); | ||
}); | ||
expect(result).toEqual(expectedResponse) | ||
}) | ||
|
||
test("verify method - success", async () => { | ||
test('verify method - success', async () => { | ||
const mockVerifyData = { | ||
status: "Success", | ||
track_id: "123456789", | ||
id: "987654321", | ||
order_id: "ORDER12345", | ||
amount: "100.00", | ||
date: "2023-10-29T14:30:00Z", | ||
status: 'Success', | ||
track_id: '123456789', | ||
id: '987654321', | ||
order_id: 'ORDER12345', | ||
amount: '100.00', | ||
date: '2023-10-29T14:30:00Z', | ||
payment: { | ||
track_id: "987654321", | ||
amount: "100.00", | ||
card_no: "**** **** **** 1234", | ||
hashed_card_no: "4b0b192d675b8632c19f989315c78e91", | ||
date: "2023-10-29T14:30:00Z", | ||
track_id: '987654321', | ||
amount: '100.00', | ||
card_no: '**** **** **** 1234', | ||
hashed_card_no: '4b0b192d675b8632c19f989315c78e91', | ||
date: '2023-10-29T14:30:00Z' | ||
}, | ||
verify: { | ||
date: "2023-10-29T14:35:00Z", | ||
}, | ||
}; | ||
date: '2023-10-29T14:35:00Z' | ||
} | ||
} | ||
|
||
mockAxiosPost.mockResolvedValue({ data: mockVerifyData }); | ||
axios.post = mockAxiosPost; | ||
mockAxiosPost.mockResolvedValue({ data: mockVerifyData }) | ||
axios.post = mockAxiosPost | ||
|
||
const idPayDriver = new IdPayDriver(); | ||
const result = await idPayDriver.verify(verifyTransactionMockData); | ||
const idPayDriver = new IdPayDriver() | ||
const result = await idPayDriver.verify(verifyTransactionMockData) | ||
|
||
const expectedResponse: TransactionVerifyResponseIdPay = { | ||
isError: false, | ||
|
@@ -131,47 +131,47 @@ describe("IdPayDriver", () => { | |
amount: mockVerifyData.payment.amount, | ||
card_no: mockVerifyData.payment.card_no, | ||
hashed_card_no: mockVerifyData.payment.hashed_card_no, | ||
date: mockVerifyData.payment.date, | ||
date: mockVerifyData.payment.date | ||
}, | ||
verify: { | ||
date: mockVerifyData.verify.date, | ||
}, | ||
date: mockVerifyData.verify.date | ||
} | ||
}, | ||
error_code: null, | ||
error_message: null, | ||
}; | ||
error_message: null | ||
} | ||
|
||
expect(result).toEqual(expectedResponse); | ||
expect(result).toEqual(expectedResponse) | ||
|
||
expect(mockAxiosPost).toHaveBeenCalledWith( | ||
expect.any(String), | ||
expect.objectContaining(verifyTransactionMockData), | ||
expect.any(Object), | ||
); | ||
}); | ||
expect.any(Object) | ||
) | ||
}) | ||
|
||
test("verify method - error", async () => { | ||
test('verify method - error', async () => { | ||
mockAxiosPost.mockRejectedValue({ | ||
isAxiosError: true, | ||
response: { | ||
data: { | ||
error_code: mockData.error_code, | ||
error_message: mockData.error_message, | ||
}, | ||
}, | ||
}); | ||
axios.post = mockAxiosPost; | ||
error_message: mockData.error_message | ||
} | ||
} | ||
}) | ||
axios.post = mockAxiosPost | ||
|
||
const idPayDriver = new IdPayDriver(); | ||
const result = await idPayDriver.verify(verifyTransactionMockData); | ||
const idPayDriver = new IdPayDriver() | ||
const result = await idPayDriver.verify(verifyTransactionMockData) | ||
|
||
const expectedResponse: TransactionVerifyResponseIdPay = { | ||
isError: true, | ||
error_code: mockData.error_code, | ||
error_message: mockData.error_message, | ||
data: {} as any, | ||
}; | ||
data: {} as any | ||
} | ||
|
||
expect(result).toEqual(expectedResponse); | ||
}); | ||
}); | ||
expect(result).toEqual(expectedResponse) | ||
}) | ||
}) |
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,21 +1,21 @@ | ||
/** | ||
* Enum representing URLs for interacting with the IdPay API. | ||
* | ||
* | ||
* @enum {string} | ||
*/ | ||
export enum IdPayUrls { | ||
/** | ||
* URL for creating a payment request. | ||
* | ||
* | ||
* @type {string} | ||
* @memberof IdPayUrls | ||
*/ | ||
REQUEST = "https://api.idpay.ir/v1.1/payment", | ||
*/ | ||
REQUEST = 'https://api.idpay.ir/v1.1/payment', | ||
/** | ||
* URL for verifying a payment. | ||
* | ||
* | ||
* @type {string} | ||
* @memberof IdPayUrls | ||
*/ | ||
VERIFY = "https://api.idpay.ir/v1.1/payment/verify", | ||
*/ | ||
VERIFY = 'https://api.idpay.ir/v1.1/payment/verify' | ||
} |
Oops, something went wrong.