{"size": 1289, "ext": "js", "max_stars_repo_path": "tests/integration/user/remove.test.js", "max_stars_repo_name": "HigorAnjos/backend-phonebook", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "tests/integration/user/remove.test.js", "max_issues_repo_name": "HigorAnjos/backend-phonebook", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "tests/integration/user/remove.test.js", "max_forks_repo_name": "HigorAnjos/backend-phonebook", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 28.0217391304, "max_line_length": 107, "alphanum_fraction": 0.65321955}
const supertest = require("supertest");
const shell = require('shelljs');
const server = require("../../../server");
const request = supertest(server);
require("dotenv").config();

const { sequelize: sequelizeCli } = require('../assets/constants');

shell.exec([
  sequelizeCli.drop,
  sequelizeCli.create,
  sequelizeCli.migrate,
  sequelizeCli.seed
].join(' && '),
  { silent: process.env.DEBUG === "false" });

describe('Rota user Delete', () => {

  it('E possivel deletar um usuario com sucesso e apos deletado nao deve ser possivel logar', async () => {

    const userLogin = {
      email: 'george@gmail.com',
      password: '1234',
    };

    const { body: { token } } = await request.post('/user').send(userLogin);

    const response = await request.delete('/user/delete/').set('authorization', token);

    expect(response.status).toBe(200);
    expect(response.body).toHaveProperty('message');
    expect(response.body.message).toBe('Usuário removido com sucesso');

    const userDeleted = {
      email: 'george@gmail.com',
      password: '1234',
    };

    const res = await request.post('/user').send(userDeleted);

    expect(res.status).toBe(400);
    expect(res.body).toHaveProperty('error');
    expect(res.body.error).toBe('Senha ou email incorretos');
  });
});
