Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed auth/auth-router.spec.js
Empty file.
88 changes: 69 additions & 19 deletions auth/authRouter.spec.js
Original file line number Diff line number Diff line change
@@ -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);
})
})

});
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);
});
});
});
Binary file modified data/auth.db3
Binary file not shown.
97 changes: 71 additions & 26 deletions posts/postsModel.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
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);
});
});
});