This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//posts.spec.js | |
const request = require('supertest') | |
const app = require('../src/app') // the express server | |
const expect = require('chai').expect | |
describe('GET /posts endpoint', () => { | |
it('GET /posts endpoint successfully returns response', () => { | |
return request(app) | |
.get('/posts') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); //https://nodejs.org/api/path.html | |
module.exports = { | |
"config": path.resolve('./config', 'config.json'), | |
"models-path": path.resolve('./src/models'), | |
"seeders-path": path.resolve('./src/models/seeders'), | |
"migrations-path": path.resolve('./src/models/migrations') | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"development": { | |
"username": "demo_user", | |
"password": "demo_user", | |
"database": "express_demo_development", | |
"host": "127.0.0.1", | |
"dialect": "postgres", | |
"logging": false | |
}, | |
"test": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// controllers/posts.js | |
const db = require('../models') | |
exports.getAllPosts = async (req, res, next) => { | |
const allPosts = await db.Post.findAll({ | |
attributes: ['id', 'title', 'content'], | |
}) | |
res.status(200).send(allPosts) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// routes/posts.js | |
// /routes/posts.js | |
const express = require('express') | |
const router = express.Router() | |
const postsController = require('../controllers/posts') | |
router.get('/', postsController.getAllPosts) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
module.exports = { | |
up: (queryInterface, Sequelize) => { | |
return queryInterface.bulkInsert( | |
'Posts', | |
[ | |
{ | |
title: 'Learning Javascript', | |
content: 'Learn to learn javascript', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const express = require('express') | |
const logger = require('morgan') | |
const db = require('./models') | |
const app = express() | |
const PORT = process.env.PORT | |
app.use(logger('dev')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// seeders/index.js | |
const db = require('../index') | |
const chance = require('chance').Chance() | |
const faker = require('faker') | |
const createSeeds = async () => { | |
const postsCount = 3 | |
chance.mixin({ | |
post: function () { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const express = require('express') | |
const logger = require('morgan') | |
const db = require('./models') | |
const createSeeds = require('./models/seeders') | |
const app = express() | |
const PORT = process.env.PORT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const factoryGirl = require('factory-girl') | |
const adapter = new factoryGirl.SequelizeAdapter() | |
const factory = factoryGirl.factory | |
factory.setAdapter(adapter) | |
factory.cleanUp() | |
const db = require('../../src/models') | |
factory.define('Post', db.Post, async () => { |