Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ PLAYGROUND_ENABLE=false
# AMQP URL
AMQP_URL=amqp://guest:guest@rabbitmq

# Billing settings
BILLING_DEBUG=true
BILLING_COMPANY_EMAIL="[email protected]"

### Accounting module ###
# Accounting service URL
# CODEX_ACCOUNTING_URL=http://accounting:3999/graphql

# Files with certs
TLS_CA_CERT=
TLS_CERT=
TLS_KEY=

## GitHub OAuth app client ID
GITHUB_CLIENT_ID=fakedata

Expand All @@ -51,6 +64,18 @@ HAWK_CATCHER_TOKEN=
## Telegram bot url to send log messages
TELEGRAM_MAIN_CHAT_URL=

## Telegam bot url for operations with money
TELEGRAM_MONEY_CHAT_URL=

# Cloudpayments public id
CLOUDPAYMENTS_PUBLIC_ID=test_api_00000000000000000000001

# Cloudpayments secret string
CLOUDPAYMENTS_SECRET=

# INN of legal entity for CloudKassir
LEGAL_ENTITY_INN=

# Token for Amplitude analytics
AMPLITUDE_TOKEN=

Expand Down
6 changes: 3 additions & 3 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ SMTP_SENDER_NAME=
SMTP_SENDER_ADDRESS=

# AMQP URL
AMQP_URL=
AMQP_URL=amqp://guest:guest@rabbitmq:5672/

# Billing settings
BILLING_DEBUG=true
BILLING_COMPANY_EMAIL="[email protected]"

### Accounting module ###
# Accounting service URL
CODEX_ACCOUNTING_URL=
# CODEX_ACCOUNTING_URL=

# Enable or disable tls verify
TLS_VERIFY=true
Expand Down Expand Up @@ -100,4 +100,4 @@ AWS_S3_ACCESS_KEY_ID=
AWS_S3_SECRET_ACCESS_KEY=
AWS_S3_BUCKET_NAME=
AWS_S3_BUCKET_BASE_URL=
AWS_S3_BUCKET_ENDPOINT=
AWS_S3_BUCKET_ENDPOINT=
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ module.exports = {
env: {
'node': true,
'jest': true
},
rules: {
'@typescript-eslint/camelcase': 'warn',
'@typescript-eslint/no-unused-vars': 'warn',
'@typescript-eslint/explicit-function-return-type': 'warn',
'require-jsdoc': 'warn',
'no-shadow': 'warn',
'no-unused-expressions': 'warn'
}
};
4 changes: 2 additions & 2 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ jobs:
- uses: actions/checkout@v2

# Setup node environment
- uses: actions/setup-node@v1
- uses: actions/setup-node@v3
with:
node-version: 15
node-version-file: '.nvmrc'
registry-url: https://registry.npmjs.org/

# Bump version to the next prerelease (patch) with rc suffix
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Run integration tests on push

on:
- push

jobs:
tests:
name: Run integration tests
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Run tests
run: yarn test:integration
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 12.x
uses: actions/setup-node@v1
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 12.x
node-version-file: '.nvmrc'
- run: yarn install
- run: yarn lint-test
63 changes: 63 additions & 0 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
version: "3.4"
services:
api:
build:
dockerfile: "./docker/Dockerfile.dev"
context: .
user: "node"
env_file:
- ./test/integration/api.env
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules
- ./test/integration/api.env:/usr/src/app/.env
depends_on:
- mongodb
- rabbitmq
# - accounting
stdin_open: true
tty: true

mongodb:
image: mongo:4.2.13
volumes:
- mongodata-test:/data/db

tests:
build:
dockerfile: "./docker/Dockerfile.dev"
context: .
depends_on:
rabbitmq:
condition: service_healthy
api:
condition: service_started
command: dockerize -wait http://api:4000/.well-known/apollo/server-health -timeout 30s yarn jest --config=./test/integration/jest.config.js --runInBand test/integration
volumes:
- ./:/usr/src/app
- /usr/src/app/node_modules

rabbitmq:
image: rabbitmq:3-management
ports:
- 15672:15672
- 5672:5672
volumes:
- ./test/integration/rabbit.definitions.json:/tmp/rabbit.definitions.json:ro
environment:
- RABBITMQ_SERVER_ADDITIONAL_ERL_ARGS=-rabbitmq_management load_definitions "/tmp/rabbit.definitions.json"
healthcheck:
test: ["CMD-SHELL", "rabbitmqctl status || exit 1"]
interval: 5s
timeout: 3s
retries: 5

# accounting:
# image: codexteamuser/codex-accounting:prod
# env_file:
# - ./test/integration/accounting.env
# volumes:
# - ./test/integration/accounting.env:/usr/src/app/.env

volumes:
mongodata-test:
45 changes: 45 additions & 0 deletions migrations/20241110143438-add-monthlyChargeCurrency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module.exports = {
async up(db, client) {
/**
* Use one transaction for all requests
*/
const session = client.startSession();

try {
await session.withTransaction(async () => {
const plansCollection = db.collection('plans');

await plansCollection.updateMany(
{},
{ $set: { monthlyChargeCurrency: 'RUB' } } // Set the default value for monthlyChargeCurrency
);
});

} finally {
await session.endSession();
}
},

async down(db, client) {
/**
* Use one transaction for all requests
*/
const session = client.startSession();

try {

await session.withTransaction(async () => {
const plansCollection = db.collection('plans');

await plansCollection.updateMany(
{},
{ $unset: { monthlyChargeCurrency: "" } } // Remove the monthlyChargeCurrency field
);

});

} finally {
await session.endSession();
}
}
};
44 changes: 44 additions & 0 deletions migrations/20241110161019-add-businessOperations-currency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module.exports = {
async up(db, client) {
/**
* Use one transaction for all requests
*/
const session = client.startSession();

try {
await session.withTransaction(async () => {
const businessOperationsCollection = db.collection('businessOperations');

await businessOperationsCollection.updateMany(
{},
{ $set: { 'payload.currency': 'RUB' } } // Set the default value for payload.currency
);
});

} finally {
await session.endSession();
}
},

async down(db, client) {
/**
* Use one transaction for all requests
*/
const session = client.startSession();

try {

await session.withTransaction(async () => {
const businessOperationsCollection = db.collection('businessOperations');

await businessOperationsCollection.updateMany(
{},
{ $unset: { 'payload.businessOperations': "" } } // Remove the businessOperations field
);
});

} finally {
await session.endSession();
}
}
};
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawk.api",
"version": "1.0.23",
"version": "1.1.1",
"main": "index.ts",
"license": "UNLICENSED",
"scripts": {
Expand All @@ -14,14 +14,18 @@
"migrations:create": "docker-compose exec api yarn migrate-mongo create",
"migrations:up": "docker-compose exec api yarn migrate-mongo up",
"migrations:down": "docker-compose exec api yarn migrate-mongo down",
"test": "jest --coverage"
"test": "jest --coverage",
"test:integration": "docker compose -f docker-compose.test.yml up --build --exit-code-from tests tests",
"test:integration:down": "docker compose -f docker-compose.test.yml down --volumes"
},
"devDependencies": {
"@shelf/jest-mongodb": "^1.2.2",
"@types/jest": "^26.0.8",
"eslint": "^6.7.2",
"eslint-config-codex": "1.2.4",
"eslint-plugin-import": "^2.19.1",
"jest": "^26.2.2",
"mongodb-memory-server": "^6.6.1",
"nodemon": "^2.0.2",
"ts-jest": "^26.1.4",
"ts-node": "^10.9.1",
Expand All @@ -33,7 +37,7 @@
"@graphql-tools/schema": "^8.5.1",
"@graphql-tools/utils": "^8.9.0",
"@hawk.so/nodejs": "^3.1.1",
"@hawk.so/types": "^0.1.18",
"@hawk.so/types": "^0.1.21",
"@types/amqp-connection-manager": "^2.0.4",
"@types/bson": "^4.0.5",
"@types/debug": "^4.1.5",
Expand All @@ -53,6 +57,8 @@
"axios": "^0.27.2",
"body-parser": "^1.19.0",
"bson": "^4.6.5",
"cloudpayments": "^6.0.1",
"codex-accounting-sdk": "https://github.com/codex-team/codex-accounting-sdk.git",
"dataloader": "^2.0.0",
"dotenv": "^16.0.1",
"escape-html": "^1.0.3",
Expand Down
Loading
Loading