Created
July 8, 2020 13:00
-
-
Save kianaditya/3616ef15de4fc601bcf3558dd5e35800 to your computer and use it in GitHub Desktop.
This file contains 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') | |
const UserModel = require('../../../src/models/user') | |
const PostModel = require('../../../src/models/post') | |
describe('src/models/User', () => { | |
const Post = PostModel(sequelize, dataTypes) | |
const post = new Post() | |
checkModelName(Post)('Post') | |
context('Properties', () => { | |
;['title', 'content'].forEach(checkPropertyExists(post)) | |
}) | |
context('associations', () => { | |
before(() => { | |
Post.belongsTo(UserModel, { as: 'Author', foreignKey: 'AuthorId' }) | |
Post.belongsToMany(UserModel, { through: 'SavedPosts', as: 'savedBy' }) | |
}) | |
it('defined a belongsTo association with Post', () => { | |
expect(Post.belongsTo).to.have.been.calledWith(UserModel, { | |
as: 'Author', | |
foreignKey: 'AuthorId', | |
}) | |
}) | |
it('defined a belongsToMany through SavedPosts association with Post', () => { | |
expect(Post.belongsToMany).to.have.been.calledWith(UserModel, { | |
through: 'SavedPosts', | |
as: 'savedBy', | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment