Skip to content

Commit

Permalink
Merge 51aea94 into 32476d7
Browse files Browse the repository at this point in the history
  • Loading branch information
mystere10 committed Apr 13, 2019
2 parents 32476d7 + 51aea94 commit 3ebfe6d
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 4 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import YAML from 'yamljs';
import routes from './routes/routes';
import user from './routes/user';
import Strategy from './middlewares/auth';
import articleRoutes from './routes/articles';

const swaggerDocument = YAML.load('./swagger.yaml');

Expand All @@ -15,7 +16,7 @@ const app = express();
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use((express.json()));

app.use('/api/articles', articleRoutes);
app.use('/api/users', user);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

Expand All @@ -28,7 +29,9 @@ app.use('/api/v1/login', user);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));

app.use('/', (req, res) => {
res.send('Welcome');
res.status(200).json({
message: 'Welcome to Author Haven'
});
});


Expand Down
15 changes: 15 additions & 0 deletions migrations/20190403113724-create-article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* eslint-disable no-unused-vars */
module.exports = {
up: (queryInterface, Sequelize) => queryInterface.createTable('articles', {
id: { type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true },
slug: { type: Sequelize.STRING, allowNull: false, unique: true },
title: { type: Sequelize.STRING, required: true },
description: { type: Sequelize.TEXT, allowNull: true },
body: { type: Sequelize.TEXT, required: true },
taglist: { type: Sequelize.ARRAY(Sequelize.STRING), defaultValue: [] },
authorid: { type: Sequelize.INTEGER, allowNull: false },
createdAt: { allowNull: false, type: Sequelize.DATE },
updatedAt: { allowNull: false, type: Sequelize.DATE },
}),
down: (queryInterface, Sequelize) => queryInterface.dropTable('articles')
};
13 changes: 13 additions & 0 deletions models/article.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = (sequelize, DataTypes) => {
const Article = sequelize.define('article', {
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
slug: { type: DataTypes.STRING, allowNull: false, unique: true },
title: { type: DataTypes.STRING, allowNull: false },
body: { type: DataTypes.TEXT, allowNull: false },
taglist: { type: DataTypes.ARRAY(DataTypes.STRING), allowNull: true },
description: { type: DataTypes.TEXT, allowNull: true },
authorid: { type: DataTypes.INTEGER, allowNull: false }
}, {});

return Article;
};
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "NODE_ENV=test nyc --reporter=html --reporter=text mocha --require @babel/polyfill --require @babel/register ./test/*.js --exit",
"start": "babel-node ./index.js",
"dev": "nodemon --exec babel-node ./index.js ",
"migrate": "node_modules/.bin/sequelize db:migrate:undo:all && node_modules/.bin/sequelize db:migrate",
"migrate": "node_modules/.bin/sequelize db:migrate:undo && node_modules/.bin/sequelize db:migrate",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"lint": "eslint ./",
"lint-fix": "eslint ./ --fix",
Expand All @@ -30,6 +30,8 @@
"express": "^4.16.3",
"express-jwt": "^5.3.1",
"express-session": "^1.15.6",
"faker": "^4.1.0",
"hasha": "^5.0.0",
"joi": "^14.3.1",
"jsonwebtoken": "^8.3.0",
"lodash": "^4.17.11",
Expand All @@ -45,9 +47,10 @@
"sequelize": "^4.42.0",
"sequelize-cli": "^5.4.0",
"slug": "^1.0.0",
"slugify": "^1.3.4",
"swagger-ui-express": "^4.0.2",
"underscore": "^1.9.1",
"uuid": "^3.3.2",
"swagger-ui-express": "^4.0.2",
"yamljs": "^0.3.0"
},
"devDependencies": {
Expand Down
11 changes: 11 additions & 0 deletions routes/articles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import express from 'express';

const router = express.Router();

router.post('/');
router.get('/');
router.delete('/:slug');
router.put('/:slug');


export default router;
21 changes: 21 additions & 0 deletions test/homeRoute_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import chai from 'chai';
import chaiHttp from 'chai-http';
import index from '../index';

chai.should();
chai.use(chaiHttp);

/**
* @author: Innocent Nkunzi
* @description: tests related to article
*/
describe('Test the home route', () => {
it('should return the landing page', (done) => {
chai.request(index).get('/').then((res) => {
res.should.have.status(200);
res.body.should.have.property('message').eql('Welcome to Author Haven');
done();
})
.catch(err => err);
});
});
8 changes: 8 additions & 0 deletions test/mockData/articleMockData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import faker from 'faker';

module.exports = {
title: faker.random.words(),
description: faker.lorem.sentences(),
body: faker.lorem.sentences(),
authorid: faker.random.number(),
};

0 comments on commit 3ebfe6d

Please sign in to comment.