Skip to content

Commit 842d27a

Browse files
authored
feat: add order service tests and jest configuration (#2)
* feat: add order service tests and jest configuration * ci: add GitHub Actions workflow for PR checks * chore: add prettier and fix eslint configuration * add extractKeyFromSecretKey method * ci: add npm publish workflow * Update version * small update
1 parent 7b6c5be commit 842d27a

25 files changed

+4657
-630
lines changed

.eslint.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/npm-publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: NPM Publish
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Use Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: '18.x'
17+
registry-url: 'https://registry.npmjs.org'
18+
19+
- name: Install dependencies
20+
run: npm ci
21+
22+
- name: Build
23+
run: npm run build
24+
25+
- name: Publish to NPM
26+
run: npm publish
27+
env:
28+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/pr-checks.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
types: [opened, synchronize, reopened]
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
node-version: [18.x]
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
18+
- name: Use Node.js ${{ matrix.node-version }}
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Run linter
28+
run: npm run lint
29+
30+
- name: Run tests
31+
run: npm test

.prettierignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
lib
3+
dist
4+
coverage
5+
*.md
6+
package-lock.json

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 100,
6+
"tabWidth": 2,
7+
"endOfLine": "lf"
8+
}

Readme.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
#### Get needed params for checkout initialization:
1212
```typescript
13-
import InlineCheckoutApiSdk from "@xmoney/api-sdk";
13+
import xMoney from "@xmoney/api-sdk";
1414

15-
const inlineCheckout = new InlineCheckoutApiSdk({
16-
secretKey: "mySecretKey",
15+
const xMoneyCheckout = new xMoney({
16+
secretKey: "sk_test_secretKey",
1717
});
1818

19-
const order = inlineCheckout.initializeCheckout({
20-
siteId: 1,
19+
const order = xMoneyCheckout.initializeCheckout({
20+
publicKey: 'pk_test_abc123',
2121
customer: {
2222
identifier: "customerIdentifier",
2323
firstName: "John",
@@ -40,16 +40,16 @@ const order = inlineCheckout.initializeCheckout({
4040

4141
#### How to decrypt order webhook payload:
4242
```typescript
43-
import InlineCheckoutApiSdk from "@xmoney/api-sdk";
43+
import xMoney from "@xmoney/api-sdk";
4444

45-
const inlineCheckout = new InlineCheckoutApiSdk({
46-
secretKey: "mySecretKey",
45+
const xMoneyCheckout = new xMoney({
46+
secretKey: "sk_test_secretKey",
4747
});
4848

4949
const webhookPayload = 'ecryptedPayload';
5050

5151
console.log(
52-
inlineCheckout.decryptOrderResponse(webhookPayload)
52+
xMoneyCheckout.decryptOrderResponse(webhookPayload)
5353
);
5454
```
5555

eslint.config.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
const eslint = require('@eslint/js');
2+
const tseslint = require('@typescript-eslint/eslint-plugin');
3+
const tsparser = require('@typescript-eslint/parser');
4+
const prettier = require('eslint-config-prettier');
5+
6+
module.exports = [
7+
eslint.configs.recommended,
8+
{
9+
files: ['**/*.ts'],
10+
languageOptions: {
11+
parser: tsparser,
12+
parserOptions: {
13+
project: './tsconfig.json',
14+
sourceType: 'module',
15+
},
16+
globals: {
17+
describe: 'readonly',
18+
it: 'readonly',
19+
expect: 'readonly',
20+
beforeEach: 'readonly',
21+
afterEach: 'readonly',
22+
Buffer: 'readonly',
23+
process: 'readonly',
24+
},
25+
},
26+
plugins: {
27+
'@typescript-eslint': tseslint,
28+
},
29+
rules: {
30+
"@typescript-eslint/no-explicit-any": "off",
31+
"@typescript-eslint/no-unused-vars": ["error", {
32+
"varsIgnorePattern": "^[A-Z]",
33+
"argsIgnorePattern": "^_",
34+
'vars': 'all',
35+
'args': 'after-used',
36+
'ignoreRestSiblings': true,
37+
}],
38+
"@typescript-eslint/ban-ts-comment": "off",
39+
"@typescript-eslint/no-empty-function": "off",
40+
"@typescript-eslint/ban-types": "off",
41+
"@typescript-eslint/no-var-requires": "off",
42+
"@typescript-eslint/no-inferrable-types": "off",
43+
"require-await": "error",
44+
"@typescript-eslint/no-floating-promises": "error",
45+
"max-len": "off",
46+
"semi": "off",
47+
"comma-dangle": "off",
48+
"eol-last": "off",
49+
"no-undef": "off", // TypeScript handles this
50+
"no-unused-vars": "off", // Let @typescript-eslint/no-unused-vars handle this
51+
},
52+
},
53+
{
54+
files: ['**/*.enum.ts'],
55+
rules: {
56+
"@typescript-eslint/no-unused-vars": "off",
57+
"no-unused-vars": "off",
58+
},
59+
},
60+
prettier,
61+
];

jest.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node',
4+
roots: ['<rootDir>/src'],
5+
testMatch: ['**/*.spec.ts'],
6+
transform: {
7+
'^.+\\.tsx?$': 'ts-jest',
8+
},
9+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
10+
};

0 commit comments

Comments
 (0)