diff --git a/auth/auth-router.spec.js b/auth/auth-router.spec.js deleted file mode 100644 index e69de29..0000000 diff --git a/auth/authRouter.spec.js b/auth/authRouter.spec.js index f1ac1a6..ae5b3b0 100644 --- a/auth/authRouter.spec.js +++ b/auth/authRouter.spec.js @@ -1,23 +1,73 @@ -const request = require('supertest'); - -const server = require('../api/server'); +const request = require("supertest"); +const server = require("../api/server"); +const newUser = { + name: "name1", + email: "email@blah.com", + username: "username9", + password: "test1", + bio: "I am a human person" +}; const user = { - name: "name1", - email: "email@blah.com", - username: "username1", - password: "test1", - bio: "I am a human person" -} - -describe('POST /', function (){ - it('it should register a new user', function () { - return request(server).post('/api/auth/register').send(user) - .then(res => { - expect(res.status).toBe(201); - }) -}) - -}); \ No newline at end of file + name: "name1", + email: "email@blah.com", + username: "username4", + password: "test1", + bio: "I am a human person" +}; + +describe("POST /", function() { + it("it should register a new user", function() { + return request(server) + .post("/api/auth/register") + .send(newUser) + .then(res => { + expect(res.status).toBe(201); + }); + }); +}); + +describe("POST /", function() { + it("it display correct error code (500)", function() { + return request(server) + .post("/api/auth/register") + .send(user) + .then(res => { + expect(res.status).toBe(500); + }); + }); +}); + +const loginUser = { + username: "username2", + password: "test1" +}; + +describe("POST /", function() { + it("should login registered user", function() { + return request(server) + .post("/api/auth/login") + .send(loginUser) + .then(res => { + expect(res.status).toBe(200); + }); + }); +}); + +const loginFakeUser = { + username: "username40", + password: "test1" +}; + +describe("POST /", function() { + it("should reject unregistered user", function() { + return request(server) + .post("/api/auth/login") + .send(loginFakeUser) + .then(res => { + expect(res.status).toBe(401); + }); + }); +}); diff --git a/data/auth.db3 b/data/auth.db3 index 94f0317..411cb06 100644 Binary files a/data/auth.db3 and b/data/auth.db3 differ diff --git a/posts/postsModel.spec.js b/posts/postsModel.spec.js index aac2ebe..5cb4438 100644 --- a/posts/postsModel.spec.js +++ b/posts/postsModel.spec.js @@ -1,31 +1,76 @@ -const request = require('supertest'); +const request = require("supertest"); -const server =require('../api/server'); +const server = require("../api/server"); +describe("GET /", function() { + it("should return all posts", function() { + return request(server) + .get("/api/posts") + .then(res => { + expect(res.status).toBe(201); + }); + }); +}); -describe('GET /', function() { - it('should return all posts', function() { - return request(server).get('/api/posts') - .then(res => { - expect(res.status).toBe(201) - }) - }) -}) +const post = { + title: "picture of thing2", + photo: "https://source.unsplash.com/random", + story: "this is a story", + details: "here are some details", + traveler_id: 1 +}; +describe("Post /", function() { + it("should add a new post", function() { + return request(server) + .post("/api/posts") + .send(post) + .then(res => { + expect(res.status).toBe(200); + }); + }); +}); -const post = { - title: "picture of thing2", - photo: "https://source.unsplash.com/random", - story: "this is a story", - details: "here are some details", - traveler_id: 1 -} - -describe('Post /', function() { - it('should add a new post', function() { - return request(server).post('/api/posts').send(post) - .then(res => { - expect(res.status).toBe(200) - }) - }) -}) \ No newline at end of file +describe("DELETE /:id", function() { + it("should delete post", function() { + return request(server) + .delete("/api/posts/2") + .send(post) + .then(res => { + expect(res.status).toBe(200); + }); + }); +}); + +describe("DELETE /:id", function() { + it("Should return 404 while attempting to delete a nonexsistent post", function() { + return request(server) + .delete("/api/posts/1") + .send(post) + .then(res => { + expect(res.status).toBe(404); + }); + }); +}); + +describe("PUT /:id", function() { + it("should update post", function() { + return request(server) + .put("/api/posts/11") + .send(post) + .then(res => { + expect(res.status).toBe(200); + }); + }); +}); + +describe("PUT /:id", function() { + it("should fail to update post and return 200", function() { + return request(server) + .put("/api/posts/100") + .send(post) + .then(res => { + expect(res.status).toBe(200); + }); + }); +});