{"action":"created","comment":{"url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/comments/82511510","pull_request_review_id":3416178,"id":82511510,"diff_hunk":"@@ -58,4 +58,56 @@ describe('sequelize-encrypted', () => {\n         assert.equal(found.private_1, undefined);\n     });\n \n+    it('should support validation', async() => {\n+      const VAULT = EncryptedField(Sequelize, key2);\n+      const ValidUser = sequelize.define('validUser', {\n+          name: Sequelize.STRING,\n+          encrypted: VAULT.vault('encrypted'),\n+\n+          // encrypted virtual fields\n+          private_1: VAULT.field('private_1', {\n+            type: Sequelize.INTEGER,\n+            validate: {\n+              notEmpty: true\n+            }\n+          })\n+      });\n+      const user = ValidUser.build();\n+      user.private_1 = '';\n+\n+      const res = await user.validate();\n+      assert.equal(res.message, \"Validation error: Validation notEmpty failed\");","path":"test/index.js","position":22,"original_position":22,"commit_id":"a2ef0a840e01f681f1f7b32796d525b0196d3aed","original_commit_id":"a2ef0a840e01f681f1f7b32796d525b0196d3aed","user":{"login":"defunctzombie","id":84792,"avatar_url":"https://avatars.githubusercontent.com/u/84792?v=3","gravatar_id":"","url":"https://api.github.com/users/defunctzombie","html_url":"https://github.com/defunctzombie","followers_url":"https://api.github.com/users/defunctzombie/followers","following_url":"https://api.github.com/users/defunctzombie/following{/other_user}","gists_url":"https://api.github.com/users/defunctzombie/gists{/gist_id}","starred_url":"https://api.github.com/users/defunctzombie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/defunctzombie/subscriptions","organizations_url":"https://api.github.com/users/defunctzombie/orgs","repos_url":"https://api.github.com/users/defunctzombie/repos","events_url":"https://api.github.com/users/defunctzombie/events{/privacy}","received_events_url":"https://api.github.com/users/defunctzombie/received_events","type":"User","site_admin":false},"body":"single quotes for strings (like elsewhere in this file)","created_at":"2016-10-08T23:23:41Z","updated_at":"2016-10-08T23:24:18Z","html_url":"https://github.com/defunctzombie/sequelize-encrypted/pull/8#discussion_r82511510","pull_request_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/comments/82511510"},"html":{"href":"https://github.com/defunctzombie/sequelize-encrypted/pull/8#discussion_r82511510"},"pull_request":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8","id":87616109,"html_url":"https://github.com/defunctzombie/sequelize-encrypted/pull/8","diff_url":"https://github.com/defunctzombie/sequelize-encrypted/pull/8.diff","patch_url":"https://github.com/defunctzombie/sequelize-encrypted/pull/8.patch","issue_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/issues/8","number":8,"state":"open","locked":false,"title":"Added support for validations, allowNull and defaultValues.","user":{"login":"validkeys","id":21793,"avatar_url":"https://avatars.githubusercontent.com/u/21793?v=3","gravatar_id":"","url":"https://api.github.com/users/validkeys","html_url":"https://github.com/validkeys","followers_url":"https://api.github.com/users/validkeys/followers","following_url":"https://api.github.com/users/validkeys/following{/other_user}","gists_url":"https://api.github.com/users/validkeys/gists{/gist_id}","starred_url":"https://api.github.com/users/validkeys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/validkeys/subscriptions","organizations_url":"https://api.github.com/users/validkeys/orgs","repos_url":"https://api.github.com/users/validkeys/repos","events_url":"https://api.github.com/users/validkeys/events{/privacy}","received_events_url":"https://api.github.com/users/validkeys/received_events","type":"User","site_admin":false},"body":"Due to the git problems I was having with the previous PR, here is a new clean PR with passing tests. As a reminder of the contents of this PR:\r\n\r\n----\r\n@defunctzombie so I cleaned up the code and rebased off of master. So to recap, the main additions here are that you get all of the same configuration options are you would when creating a regular sequelize field:\r\n\r\n```javascript\r\n    private_2: enc_fields.field('private_2', {\r\n      type: Sequelize.TEXT,\r\n      validate: {\r\n        isInt: true  \r\n      },\r\n      allowNull: false,\r\n      defaultValue: null\r\n    })\r\n```\r\n\r\nIf you pass in the \"type\", your field will be cast as that type using the built-in functionality of sequelize. You can pass in validation rules just like you would a regular field and you can also supply a default value. One of the issues I was having was when creating models where the field is not in the payload, the encrypted field was showing up like this:\r\n\r\n```\r\n{\"encrypted\": {\"someField\":\"undefined\"}}\r\n```\r\n\r\nSo passing in the the default value, the getter on the virtual field returns your defaultValue if the value in the encrypted field is empty.\r\n\r\nFinally, the ability to pass in the allowNull attr as you would a regular property.\r\n\r\nI've also added tests for each of the above.","created_at":"2016-10-01T21:23:41Z","updated_at":"2016-10-08T23:24:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f781dc1e5dd9e8f28ce4bd881dc1081598a30643","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8/commits","review_comments_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8/comments","review_comment_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/comments{/number}","comments_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/issues/8/comments","statuses_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/statuses/a2ef0a840e01f681f1f7b32796d525b0196d3aed","head":{"label":"validkeys:master","ref":"master","sha":"a2ef0a840e01f681f1f7b32796d525b0196d3aed","user":{"login":"validkeys","id":21793,"avatar_url":"https://avatars.githubusercontent.com/u/21793?v=3","gravatar_id":"","url":"https://api.github.com/users/validkeys","html_url":"https://github.com/validkeys","followers_url":"https://api.github.com/users/validkeys/followers","following_url":"https://api.github.com/users/validkeys/following{/other_user}","gists_url":"https://api.github.com/users/validkeys/gists{/gist_id}","starred_url":"https://api.github.com/users/validkeys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/validkeys/subscriptions","organizations_url":"https://api.github.com/users/validkeys/orgs","repos_url":"https://api.github.com/users/validkeys/repos","events_url":"https://api.github.com/users/validkeys/events{/privacy}","received_events_url":"https://api.github.com/users/validkeys/received_events","type":"User","site_admin":false},"repo":{"id":69763803,"name":"sequelize-encrypted","full_name":"validkeys/sequelize-encrypted","owner":{"login":"validkeys","id":21793,"avatar_url":"https://avatars.githubusercontent.com/u/21793?v=3","gravatar_id":"","url":"https://api.github.com/users/validkeys","html_url":"https://github.com/validkeys","followers_url":"https://api.github.com/users/validkeys/followers","following_url":"https://api.github.com/users/validkeys/following{/other_user}","gists_url":"https://api.github.com/users/validkeys/gists{/gist_id}","starred_url":"https://api.github.com/users/validkeys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/validkeys/subscriptions","organizations_url":"https://api.github.com/users/validkeys/orgs","repos_url":"https://api.github.com/users/validkeys/repos","events_url":"https://api.github.com/users/validkeys/events{/privacy}","received_events_url":"https://api.github.com/users/validkeys/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/validkeys/sequelize-encrypted","description":"Encrypted fields for Sequelize ORM","fork":true,"url":"https://api.github.com/repos/validkeys/sequelize-encrypted","forks_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/forks","keys_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/keys{/key_id}","collaborators_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/teams","hooks_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/hooks","issue_events_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/issues/events{/number}","events_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/events","assignees_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/assignees{/user}","branches_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/branches{/branch}","tags_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/tags","blobs_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/git/refs{/sha}","trees_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/git/trees{/sha}","statuses_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/statuses/{sha}","languages_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/languages","stargazers_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/stargazers","contributors_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/contributors","subscribers_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/subscribers","subscription_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/subscription","commits_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/commits{/sha}","git_commits_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/git/commits{/sha}","comments_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/comments{/number}","issue_comment_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/issues/comments{/number}","contents_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/contents/{+path}","compare_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/compare/{base}...{head}","merges_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/merges","archive_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/downloads","issues_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/issues{/number}","pulls_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/pulls{/number}","milestones_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/milestones{/number}","notifications_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/labels{/name}","releases_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/releases{/id}","deployments_url":"https://api.github.com/repos/validkeys/sequelize-encrypted/deployments","created_at":"2016-10-01T21:06:10Z","updated_at":"2016-10-01T21:06:11Z","pushed_at":"2016-10-01T21:22:24Z","git_url":"git://github.com/validkeys/sequelize-encrypted.git","ssh_url":"git@github.com:validkeys/sequelize-encrypted.git","clone_url":"https://github.com/validkeys/sequelize-encrypted.git","svn_url":"https://github.com/validkeys/sequelize-encrypted","homepage":null,"size":8,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"defunctzombie:master","ref":"master","sha":"47d562f2baff14df569bd037e29710e9d127eaf6","user":{"login":"defunctzombie","id":84792,"avatar_url":"https://avatars.githubusercontent.com/u/84792?v=3","gravatar_id":"","url":"https://api.github.com/users/defunctzombie","html_url":"https://github.com/defunctzombie","followers_url":"https://api.github.com/users/defunctzombie/followers","following_url":"https://api.github.com/users/defunctzombie/following{/other_user}","gists_url":"https://api.github.com/users/defunctzombie/gists{/gist_id}","starred_url":"https://api.github.com/users/defunctzombie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/defunctzombie/subscriptions","organizations_url":"https://api.github.com/users/defunctzombie/orgs","repos_url":"https://api.github.com/users/defunctzombie/repos","events_url":"https://api.github.com/users/defunctzombie/events{/privacy}","received_events_url":"https://api.github.com/users/defunctzombie/received_events","type":"User","site_admin":false},"repo":{"id":27042468,"name":"sequelize-encrypted","full_name":"defunctzombie/sequelize-encrypted","owner":{"login":"defunctzombie","id":84792,"avatar_url":"https://avatars.githubusercontent.com/u/84792?v=3","gravatar_id":"","url":"https://api.github.com/users/defunctzombie","html_url":"https://github.com/defunctzombie","followers_url":"https://api.github.com/users/defunctzombie/followers","following_url":"https://api.github.com/users/defunctzombie/following{/other_user}","gists_url":"https://api.github.com/users/defunctzombie/gists{/gist_id}","starred_url":"https://api.github.com/users/defunctzombie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/defunctzombie/subscriptions","organizations_url":"https://api.github.com/users/defunctzombie/orgs","repos_url":"https://api.github.com/users/defunctzombie/repos","events_url":"https://api.github.com/users/defunctzombie/events{/privacy}","received_events_url":"https://api.github.com/users/defunctzombie/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/defunctzombie/sequelize-encrypted","description":"Encrypted fields for Sequelize ORM","fork":false,"url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted","forks_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/forks","keys_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/keys{/key_id}","collaborators_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/teams","hooks_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/hooks","issue_events_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/issues/events{/number}","events_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/events","assignees_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/assignees{/user}","branches_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/branches{/branch}","tags_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/tags","blobs_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/git/refs{/sha}","trees_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/git/trees{/sha}","statuses_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/statuses/{sha}","languages_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/languages","stargazers_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/stargazers","contributors_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/contributors","subscribers_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/subscribers","subscription_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/subscription","commits_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/commits{/sha}","git_commits_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/git/commits{/sha}","comments_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/comments{/number}","issue_comment_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/issues/comments{/number}","contents_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/contents/{+path}","compare_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/compare/{base}...{head}","merges_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/merges","archive_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/downloads","issues_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/issues{/number}","pulls_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls{/number}","milestones_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/milestones{/number}","notifications_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/labels{/name}","releases_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/releases{/id}","deployments_url":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/deployments","created_at":"2014-11-23T18:27:14Z","updated_at":"2016-10-08T07:26:41Z","pushed_at":"2016-10-01T21:23:41Z","git_url":"git://github.com/defunctzombie/sequelize-encrypted.git","ssh_url":"git@github.com:defunctzombie/sequelize-encrypted.git","clone_url":"https://github.com/defunctzombie/sequelize-encrypted.git","svn_url":"https://github.com/defunctzombie/sequelize-encrypted","homepage":null,"size":11,"stargazers_count":14,"watchers_count":14,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":2,"forks":3,"open_issues":2,"watchers":14,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8"},"html":{"href":"https://github.com/defunctzombie/sequelize-encrypted/pull/8"},"issue":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/issues/8"},"comments":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/defunctzombie/sequelize-encrypted/statuses/a2ef0a840e01f681f1f7b32796d525b0196d3aed"}}}}
{"actor":{"display_login":"defunctzombie"}}