# ywemay-api-test

> API test helper functions

Latest version **0.0.9** (published 2022-07-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install ywemay-api-test
pnpm add ywemay-api-test
yarn add ywemay-api-test
bun add ywemay-api-test
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.9 |
| Published | 2022-07-23 |
| First published | 2022-05-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Cibuc Dorian |
| Maintainers | ywemay |
| Keywords | api, test |

## Links

- npm: https://www.npmjs.com/package/ywemay-api-test
- Repository: https://github.com/ywemay/api-test
- Homepage: https://github.com/ywemay/api-test#readme
- Issues: https://github.com/ywemay/api-test/issues
- npm.io page: https://npm.io/package/ywemay-api-test

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2022-07-23
- 0.0.8 — 2022-07-23
- 0.0.7 — 2022-07-23
- 0.0.6 — 2022-07-23
- 0.0.5 — 2022-07-23
- 0.0.4 — 2022-07-23
- 0.0.3 — 2022-07-23
- 0.0.2 — 2022-05-20
- 0.0.1 — 2022-05-19
- 0.0.0 — 2022-05-19

## README

# YWEmay API Test Helpers

An NPM package uses to simplify writting API testing functions.

## Install

```bash
npm i -D ywemay-api-test
```

## Usage

```js
process.env.NODE_ENV = "test";

const apiTest = require("ywemay-api-test");
const server = require("../server");

const test = apiTest({
  server,
  uriLogIn: "/auth/login",
});

const userAdmin = { username: "admin", password: "password" };

describe("My API endpoint test", () => {
  beforeEach((done) => {
    // connect to db - clear/insert data
    done();
  });

  const ops = {
    credentials: userAdmin,
    uri: "/products",
  };

  test.list("it shall get products list", {
    ...ops,
    check: 200, //if number - check status
  });

  test.list("it shall get products list", {
    // if 'credentials' key omitted - log in/authorization will not be performed
    // as result not token will be sent to the tested route
    uri: "/products",
    check: 200, //if number - check status
  });

  test.get("it shall get products list", {
    ...ops,
    id: "09u09u09au0uf",
    // check: 200, //if check key omitted - default check function will be used
  });

  test.post("it shall post a product", {
    ...ops,
    item: { name: "Headphones", price: 123 },
    // own check function:
    check: (res) => {
      res.should.have.status(200);
      res.body.should.be.a("object");
    },
  });

  test.put("it shall modify a product", {
    ...ops,
    id: "92348029384",
    ops: { price: 231 },
    check: (res) => {
      res.should.have.status(200);
      res.body.should.be.a("object");
    },
  });

  test.delete("it shall delete the product", {
    ...ops,
    id: "92348029384",
    check: 200,
  });
});
```

---
_Source: https://npm.io/package/ywemay-api-test · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
