Spaces:
Sleeping
Sleeping
Delete __tests__
Browse files- __tests__/integration.js +0 -72
- __tests__/unit.js +0 -42
__tests__/integration.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
/**
|
| 2 |
-
* These tests currently only work if you have a local MongoDB database
|
| 3 |
-
*/
|
| 4 |
-
const request = require("supertest");
|
| 5 |
-
const mongoose = require("mongoose");
|
| 6 |
-
const app = require("../app/app");
|
| 7 |
-
const { Thing } = require("../app/models");
|
| 8 |
-
|
| 9 |
-
const exampleThing = {
|
| 10 |
-
name: "Example",
|
| 11 |
-
number: 5,
|
| 12 |
-
stuff: ["cats", "dogs"],
|
| 13 |
-
url: "https://google.com",
|
| 14 |
-
};
|
| 15 |
-
|
| 16 |
-
beforeEach(async () => {
|
| 17 |
-
const testThing = new Thing(exampleThing);
|
| 18 |
-
await testThing.save();
|
| 19 |
-
});
|
| 20 |
-
|
| 21 |
-
afterEach(async () => {
|
| 22 |
-
await mongoose.connection.dropCollection("things");
|
| 23 |
-
});
|
| 24 |
-
|
| 25 |
-
afterAll(async () => {
|
| 26 |
-
await mongoose.disconnect();
|
| 27 |
-
});
|
| 28 |
-
|
| 29 |
-
describe("GET /things", () => {
|
| 30 |
-
test("Get a list of things", async () => {
|
| 31 |
-
let response = await request(app).get("/things");
|
| 32 |
-
expect(response.body).toEqual([exampleThing]);
|
| 33 |
-
});
|
| 34 |
-
});
|
| 35 |
-
|
| 36 |
-
describe("POST /things", () => {
|
| 37 |
-
test("Create a mini new Thing", async () => {
|
| 38 |
-
let response = await request(app).post("/things").send({ name: "A Thing" });
|
| 39 |
-
expect(response.body).toEqual({ name: "A Thing", stuff: [] });
|
| 40 |
-
});
|
| 41 |
-
test("Create a full new Thing", async () => {
|
| 42 |
-
const fullThing = {
|
| 43 |
-
name: "Other Thing",
|
| 44 |
-
stuff: ["cats", "dogs"],
|
| 45 |
-
number: 5,
|
| 46 |
-
url: "http://google.com",
|
| 47 |
-
};
|
| 48 |
-
let response = await request(app).post("/things").send(fullThing);
|
| 49 |
-
expect(response.body).toEqual(fullThing);
|
| 50 |
-
|
| 51 |
-
let duplicateResponse = await request(app)
|
| 52 |
-
.post("/things")
|
| 53 |
-
.send({ name: "Other Thing" });
|
| 54 |
-
expect(duplicateResponse.status).toEqual(409);
|
| 55 |
-
});
|
| 56 |
-
});
|
| 57 |
-
|
| 58 |
-
describe("PATCH /things/:name", () => {
|
| 59 |
-
test("Update a thing's name", async () => {
|
| 60 |
-
let response = await request(app)
|
| 61 |
-
.patch("/things/Example")
|
| 62 |
-
.send({ name: "New Name" });
|
| 63 |
-
expect(response.body).toEqual({ ...exampleThing, name: "New Name" });
|
| 64 |
-
});
|
| 65 |
-
});
|
| 66 |
-
|
| 67 |
-
describe("DELETE /things/:name", () => {
|
| 68 |
-
test("Delete a thing name", async () => {
|
| 69 |
-
let response = await request(app).delete("/things/Example");
|
| 70 |
-
expect(response.body).toEqual(exampleThing);
|
| 71 |
-
});
|
| 72 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__tests__/unit.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
const { APIError, parseSkipLimit } = require("../app/helpers");
|
| 2 |
-
|
| 3 |
-
describe("Helper Functions", () => {
|
| 4 |
-
describe("parseSkipLimit()", () => {
|
| 5 |
-
it("should return a number if a valid limit is passed", () => {
|
| 6 |
-
const limit = "6";
|
| 7 |
-
const validatedLimit = parseSkipLimit(limit);
|
| 8 |
-
expect(validatedLimit).toBe(6);
|
| 9 |
-
});
|
| 10 |
-
it("should return an API Error if a non-numeric limit is passed", () => {
|
| 11 |
-
const limit = "foo";
|
| 12 |
-
const validatedLimit = parseSkipLimit(limit);
|
| 13 |
-
expect(validatedLimit).toBeInstanceOf(APIError);
|
| 14 |
-
});
|
| 15 |
-
it('should return an API Error if zero is passed when type is "limit"', () => {
|
| 16 |
-
const limit = "0";
|
| 17 |
-
const validatedLimit = parseSkipLimit(limit);
|
| 18 |
-
expect(validatedLimit).toBeInstanceOf(APIError);
|
| 19 |
-
});
|
| 20 |
-
it('should return zero if zero is passed when the type is "skip"', () => {
|
| 21 |
-
const skip = "0";
|
| 22 |
-
const validatedLimit = parseSkipLimit(skip, 1000, "skip");
|
| 23 |
-
expect(validatedLimit).toBe(0);
|
| 24 |
-
});
|
| 25 |
-
it("should return an API Error if a negative limit is passed", () => {
|
| 26 |
-
const limit = "-1";
|
| 27 |
-
const validatedLimit = parseSkipLimit(limit);
|
| 28 |
-
expect(validatedLimit).toBeInstanceOf(APIError);
|
| 29 |
-
});
|
| 30 |
-
it("should return an API Error if a limit > max is passed", () => {
|
| 31 |
-
const maximum = 100;
|
| 32 |
-
const limit = "101";
|
| 33 |
-
const validatedLimit = parseSkipLimit(limit, maximum);
|
| 34 |
-
expect(validatedLimit).toBeInstanceOf(APIError);
|
| 35 |
-
});
|
| 36 |
-
it("should return a number if a valid numeric limit is passed", () => {
|
| 37 |
-
const limit = "5";
|
| 38 |
-
const validatedLimit = parseSkipLimit(limit);
|
| 39 |
-
expect(validatedLimit).toBe(5);
|
| 40 |
-
});
|
| 41 |
-
});
|
| 42 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|