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 sinon = require('sinon') | |
const expect = require('chai').expect | |
const queries = require('../../../src/models/queries') | |
const { show } = require('../../../src/controllers/users') | |
describe('Users Controller', () => { | |
const user = {} | |
describe('GET User', () => { |
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 sinon = require('sinon') | |
const expect = require('chai').expect | |
const queries = require('../../../src/models/queries') | |
const { index, show } = require('../../../src/controllers/posts') | |
describe('Posts controller', () => { | |
const posts = [] | |
const specificPost = {} |
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 expect = require('chai').expect | |
const chai = require('chai') | |
chai.use(require('sinon-chai')) | |
const { | |
sequelize, | |
dataTypes, | |
checkModelName, | |
checkPropertyExists, | |
} = require('sequelize-test-helpers') |
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 expect = require('chai').expect | |
const chai = require('chai') | |
chai.use(require('sinon-chai')) | |
const { | |
sequelize, | |
dataTypes, | |
checkModelName, | |
checkPropertyExists, | |
} = require('sequelize-test-helpers') |
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 | |
const express = require('express') | |
const router = express.Router() | |
const postsController = require('../controllers/posts') | |
router.get('/', postsController.index) | |
router.get('/:id', postsController.show) | |
module.exports = router |
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 express = require('express') | |
const router = express.Router() | |
const usersController = require('../controllers/users') | |
router.get('/', usersController.show) | |
module.exports = router |
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 queries = require('../models/queries') | |
const show = async (req, res) => { | |
const email = req.user.email | |
const user = await queries.getUser(email) | |
res.status(200).send(user) | |
} | |
module.exports = { show } |
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 queries = require('../models/queries') | |
const index = async (req, res) => { | |
const allPosts = await queries.getAllPosts() | |
res.status(200).send(allPosts) | |
} | |
const show = async (req, res) => { | |
const specificPost = await queries.getSpecificPost(req.params.id) | |
res.status(200).send(specificPost) |
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 getUser = require('./users') | |
const { getAllPosts, getSpecificPost } = require('./posts') | |
module.exports = { | |
getUser, | |
getAllPosts, | |
getSpecificPost, | |
} |
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 getUser = async (email) => { | |
const user = await db.User.findOne({ | |
where: { email: email }, | |
attributes: ['firstName', 'lastName'], | |
include: [ | |
{ | |
model: db.Post, | |
as: 'Written', |