Skip to content

Commit

Permalink
Merge pull request #15 from amandastecz/tests/implementation
Browse files Browse the repository at this point in the history
Tests/implementation
  • Loading branch information
amandastecz committed Aug 25, 2023
2 parents f30d8cc + 509d8a8 commit 953bcdf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 25 deletions.
68 changes: 48 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
## Wiki
[For more information, check the project's wiki.](https://github.com/amandastecz/rentapi/wiki/)
## Project Overview

## API Documentation
Welcome to the RentAPI repository! This project is part of a series of personal studies on Node.js, aimed at showcasing a range of advanced concepts and practical applications. The RentAPI is developed with TypeScript, adhering to the foundational principles of Clean Architecture and S.O.L.I.D. The project encompasses REST API design, file handling via streams, communication with PostgreSQL databases using TypeORM, injectable containers, JWT authentication with refresh tokens, and meticulous API documentation with Swagger. The application is fortified with automated tests, spanning both unit and integration levels, seamlessly integrated with the Jest Framework.

[Check the API documentation on Swagger UI](http://18.231.189.148/api-docs/)

## NodeJs - Rent API
## Technical specification

This project is part of a series of personal studies on Node.js. This project is being developed with Typescript, applying principles of Clean Architecture and S.O.L.I.D, API Rest, import and reading of files in stream, communication with PostgreSQL database through TypeORM, containerization with Docker, refresh token with JWT authentication, in addition to all the API documentation with Swagger and automated tests at unit and integration level with Jest Framework.
- **Design**: Guided by Clean Architecture, Clean Code, Test Patterns, and S.O.L.I.D principles.
- **Architecture**: Powered by Express, Node.js, and TypeScript. Communicates seamlessly with PostgreSQL using TypeORM. Utilizes Jsonwebtoken for authentication and Nodemailer for efficient email communication.
- **Documentation Framework**: Swagger ensures clear API documentation.
- **Testing Frameworks**: Embraces Jest and Supertest for comprehensive testing.
- **Infrastructure**: Seamlessly integrates with AWS services like EC2, S3, and SES. Simplifies deployment through Docker.
- **CI/CD**: GitHub Actions streamline the development workflow.
- **Security Measures**: Rate-limiter-flexible and Redis enhance security and data management.

### SOLID - Robert C. Martin (Uncle Bob) - Applied Principles
- [X] S: SRP: Single Responsibility Principle - Single responsibility (separation by context)
- [X] L: LSP: Liskov Substitution Principle - Liskov Substitution Principle, talks about using contracts (class implementing interfaces)!
- [X] D: DIP: Dependency Inversion Principle - Dependency Inversion Principle, also means that what is at a high level does not need to know what is at a low level, that is, services do not need to know the repository, the responsibility passes for who calls the service
For deeper insights, delve into the [project's wiki](https://github.com/amandastecz/rentapi/wiki/).

### Docker
- To run the application image: `docker-compose up`
# Running the RentAPI project locally

- up: Creates the container
- down: Removes the container
- start: Starts the container
- stop: Stops the container
Follow these steps to get the RentAPI project up and running on your local machine:

### Migrations
- To create a migration run: `yarn run typeorm migration:create -n CreateCategories`
- To run the migration run: `yarn run typeorm migration:run`
### 1. Install Dependencies

### Seeds
- To create an admin user, run: `yarn run seed:admin`
Open a terminal and navigate to the project's root directory. Run the following command to install all required dependencies:

```bash
yarn
```

### 2. Set Up Database and Caching

Run the following command to create the PostgreSQL database and Redis images necessary for the project:

```bash
docker-compose up
```

### 3. Run Migrations
After setting up the database, execute the following command to run all migrations and set up the database schema:

```bash
yarn run typeorm migration:run
```

### 4. Populate Database
Populate the database with an admin user by running the following command:
```bash
yarn run seed:admin
```
This step ensures that you have initial data for testing and development.
### 5. Start the Server
To start the server and launch the application, use the following command:
```bash
yarn dev
```

With these steps completed, you'll have the RentAPI project running on your localhost, ready for exploration, testing, and development. Feel free to dive into the codebase and API documentation.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "babel src --extensions \".js,.ts\" --out-dir dist --copy-files",
"dev": "ts-node-dev --inspect=0.0.0.0 --transpile-only --ignore-watch node_modules --respawn src/shared/infra/http/server.ts",
"typeorm": "ts-node-dev ./node_modules/typeorm/cli",
"test": "cross-env NODE_ENV=test jest --detectOpenHandles --runInBand",
"test": "cross-env NODE_ENV=test jest --detectOpenHandles --runInBand --forceExit",
"test:ci": "cross-env jest --detectOpenHandles --runInBand",
"seed:admin": "ts-node-dev src/shared/infra/typeorm/seed/admin.ts"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ describe("Create Category Controller", () => {
password: "123456"
});

const { refresh_token} = responseToken.body;
const { token} = responseToken.body;

const response = await request(app).post("/categories")
.send({
"name": "Category Supertest",
"description": "integration test"
}).set({
Authorization: `Bearer ${refresh_token}`,
Authorization: `Bearer ${token}`,
});

expect(response.status).toBe(201);
Expand All @@ -54,14 +54,14 @@ describe("Create Category Controller", () => {
password: "123456"
});

const { refresh_token} = responseToken.body;
const { token } = responseToken.body;

const response = await request(app).post("/categories")
.send({
"name": "Category Supertest",
"description": "integration test"
}).set({
Authorization: `Bearer ${refresh_token}`,
Authorization: `Bearer ${token }`,
});

expect(response.status).toBe(400);
Expand Down

0 comments on commit 953bcdf

Please sign in to comment.