Skip to content

Commit

Permalink
chore: ✨ introduce v1.0.0 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
BartekCK committed Jan 24, 2023
2 parents f723673 + d0385d8 commit b47dd92
Show file tree
Hide file tree
Showing 63 changed files with 10,993 additions and 1,855 deletions.
1 change: 1 addition & 0 deletions .db/postgres-config.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE DATABASE test OWNER user123;
10 changes: 10 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DEXCOM_USERNAME=exampleUsername
DEXCOM_PASSWORD=examplePassword
DEXCOM_APPLICATION_ID=d89443d2-327c-4a6f-89e5-496bbb0317db
DEXCOM_USER_LOCATION=EU

DATABASE_HOST=exampleHost
DATABASE_PORT=8080
DATABASE_USER=exampleUser
DATABASE_PASSWORD=examplePassword
DATABASE_NAME=exampleDbName
10 changes: 10 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
DEXCOM_USERNAME=test
DEXCOM_PASSWORD=test
DEXCOM_APPLICATION_ID=d89443d2-327c-4a6f-89e5-496bbb0317db
DEXCOM_USER_LOCATION=EU

DATABASE_HOST=127.0.0.1
DATABASE_PORT=5432
DATABASE_USER=user123
DATABASE_PASSWORD=root
DATABASE_NAME=test
27 changes: 6 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,17 @@
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
],
"overrides": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest"
},
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {
"indent": [
"error",
4
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
"indent": ["error", 4],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"]
},
"ignorePatterns": ["dist", "node_modules"]
}
108 changes: 108 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: App testing

on:
push:
branches: [ "develop", "master" ]
pull_request:
branches: [ "develop", "master" ]

jobs:

test:
services:
postgres:
image: postgres
ports:
- "5432:5432"
env:
POSTGRES_USER: user123
POSTGRES_PASSWORD: root
POSTGRES_DB: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install all dependencies
run: npm ci

- name: Check typescript types
run: npm run check-types

- name: Check lint
run: npm run lint

- name: Run test
run: npm test

- name: Upload coverage reports
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov
test-build-run:
runs-on: ubuntu-latest
env:
DEXCOM_USERNAME: ${{ secrets.DEXCOM_USERNAME }}
DEXCOM_PASSWORD: ${{ secrets.DEXCOM_PASSWORD }}
DEXCOM_APPLICATION_ID: d89443d2-327c-4a6f-89e5-496bbb0317db
DEXCOM_USER_LOCATION: EU
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: user123
DATABASE_PASSWORD: root
DATABASE_NAME: glucose_dev

steps:

- uses: actions/checkout@v3

- name: Install all dependencies
run: npm ci

- name: Install aws-lambda-runtime-interface-emulator
run: |
mkdir -p ~/.aws-lambda-rie && curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && chmod +x ~/.aws-lambda-rie/aws-lambda-rie
- name: Build docker compose
run: |
docker-compose up -d --build
- name: Run migrations for containerised postgres
env:
DATABASE_HOST: localhost
run: |
npm run migrations:latest
- name: Check if image is appropriate for lambda container
run: |
set -e
response=$(curl -i "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"maxCount": 5}')
docker logs cgm-handler-container
echo $response
if echo $response | grep -q "error"; then
echo "Error found in response"
exit 1
else
echo "No errors found in response"
fi
- name: Clear after pipeline
run: |
docker-compose down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
dist/
.idea
.env
.coverage
coverage
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"printWidth": 100,
"printWidth": 90,
"tabWidth": 4
}
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

[![codecov](https://codecov.io/gh/BartekCK/cgm-handler/branch/develop/graph/badge.svg?token=XZC8ABPXDH)](https://codecov.io/gh/BartekCK/cgm-handler)

### TODO:
1. Add contract tests


### Migrations
- Create new migration
```bash
npm run migrations:create ${migration_name}
```


docker-compose --env-file .env.test up
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3'

services:
postgres:
image: postgres
environment:
- POSTGRES_USER=${DATABASE_USER}
- POSTGRES_PASSWORD=${DATABASE_PASSWORD}
- POSTGRES_DB=${DATABASE_NAME}
ports:
- "${DATABASE_PORT}:${DATABASE_PORT}"
volumes:
- ./.db/postgres-config.sql:/docker-entrypoint-initdb.d/postgres-config.sql
healthcheck:
test: pg_isready
interval: 10s
timeout: 5s
retries: 5

cgm-handler:
container_name: cgm-handler-container
build:
context: .
args:
- NODE_ENV=production
ports:
- "9000:8080"
environment:
- DEXCOM_USERNAME=${DEXCOM_USERNAME}
- DEXCOM_PASSWORD=${DEXCOM_PASSWORD}
- DEXCOM_APPLICATION_ID=${DEXCOM_APPLICATION_ID}
- DEXCOM_USER_LOCATION=${DEXCOM_USER_LOCATION}
- DATABASE_HOST=postgres
- DATABASE_PORT=5432
- DATABASE_USER=${DATABASE_USER}
- DATABASE_PASSWORD=${DATABASE_PASSWORD}
- DATABASE_NAME=${DATABASE_NAME}
depends_on:
- postgres

12 changes: 12 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { Config } from 'jest';

const config: Config = {
verbose: true,
preset: 'ts-jest',
testPathIgnorePatterns: ['/node_modules/'],
testMatch: ['**/*.test.ts'],
collectCoverage: true,
coverageDirectory: '.coverage',
};

export default config;
28 changes: 28 additions & 0 deletions knexfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { IDbClientEnvConfig } from './src/infrastructure/database/client/dbClientEnvConfig.inteface';
import { EnvConfig } from './src/infrastructure/envConfig/envConfig';

export default async () => {
const config: IDbClientEnvConfig = await EnvConfig.factory();

const [databasePassword, databasePort, databaseHost, databaseName, databaseUser] = [
config.getDatabasePassword(),
config.getDatabasePort(),
config.getDatabaseHost(),
config.getDatabaseName(),
config.getDatabaseUser(),
];

return {
client: 'pg',
connection: {
host: databaseHost,
port: databasePort,
user: databaseUser,
password: databasePassword,
database: databaseName,
},
migrations: {
directory: './src/infrastructure/database/migrations',
},
};
};
Loading

0 comments on commit b47dd92

Please sign in to comment.