Skip to content

feat: Upgrade to TypeScript, add data types, and mock auth #39

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

Merged
merged 4 commits into from
Jun 6, 2025

Conversation

StanleyMasinde
Copy link
Member

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.

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.
Adds `coverage/` to `.gitignore` to prevent tracking of
locally generated code coverage reports by Vitest.
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.
Adds the `dist/` directory (default TypeScript output)
to `.gitignore` to prevent compiled files from being
committed to the repository.
Copy link
Member Author

@StanleyMasinde StanleyMasinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@StanleyMasinde StanleyMasinde merged commit 567d220 into master Jun 6, 2025
4 checks passed
@StanleyMasinde StanleyMasinde deleted the feat/typescript-upgrade-new-types-mock-auth branch June 6, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant