Skip to content

Instantly share code, notes, and snippets.

@jonathangaldino
Created January 21, 2020 03:27
Show Gist options
  • Save jonathangaldino/49c0d09e649c5243d85780e83a95d922 to your computer and use it in GitHub Desktop.
Save jonathangaldino/49c0d09e649c5243d85780e83a95d922 to your computer and use it in GitHub Desktop.
Teste da função de criar usuários - exemplos
import supertest from "supertest";
import app from "../../../app";
import { connect, disconnect } from "../../../../test/database";
import {
generateUser,
removeUsers,
removePlates,
generatePlate
} from "../../../../test/helper";
const server = app.callback();
beforeAll(connect);
afterAll(disconnect);
afterAll(removeUsers);
beforeEach(removePlates);
const getToken = async () => {
const user = generateUser();
await supertest(server)
.post("/users")
.send(user);
let response2 = await supertest(server)
.post("/session/signin")
.send({ email: user.email, password: user.password });
const { token } = response2.body;
return token;
}
describe("Plate Create", () => {
test("should create a new plate", async () => {
const token = await getToken();
const plate = generatePlate();
let response3 = await supertest(server)
.post("/plates")
.set("authorization", `Bearer ${token}`)
.send(plate);
expect(response3.status).toBe(201);
});
test("should NOT create a new plate with empty name", async () => {
const token = await getToken();
const plate = generatePlate({ name: undefined });
let response3 = await supertest(server)
.post("/plates")
.set("authorization", `Bearer ${token}`)
.send(plate);
expect(response3.status).toBe(400);
})
test("should NOT create a new plate with empty description", async () => {
const token = await getToken();
const plate = generatePlate({ description: undefined });
let response3 = await supertest(server)
.post("/plates")
.set("authorization", `Bearer ${token}`)
.send(plate);
expect(response3.status).toBe(400);
})
test("should NOT create a new plate with empty price", async () => {
const token = await getToken();
const plate = generatePlate({ price: undefined });
let response3 = await supertest(server)
.post("/plates")
.set("authorization", `Bearer ${token}`)
.send(plate);
expect(response3.status).toBe(400);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment