Skip to content
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

Add unit tests #6

Open
chriscalo opened this issue Mar 31, 2021 · 0 comments
Open

Add unit tests #6

chriscalo opened this issue Mar 31, 2021 · 0 comments
Assignees
Milestone

Comments

@chriscalo
Copy link
Owner

Useful article: How you can test your Node.js applications with Ava.js

import test from 'ava';
const request = require('supertest');
const app = require('./../app.js');


test('check status', async t => {
  const response = await request(app)
    .get('/status');
    t.is(response.status, 200);
    t.deepEqual(response.body, {
      status : 'Ok'
    });
})

test('greet', async t => {
  const name = 'Nitish';
  const food = 'Pizza';
  const response = await request(app)
    .get('/greet')
    .query({name, food});

    t.is(response.status, 200);
    t.is(response.body.message, `hello ${name} would you like a ${food}`);
})


test('Dont send username', async t => {
  const password = 'some-hase'
  const response = await request(app)
    .post('/register')
    .send({password});

    t.is(response.status, 400);
    t.is(response.body.message, `username is missing`);
})


test('Dont send password', async t => {
  const username = 'some-hase'
  const response = await request(app)
    .post('/register')
    .send({username});

    
    t.is(response.status, 400);
    t.is(response.body.message, `password is missing`);
})
@chriscalo chriscalo mentioned this issue Mar 31, 2021
6 tasks
@chriscalo chriscalo self-assigned this Mar 31, 2021
@chriscalo chriscalo added this to the v1 milestone Mar 31, 2021
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

No branches or pull requests

1 participant