Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add initial setup for config, GraphQL, Prisma, TypeScript, ESLint and Jest #1

Merged
merged 17 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
6 changes: 4 additions & 2 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
HTTP_PORT=3000
HTTP_PORT=
HTTP_DOMAIN=
HTTP_SCHEME=https
HTTP_SCHEME=

GRAPHQL_INTROSPECTION_ENABLED=
43 changes: 43 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Validate TypeScript & check code formatting

# Triggered when code is pushed to any branch in a repository
on:
push:
workflow_dispatch:

# https://twitter.com/adamchainz/status/1485572084617121796?s=21
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 2

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: "16"
cache: "npm"

- name: Cache node_modules
uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-cache-
theskumar marked this conversation as resolved.
Show resolved Hide resolved

- name: Install Dependencies
run: npm ci # npm ci is a CI environment specific installer https://stackoverflow.com/a/53325242

- name: Validate TypeScript
run: npm run tsc:validate

- name: ESLint
run: npm run lint
27 changes: 0 additions & 27 deletions .github/workflows/lint.yml

This file was deleted.

21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:16 as base

WORKDIR /var/app

COPY package*.json ./

RUN npm install

COPY . .

# Generate the prisma client in the docker OS
RUN npx prisma generate

# Production step

FROM base as production

ENV NODE_PATH=./dist
RUN npm run build

ENTRYPOINT [ "nodemon", "/var/app/src/server.ts" ]
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# [Sample Project]
# Fueled Assignment

[@TODO: add project description here]
This repo contains the starter code for Fueled Assignment in NodeJS + TypeScript. Using Postgres as the primary database.

## Requirements

Expand All @@ -19,9 +19,45 @@

## Get Started

The following will install all necessary packages and run the app under development mode which uses `nodemon` for reloading the build when changes are made.

```
npm install
npm run start
npm run dev
```

## Docker Local

A Dockerfile is available to run the backend services in a container exposed through ports. The Docker container
includes the hot reloading Node application, PostgresSQL database, and Redis for caching.

The three services are available under the following:

```
app: fueled_assignment
fueled_assignment_app // Node application
fueled_assignment_redis // Redis server
fueled_assignment_postgres // PostgreSQL database
```

To build and run the Docker container, ensure you have the Docker CLI available, and optionally Docker Desktop.

To build the Docker container:

```
docker compose build
```

To start the Docker container:

```
docker compose up
```

To stop the Docker container:

```
docker compose down
```

## ESLint
Expand All @@ -44,3 +80,4 @@ npm run lint // runs only ESLint
Notice that ESLint is not a part of the main watch task.

If you are interested in seeing ESLint feedback as soon as possible, I strongly recommend the [VS Code ESLint extension](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).

29 changes: 29 additions & 0 deletions __tests__/stripe.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as StripeService from "../src/services/stripe.service";
theskumar marked this conversation as resolved.
Show resolved Hide resolved

const mockedPaymentIntentsCreate = jest.fn((payload) => ({
id: "pi_1234",
...payload,
}));

jest.mock("stripe", () => {
const paymentIntents = jest.fn();
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
paymentIntents.create = (...args) => mockedPaymentIntentsCreate(...args);
return jest.fn().mockImplementation(() => ({ paymentIntents }));
});

describe("Stripe Service", () => {
afterAll(() => {
jest.resetAllMocks();
});

it("should create a capture payment intent set to manual", async () => {
const paymentIntent = await StripeService.createCapturePaymentIntent(100, "usd");

expect(paymentIntent.id).toBe("pi_1234");
expect(paymentIntent.amount).toBe(100);
expect(paymentIntent.currency).toBe("usd");
expect(paymentIntent.capture_method).toBe("manual");
});
});
32 changes: 32 additions & 0 deletions codegen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
schema: ./src/schema.graphql
hooks:
afterAllFileWrite:
- prettier --write
generates:
./src/resolvers-types.ts:
config:
useIndexSignature: true
mapperTypeSuffix: Model
enumValues:
HandoffType: "@prisma/client/index.d#HandoffType"
LabelType: "@prisma/client/index.d#LabelType"
MembershipBillingInterval: "@prisma/client/index.d#MembershipBillingInterval"
OrderStatus: "@prisma/client/index.d#OrderStatus"
PaymentStatus: "@prisma/client/index.d#PaymentStatus"
PickupStatus: "@prisma/client/index.d#PickupStatus"
PickupPackageStatus: "@prisma/client/index.d#PickupPackageStatus"
UserMembershipStatus: "@prisma/client/index.d#UserMembershipStatus"
theskumar marked this conversation as resolved.
Show resolved Hide resolved
mappers:
MembershipPackage: "@prisma/client/index.d#MembershipPackage"
PackagePricing: "@prisma/client/index.d#PackagePricing"
Pickup: "@prisma/client/index.d#Pickup"
PickupPackage: "@prisma/client/index.d#PickupPackage"
Region: "@prisma/client/index.d#Region"
RegionPickupAvailability: "@prisma/client/index.d#RegionPickupAvailability"
User: "@prisma/client/index.d#User"
UserMembership: "@prisma/client/index.d#UserMembership"
plugins:
- add:
content: "/* eslint-disable */" # https://github.com/dotansimha/graphql-code-generator/issues/4120
- typescript
- typescript-resolvers
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3.9"

services:
db:
container_name: fueled_assignment_postgres
theskumar marked this conversation as resolved.
Show resolved Hide resolved
image: postgres
volumes:
- ./data/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=fueled-assignment-db
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"

web:
container_name: fueled_assignment_app
build:
context: .
dockerfile: Dockerfile
target: base
volumes:
- ".:/var/app"
expose:
- "8000"
ports:
- "8000:8000"
depends_on:
- db
environment:
- DATABASE_URL=postgres://postgres:postgres@db/fueled-assignment-db
command: npm run dev

redis:
container_name: fueled_assignment_redis
image: redis:latest
Loading