{"action":"created","issue":{"url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift/issues/3","repository_url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift","labels_url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift/issues/3/comments","events_url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift/issues/3/events","html_url":"https://github.com/Driftt/analytics.js-integration-drift/pull/3","id":156605514,"number":3,"title":"add a test that identify() gets called on page load","user":{"login":"trun","id":160978,"avatar_url":"https://avatars.githubusercontent.com/u/160978?v=3","gravatar_id":"","url":"https://api.github.com/users/trun","html_url":"https://github.com/trun","followers_url":"https://api.github.com/users/trun/followers","following_url":"https://api.github.com/users/trun/following{/other_user}","gists_url":"https://api.github.com/users/trun/gists{/gist_id}","starred_url":"https://api.github.com/users/trun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trun/subscriptions","organizations_url":"https://api.github.com/users/trun/orgs","repos_url":"https://api.github.com/users/trun/repos","events_url":"https://api.github.com/users/trun/events{/privacy}","received_events_url":"https://api.github.com/users/trun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-05-24T20:48:50Z","updated_at":"2016-05-25T17:48:46Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift/pulls/3","html_url":"https://github.com/Driftt/analytics.js-integration-drift/pull/3","diff_url":"https://github.com/Driftt/analytics.js-integration-drift/pull/3.diff","patch_url":"https://github.com/Driftt/analytics.js-integration-drift/pull/3.patch"},"body":"adds some additional tests for `#page`.\r\n\r\n- `drift.identify` is called on `#page` if it hasn't been called yet\r\n- `drift.identify` is not called again on `#page` if it has already been called\r\n"},"comment":{"url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift/issues/comments/221653153","html_url":"https://github.com/Driftt/analytics.js-integration-drift/pull/3#issuecomment-221653153","issue_url":"https://api.github.com/repos/Driftt/analytics.js-integration-drift/issues/3","id":221653153,"user":{"login":"hankim813","id":5907121,"avatar_url":"https://avatars.githubusercontent.com/u/5907121?v=3","gravatar_id":"","url":"https://api.github.com/users/hankim813","html_url":"https://github.com/hankim813","followers_url":"https://api.github.com/users/hankim813/followers","following_url":"https://api.github.com/users/hankim813/following{/other_user}","gists_url":"https://api.github.com/users/hankim813/gists{/gist_id}","starred_url":"https://api.github.com/users/hankim813/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hankim813/subscriptions","organizations_url":"https://api.github.com/users/hankim813/orgs","repos_url":"https://api.github.com/users/hankim813/repos","events_url":"https://api.github.com/users/hankim813/events{/privacy}","received_events_url":"https://api.github.com/users/hankim813/received_events","type":"User","site_admin":false},"created_at":"2016-05-25T17:48:46Z","updated_at":"2016-05-25T17:48:46Z","body":"@trun Ahh yeah the reason why `page.userId()` is being undefined there even though you are calling `analytics.identify()` in the test is that the library is being mocked. In production, calling `.identify()` will cache the `userId` into the cookie, which is how long story short-- `page.userId()` depends on. But in the scope of the testing framework, we obviously can't use cookies so that wouldn't work.\r\n\r\nI think you can do a test like this:\r\n\r\n```js\r\nit('should send an page view event and should not send another identify event', function() {\r\n  analytics.page('page');\r\n  analytics.called(window.drift.page, 'page');\r\n  analytics.didNotCall(window.drift.identify);\r\n});\r\n```\r\n\r\nI'm not sure how to test the feature in regards to sending both `.page()` and `.identify()` given that an `.identify()` call has already been made given your current implementation of the logic. \r\n\r\nHowever, if you change this code:\r\n\r\n```js\r\nif (!this.identified && page.userId()) {\r\n    window.drift.identify(page.userId());\r\n    this.identified = true;\r\n}\r\n```\r\nto:\r\n\r\n```js\r\nvar id = analytics.user().id();\r\n\r\nif (!this.identified && id) {\r\n  window.drift.identify(id);\r\n  this.identified = true;\r\n}\r\n\r\n// and then for the test:\r\n\r\nanalytics.user.id('id');\r\nanalytics.page();\r\nanalytics.called(window.drift.identify, 'id');\r\nanalytics.called(window.drift.page, 'page');\r\n```\r\n\r\nThe new implementation code would functionally be the same. `analytics.user().id()` will return whatever is the latest cached `userId` which can be updated via passing in an `argument` to the `id()` function or through the `.identify()` call.\r\n\r\nLet me know if that works for you"}}
{"actor":{"display_login":"hankim813"}}