Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/adityachandak287/unit-testing-demo

Repository for Unit Testing Presentation
https://github.com/adityachandak287/unit-testing-demo

testing unit-testing

Last synced: about 7 hours ago
JSON representation

Repository for Unit Testing Presentation

Awesome Lists containing this project

README

        

# Unit Testing Demo

## Commands

Run tests

```
npm run test
```

Run tests in watch mode

```
npm run test:watch
```

Run tests in watch mode and serve coverage report

```
npm run test-and-serve
```

API documentation

### GET /hello

```json
{ "msg": "Hello World" }
```

### GET /

Get all users

```json
[
{
"id": 1,
"name": "test",
"email": "[email protected]"
}
]
```

### GET /

Get user by id

```json
{
"id": 3,
"name": "test",
"email": "[email protected]"
}

// Error Response if user does not exist
{
"statusCode": 404,
"message": "Not Found"
}
```

### POST /

Create user

```json
// Request Body
{
"name": "John Doe",
"email": "[email protected]"
}

// Response
{
"id": 2,
"name": "John Doe",
"email": "[email protected]"
}

// Error Response
{
"statusCode": 400,
"message": "Bad Request"
}
```

### PATCH /

Create user

```json
// Request Body
{
"name": "John Cena"
}

// Response
{ "success": true }

// Error Response
// If update fails
{
"statusCode": 400,
"message": "Bad Request"
}
// If user does not exist
{
"statusCode": 404,
"message": "Not Found"
}
```

### DELETE /

Delete user by id

```json
// Response
{ "success": true }

// Error Response if user does not exist
{
"statusCode": 404,
"message": "Not Found"
}
```

### POST /pay

Verify if payment in given currency is valid for given amount in INR

```json
// Request Body
{
"amountPaid": 10,
"currency": "USD",
"inrToPay": 500
}

// Response
{ "success": true }

// Error Response
// If currency is not valid
{
"statusCode": 400,
"message": "Invalid currency",
"error": "Bad Request"
}

// If given currency amount converted to INR is not >= inrToPay
{
"statusCode": 400,
"message": "Insufficient amount",
"error": "Bad Request"
}
```

## Credits

- [Currency API](https://github.com/fawazahmed0/currency-api)

## Resources

- [Prisma Docs - Testing](https://www.prisma.io/docs/guides/testing/unit-testing)
- [NestJS Docs - Testing](https://docs.nestjs.com/fundamentals/testing)
- [Jest Docs](https://jestjs.io/docs/28.x/getting-started)