Skip to content

Commit

Permalink
add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
sajjadmrx committed Jul 4, 2024
1 parent b04e6b9 commit 2a0e642
Show file tree
Hide file tree
Showing 20 changed files with 462 additions and 453 deletions.
23 changes: 23 additions & 0 deletions .eslintrc.js
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
}
}
11 changes: 11 additions & 0 deletions .prettierrc
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 removed .prettierrc.json
Empty file.
8 changes: 5 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,19 @@
"lint": "eslint . --ext .ts",
"test:unit": "jest",
"build": "tsup && npm run doc",
"doc": "jsdoc -c jsdoc.json"
"doc": "jsdoc -c jsdoc.json",
"format": "prettier --write \"./src/**/*.ts\""
},
"author": "sajjadmrx",
"license": "ISC",
"devDependencies": {
"@types/jest": "^29.5.6",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"better-docs": "^2.7.3",
"clean-jsdoc-theme": "^4.2.17",
"eslint": "^8.52.0",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"eslint": "^8.42.0",
"prettier": "^3.0.0",
"jest": "^29.7.0",
"jsdoc": "^4.0.2",
"jsdoc-plugin-typescript": "^2.2.1",
Expand Down
182 changes: 91 additions & 91 deletions src/drivers/idpay/__tests__/idPayDriver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
})
})
14 changes: 7 additions & 7 deletions src/drivers/idpay/enums/urls.enum.ts
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'
}
Loading

0 comments on commit 2a0e642

Please sign in to comment.