{"action":"created","issue":{"url":"https://api.github.com/repos/danecando/hapi-sequelize/issues/38","repository_url":"https://api.github.com/repos/danecando/hapi-sequelize","labels_url":"https://api.github.com/repos/danecando/hapi-sequelize/issues/38/labels{/name}","comments_url":"https://api.github.com/repos/danecando/hapi-sequelize/issues/38/comments","events_url":"https://api.github.com/repos/danecando/hapi-sequelize/issues/38/events","html_url":"https://github.com/danecando/hapi-sequelize/issues/38","id":127212356,"number":38,"title":"Testing without database connection","user":{"login":"Nargonath","id":583657,"avatar_url":"https://avatars.githubusercontent.com/u/583657?v=3","gravatar_id":"","url":"https://api.github.com/users/Nargonath","html_url":"https://github.com/Nargonath","followers_url":"https://api.github.com/users/Nargonath/followers","following_url":"https://api.github.com/users/Nargonath/following{/other_user}","gists_url":"https://api.github.com/users/Nargonath/gists{/gist_id}","starred_url":"https://api.github.com/users/Nargonath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nargonath/subscriptions","organizations_url":"https://api.github.com/users/Nargonath/orgs","repos_url":"https://api.github.com/users/Nargonath/repos","events_url":"https://api.github.com/users/Nargonath/events{/privacy}","received_events_url":"https://api.github.com/users/Nargonath/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/danecando/hapi-sequelize/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/danecando/hapi-sequelize/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-01-18T11:58:36Z","updated_at":"2016-10-15T09:16:00Z","closed_at":null,"body":"**This is just a question.**\r\n\r\nI just wrote a unit test suite where I check the integrity of my models (password should not be < 8 etc.) but I have to perform a database connection on each test therefore my test are pretty slow (~350ms).\r\n\r\nHere is an example of a basic test:\r\n````javascript\r\n\r\n'use strict';\r\n\r\nvar assert = require('assert');\r\n\r\nvar config = require('../../config/config');\r\n\r\nvar Hapi = require('hapi');\r\n\r\ndescribe('User module: [model]', function() {\r\n  var server = {};\r\n\r\n  beforeEach('Setting up the server', function() {\r\n    server = new Hapi.Server();\r\n    server.connection();\r\n\r\n    return server.register({\r\n      register: require('hapi-sequelize'),\r\n      options: {\r\n        database: config.get('/database/credentials').dbName,\r\n        user: config.get('/database/credentials').user,\r\n        pass: config.get('/database/credentials').pass,\r\n        dialect: config.get('/database/credentials').dialect,\r\n        port: config.get('/database/credentials').port,\r\n        models: 'app/modules/user/model.js',\r\n        logging: false\r\n      }\r\n    })\r\n    .then(function() {\r\n      var db = server.plugins['hapi-sequelize'].db;\r\n\r\n      return db.sequelize.sync({force: true})\r\n                        .then(function() {\r\n                          return server.initialize();\r\n                        });\r\n    })\r\n    .catch(assert.ifError);\r\n  });\r\n\r\n  afterEach('Clear database/server connection', function() {\r\n    server.plugins['hapi-sequelize'].db.sequelize.close();\r\n    return server.stop();\r\n  });\r\n\r\n  describe('User model', function() {\r\n\r\n    it('should hash user\\'s password', function() {\r\n      var User = server.plugins['hapi-sequelize'].db.sequelize.models.User;\r\n\r\n      return User.create({\r\n        email: 'test@gmail.com',\r\n        password: 'iamapassword'\r\n      })\r\n      .then(function(user) {\r\n        assert.equal(user.password.length, 60);\r\n      })\r\n      .catch(assert.ifError);\r\n    });\r\n  });\r\n});\r\n````\r\n\r\nIs it possible to test Model creation without actually using a database connection? Is it possible to mock it or something alike?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/danecando/hapi-sequelize/issues/comments/253972620","html_url":"https://github.com/danecando/hapi-sequelize/issues/38#issuecomment-253972620","issue_url":"https://api.github.com/repos/danecando/hapi-sequelize/issues/38","id":253972620,"user":{"login":"Nargonath","id":583657,"avatar_url":"https://avatars.githubusercontent.com/u/583657?v=3","gravatar_id":"","url":"https://api.github.com/users/Nargonath","html_url":"https://github.com/Nargonath","followers_url":"https://api.github.com/users/Nargonath/followers","following_url":"https://api.github.com/users/Nargonath/following{/other_user}","gists_url":"https://api.github.com/users/Nargonath/gists{/gist_id}","starred_url":"https://api.github.com/users/Nargonath/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nargonath/subscriptions","organizations_url":"https://api.github.com/users/Nargonath/orgs","repos_url":"https://api.github.com/users/Nargonath/repos","events_url":"https://api.github.com/users/Nargonath/events{/privacy}","received_events_url":"https://api.github.com/users/Nargonath/received_events","type":"User","site_admin":false},"created_at":"2016-10-15T09:16:00Z","updated_at":"2016-10-15T09:16:00Z","body":"Hey sorry for not being active as I wanted to. The last months have been pretty harsh on me and I didn't have the time for OSS as I wished. \r\n\r\nI haven't really dived into your v3 rewrite but, if we can't free ourselves from an actual database, sqlite seems a good option. I saw that you moved the sequelize instanciation out of your plugin. Perhaps there is a way we could mock up sequelize instance now so we wouldn't actually require a real database for the tests. I remember reading something about it somewhere. I'll see if I can find it back. Not sure if you were talking about your own module's tests or people's tests using your module. :)"}}
{"actor":{"display_login":"Nargonath"}}