Skip to content

Commit

Permalink
Update with part three resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Orie Chinedu committed Aug 24, 2019
1 parent d03c7e7 commit d5987eb
Show file tree
Hide file tree
Showing 4 changed files with 2,271 additions and 34 deletions.
18 changes: 16 additions & 2 deletions package.json
Expand Up @@ -5,7 +5,18 @@
"author": "orie chinedu",
"license": "MIT",
"scripts": {
"start-dev": "nodemon index.js"
"start-dev": "nodemon index.js",
"migrate": "npx sequelize-cli db:migrate",
"test": "cross-env NODE_ENV=test jest --testTimeout=10000",
"migrate:reset": "npx sequelize-cli db:migrate:undo:all && npm run migrate",
"pretest": "cross-env NODE_ENV=test npm run migrate:reset"
},
"jest": {
"testEnvironment": "node",
"coveragePathIgnorePatterns": [
"/node_modules/"
],
"verbose": true
},
"dependencies": {
"dotenv": "^8.0.0",
Expand All @@ -16,6 +27,9 @@
"sequelize-cli": "^5.5.0"
},
"devDependencies": {
"nodemon": "^1.19.1"
"cross-env": "^5.2.0",
"jest": "^24.9.0",
"nodemon": "^1.19.1",
"supertest": "^4.0.2"
}
}
45 changes: 45 additions & 0 deletions tests/routes.test.js
@@ -0,0 +1,45 @@
const request = require('supertest');
const app = require('../server');

describe('Post Endpoints', () => {
it('should create a new post', async () => {
const res = await request(app).post('/api/posts')
.send({
userId: 1,
title: 'test is cool',
});
expect(res.statusCode).toEqual(201);
expect(res.body).toHaveProperty('post');
});

it('should fetch a single post', async () => {
const postId = 1;
const res = await request(app).get(`/api/posts/${postId}`);
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty('post');
});

it('should fetch all posts', async () => {
const res = await request(app).get('/api/posts');
expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty('posts');
expect(res.body.posts).toHaveLength(1);
});

it('should update a post', async () => {
const res = await request(app).put('/api/posts/1')
.send({
userId: 1,
title: 'updated title',
});

expect(res.statusCode).toEqual(200);
expect(res.body).toHaveProperty('post');
expect(res.body.post).toHaveProperty('title','updated title');
});

it('should delete a post', async () => {
const res = await request(app).delete('/api/posts/1');
expect(res.statusCode).toEqual(204);
});
});
6 changes: 6 additions & 0 deletions tests/sample.test.js
@@ -0,0 +1,6 @@

describe('Sample Test', () => {
it('should test that true === true', () => {
expect(true).toBe(true);
});
});

0 comments on commit d5987eb

Please sign in to comment.