Skip to content

Commit baa2c50

Browse files
authored
Merge pull request #14 from davidsilva/chore/readme-and-clean-up
Chore/readme and clean up
2 parents bdb8ece + 82eb6ab commit baa2c50

37 files changed

+308
-240
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,23 @@ jobs:
7070
working-directory: ./backend
7171
run: npm install
7272

73-
- name: Run backend tests
73+
# Run integration tests separately to avoid db conflicts
74+
- name: Run backend integration tests for users
7475
working-directory: ./backend
7576
env:
7677
DATABASE_URL: postgres://postgres:postgres@localhost:5432/testdb
77-
run: npm test
78+
run: npm test -- src/__tests__/integration/users.integration.test.ts
79+
80+
- name: Run backend integration tests for products
81+
working-directory: ./backend
82+
env:
83+
DATABASE_URL: postgres://postgres:postgres@localhost:5432/testdb
84+
run: npm test -- src/__tests__/integration/products.integration.test.ts
85+
86+
# Unit tests can be run together
87+
- name: Run backend unit tests
88+
working-directory: ./backend
89+
run: npm test -- src/__tests__/unit
7890

7991
- name: Install dependencies for frontend
8092
working-directory: ./frontend

README.md

Lines changed: 131 additions & 25 deletions
Large diffs are not rendered by default.

backend/Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stage 1: Build the Node.js application
22
FROM node:20 AS build
33

4-
WORKDIR /app
4+
WORKDIR /app/backend
55

66
COPY package.json ./
77

@@ -14,15 +14,18 @@ RUN npm run build
1414
# Stage 2: Prepare to serve the application
1515
FROM node:20-alpine
1616

17-
WORKDIR /app
17+
WORKDIR /app/backend
1818

19-
COPY --from=build /app/dist /app/dist
20-
COPY --from=build /app/package.json /app/package.json
21-
22-
# Exclude devDependencies
23-
RUN npm install --only=production
19+
COPY --from=build /app/backend/dist /app/backend/dist
20+
COPY --from=build /app/backend/package.json /app/backend/package.json
21+
COPY --from=build /app/backend/src /app/backend/src
22+
COPY --from=build /app/backend/jest.config.ts /app/backend/jest.config.ts
23+
COPY --from=build /app/backend/tsconfig.json /app/backend/tsconfig.json
24+
COPY --from=build /app/backend/migrations /app/backend/migrations
25+
COPY --from=build /app/backend/seeds /app/backend/seeds
26+
RUN npm install
2427

25-
ENV DEBUG=* NPM_CONFIG_LOGLEVEL=verbose
28+
# ENV DEBUG=* NPM_CONFIG_LOGLEVEL=error
2629

2730
EXPOSE 3000
2831

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { Knex } from "knex";
2+
3+
4+
export async function up(knex: Knex): Promise<void> {
5+
return knex.schema.table('users', (table) => {
6+
table.string('street_address').nullable();
7+
});
8+
}
9+
10+
11+
export async function down(knex: Knex): Promise<void> {
12+
return knex.schema.table('users', (table) => {
13+
table.dropColumn('street_address');
14+
});
15+
}
16+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type { Knex } from "knex";
2+
3+
4+
export async function up(knex: Knex): Promise<void> {
5+
return knex.schema.table('products', (table) => {
6+
table.integer('quantity').notNullable().defaultTo(0);
7+
});
8+
}
9+
10+
11+
export async function down(knex: Knex): Promise<void> {
12+
return knex.schema.table('products', (table) => {
13+
table.dropColumn('quantity');
14+
});
15+
}

backend/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "interview-prep-backend",
3-
"version": "0.0.0",
3+
"version": "0.1.0",
44
"main": "dist/server.js",
55
"scripts": {
66
"start": "node dist/server.js",

backend/src/__tests__/integration/products.integration.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import request from 'supertest';
22
import app from '../../app';
33
import knex from 'knex';
44
import knexConfig from '../../knexFile';
5-
import dotenv from 'dotenv';
65
import {
76
Product,
87
ProductStatus,
98
} from '@onyxdevtutorials/interview-prep-shared';
109
import retry from "retry";
1110

12-
dotenv.config({ path: '../../../.env.test' });
13-
1411
const db = knex(knexConfig['test_products']);
1512

1613
const productsPath = '/api/v0/products';

backend/src/__tests__/integration/users.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import request from 'supertest';
22
import app from '../../app';
33
import knex from 'knex';
44
import knexConfig from '../../knexFile';
5-
import dotenv from 'dotenv';
5+
// import dotenv from 'dotenv';
66
import { User, UserStatus } from '@onyxdevtutorials/interview-prep-shared';
77
import retry from "retry";
88

9-
dotenv.config({ path: '../../../.env.test' });
9+
// dotenv.config({ path: '../../../.env.test' });
1010

1111
const db = knex(knexConfig['test_users']);
1212

backend/src/__tests__/server.test.ts renamed to backend/src/__tests__/unit/server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import request from 'supertest';
2-
import app from '../app';
2+
import app from '../../app';
33
import http from 'http';
44

55
describe('Server', () => {

0 commit comments

Comments
 (0)