Skip to content

Commit 567d220

Browse files
feat: Upgrade to TypeScript, add data types, and mock auth (#39)
* feat: Upgrade to TypeScript, add data types, and mock auth This major update transitions the entire project from JavaScript to TypeScript, enhancing type safety and maintainability. Key changes include: 1. **TypeScript Conversion:** * All source files (`.js` to `.ts`) in `app.js`, `bin/www`, routes, and new modules. * Setup of `tsconfig.json` for strict type checking. * Updated `package.json` scripts for TypeScript compilation (`tsc`). 2. **Dependency Updates & Testing Framework:** * Upgraded dependencies to their latest versions. * Replaced Faker.js with `@faker-js/faker`. * Integrated Vitest as the testing framework, replacing Mocha/Chai. * Converted all existing tests to TypeScript/Vitest and added `supertest` for HTTP request testing. 3. **New Data Types:** * Added `Company`, `Address`, and `Order` data types. * Created interfaces for these types in `src/interfaces/`. * Generated mock data using Faker.js scripts (stored in `src/database/`). * Implemented new Express routes for each data type (GET all, GET by ID). 4. **Mock Authentication:** * Implemented JWT-based mock authentication. * Added `/auth/login` endpoint to issue tokens (mock credential check). * Created a protected `/auth/me` endpoint. * Developed an `authenticateToken` middleware for securing routes. * Defined `JwtPayload` and extended Express Request types. 5. **Testing Enhancements:** * Added comprehensive tests for all new data type routes. * Added detailed tests for the authentication flow (login, token validation, protected route access). * Achieved high test coverage for all new and modified functionalities. 6. **Code Quality and Refinement:** * Ensured strong typing throughout the codebase, minimizing `any`. * Verified successful build and all tests passing post-refinement. This upgrade provides a more robust, well-typed, and feature-rich mock API server suitable for further development and testing purposes. * fix: Add Vitest coverage directory to .gitignore Adds `coverage/` to `.gitignore` to prevent tracking of locally generated code coverage reports by Vitest. * chore: Update Node.js versions in CI workflow I've updated the GitHub Actions CI workflow to use more recent Node.js versions. - I modified the `node-version` matrix to `[20.x, 22.x]`. - I updated `actions/checkout` from `v2` to `v4`. - I updated `actions/setup-node` from `v1` to `v4`. - I enabled npm caching in the `setup-node` step. - I ensured `npm test` is always executed. * fix: Add dist directory to .gitignore Adds the `dist/` directory (default TypeScript output) to `.gitignore` to prevent compiled files from being committed to the repository. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 12b22bb commit 567d220

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+8822
-2125
lines changed

.github/workflows/node.js.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
node-version: [12.x, 14.x, 16.x, 17.x, 18.x, 19.x]
19+
node-version: [20.x, 22.x]
2020

2121
steps:
22-
- uses: actions/checkout@v2
22+
- uses: actions/checkout@v4
2323
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v1
24+
uses: actions/setup-node@v4
2525
with:
2626
node-version: ${{ matrix.node-version }}
27+
cache: 'npm' # Added npm caching
2728
- run: npm ci
2829
- run: npm run build --if-present
29-
- run: npm test --if-present
30+
- run: npm test # Removed --if-present, tests should always run

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
node_modules
1+
node_modules
2+
3+
# Vitest coverage directory
4+
coverage/
5+
6+
# TypeScript output directory
7+
dist/

app.js

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

0 commit comments

Comments
 (0)