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 db = require('../index') | |
const chance = require('chance').Chance() | |
const faker = require('faker') | |
const createSeeds = async () => { | |
const author1 = await db.User.create({ | |
firstName: chance.first(), | |
lastName: chance.last(), | |
}) |
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 = (sequelize, DataTypes) => { | |
const Post = sequelize.define( | |
'Post', | |
{ | |
title: DataTypes.STRING, | |
content: DataTypes.TEXT, | |
}, | |
{} | |
) |
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 = (sequelize, DataTypes) => { | |
const User = sequelize.define( | |
'User', | |
{ | |
firstName: DataTypes.STRING, | |
lastName: DataTypes.STRING, | |
}, | |
{} | |
) |
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 request = require('supertest') | |
const app = require('../src/app') | |
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 factories = require('../factories') | |
const db = require('../../src/models') | |
before(async function () { | |
try { | |
for (let index = 0; index < 4; index++) { | |
const post = await factories.create('Post') | |
} | |
} catch (error) { | |
console.error(error) |
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 () => { |
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
// 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 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
'use strict' | |
module.exports = { | |
up: (queryInterface, Sequelize) => { | |
return queryInterface.bulkInsert( | |
'Posts', | |
[ | |
{ | |
title: 'Learning Javascript', | |
content: 'Learn to learn javascript', |