# Testinha

[![npm version](https://img.shields.io/npm/v/testinha.svg?style=flat-square)](https://www.npmjs.org/package/testinha)
[![install size](https://packagephobia.now.sh/badge?p=testinha)](https://packagephobia.now.sh/result?p=testinha)
[![npm downloads](https://img.shields.io/npm/dm/testinha.svg?style=flat-square)](http://npm-stat.com/charts.html?package=testinha)

Routes tester for node.js

> Created by: [Alexandria]("https://alexandria.solar")

---

## Installing

Using npm:
```bash
npm install testinha
```

Using npm as dev dependence:
```bash
npm install testinha --save-dev
```

Using yarn:
```bash
yarn add testinha
```

Using yarn as dev dependence:
```bash
yarn add testinha -D
```

## Dependencies

- [axios](https://github.com/axios/axios)

## How to use it

- Starting an instance of Testinha
  ```javascript
  const test = Testinha("https://google.com", 80);
  ```

- Changing the base url
  ```javascript
  test.changeBaseUrl("https://google.com");
  ```

- Changing the port
  ```javascript
  test.changePort("80");
  ```

- Testing a route
  ```javascript
  test.testOne({
    answer: { error: "No data provided" },
    url: "test",
    method: "GET",
    comparation: "EQUAL",
    params: { data: "no data" }
  }).then(res => console.log(res))
  ```

- Testing many routes
  ```javascript
  test.test([
    {
      answer: { error: "No data provided" },
      url: "test",
      method: "GET",
      comparation: "EQUAL",
      params: { data: "no data" }
    },
    {
      answer: "",
      url: "login",
      method: "POST",
      comparation: "TYPE",
      body: {
        email: "me@gmail.com",
        password: "123",
      },
    },
    {
      answer: {
        user: { name: "string", email: "string", age: "number" },
        access: "string"
      },
      url: "user",
      method: "GET",
      comparation: "INTERFACE",
      params: { email: "me@gmail.com" }
    }
  ])
  ```

## Params explanation

- baseURL:
  - The consistent part of the web address you want to test

- port:
  - The port of the web address you want to test

- answer:
  - The expected answer for the route

- url:
  - The route you want to test

- method:
  - The method used for the route
  - Accepted methods: GET, POST, PUT, DELETE
  - Defaults to: GET

- comparation:
  - The type of comparation between the expected answer and the received answer
  - Accepted comparations: EQUAL, TYPE, INTERFACE
  - Defaults to: EQUAL
  - EQUAL: compares if the answers are exact the same
  - TYPE: compares if the answers are the same type (objects are considered the same no matter theirs keys)
  - INTERFACE: compares if the answer received has the exact same type as the expected answer defined (each objects keys are compared, unless the expected answer is "object")

