From 61991002f6f22db48358e69087e3770797455c5f Mon Sep 17 00:00:00 2001 From: Jack LaBarba Date: Tue, 17 Jan 2017 11:10:17 -0800 Subject: [PATCH 1/3] APERTA-8551 add user details to FullStory --- .../full-story-config.js | 15 ++++++ .../full-story-config-test.js | 51 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 client/app/instance-initializers/full-story-config.js create mode 100644 client/tests/unit/instance-initializers/full-story-config-test.js diff --git a/client/app/instance-initializers/full-story-config.js b/client/app/instance-initializers/full-story-config.js new file mode 100644 index 00000000000..876ee1dae31 --- /dev/null +++ b/client/app/instance-initializers/full-story-config.js @@ -0,0 +1,15 @@ +export function initialize(applicationInstance) { + const currentUser = applicationInstance.lookup('user:current'); + if (currentUser && typeof window.FS !== 'undefined') { + window.FS.identify(currentUser.get('username'), { + displayName: currentUser.get('fullName'), + email: currentUser.get('email') + }); + } +} + +export default { + name: 'full-story-config', + after: 'current-user', + initialize +}; diff --git a/client/tests/unit/instance-initializers/full-story-config-test.js b/client/tests/unit/instance-initializers/full-story-config-test.js new file mode 100644 index 00000000000..bd6d7ada767 --- /dev/null +++ b/client/tests/unit/instance-initializers/full-story-config-test.js @@ -0,0 +1,51 @@ +import destroyApp from '../../helpers/destroy-app'; +import Ember from 'ember'; +import sinon from 'sinon'; +import { initialize } from 'tahi/instance-initializers/full-story-config'; +import { module, test } from 'qunit'; + +const currentUser = Ember.Object.create({ + username: 'pikachu', + email: 'pikachu@oak.edu', + fullName: 'Pikachu Pokémon' +}); + +module('Unit | Instance Initializer | full story config', { + beforeEach() { + Ember.run(() => { + this.application = Ember.Application.create(); + this.appInstance = this.application.buildInstance(); + this.application.registry.register('user:current', currentUser, { + instantiate: false + }); + this.application.registry.injection('initializer:full-story-config', 'currentUser', 'user:current'); + }); + }, + afterEach() { + Ember.run(this.appInstance, 'destroy'); + destroyApp(this.application); + } +}); + +test('it does nothing when FS is not loaded', function(assert) { + initialize(this.appInstance); + assert.ok('things should not blow up'); +}); + +test('it calls FS.identify when FS is loaded', function(assert) { + const identifySpy = sinon.spy(); + window.FS = { identify: identifySpy }; + initialize(this.appInstance); + assert.spyCalledWith( + identifySpy, + [ + currentUser.get('username'), + { + email: currentUser.get('email'), + displayName: currentUser.get('fullName') + } + ], + 'identify should be called with user details' + ); + delete window.FS; +}); From 1dc81729aa378b4cb10562d3c5fe782ca35f4f86 Mon Sep 17 00:00:00 2001 From: Jack LaBarba Date: Wed, 18 Jan 2017 09:52:10 -0800 Subject: [PATCH 2/3] APERTA-8551 use our bespoke startApp function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apparently it doesn’t work to mix startApp and Application.create in the same test suite. --- .../tests/unit/instance-initializers/full-story-config-test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/tests/unit/instance-initializers/full-story-config-test.js b/client/tests/unit/instance-initializers/full-story-config-test.js index bd6d7ada767..38294a9d343 100644 --- a/client/tests/unit/instance-initializers/full-story-config-test.js +++ b/client/tests/unit/instance-initializers/full-story-config-test.js @@ -1,6 +1,7 @@ import destroyApp from '../../helpers/destroy-app'; import Ember from 'ember'; import sinon from 'sinon'; +import startApp from 'tahi/tests/helpers/start-app'; import { initialize } from 'tahi/instance-initializers/full-story-config'; import { module, test } from 'qunit'; @@ -13,7 +14,7 @@ const currentUser = Ember.Object.create({ module('Unit | Instance Initializer | full story config', { beforeEach() { Ember.run(() => { - this.application = Ember.Application.create(); + this.application = startApp(); this.appInstance = this.application.buildInstance(); this.application.registry.register('user:current', currentUser, { instantiate: false From 596b25bed080bd96e564d70541cf3db3842f6c0f Mon Sep 17 00:00:00 2001 From: Jack LaBarba Date: Wed, 18 Jan 2017 14:28:41 -0800 Subject: [PATCH 3/3] APERTA-8551 ensure FS absence in test --- .../tests/unit/instance-initializers/full-story-config-test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/tests/unit/instance-initializers/full-story-config-test.js b/client/tests/unit/instance-initializers/full-story-config-test.js index 38294a9d343..d1169a22682 100644 --- a/client/tests/unit/instance-initializers/full-story-config-test.js +++ b/client/tests/unit/instance-initializers/full-story-config-test.js @@ -29,8 +29,11 @@ module('Unit | Instance Initializer | full story config', { }); test('it does nothing when FS is not loaded', function(assert) { + const fs = window.FS; + delete window.FS; initialize(this.appInstance); assert.ok('things should not blow up'); + window.FS = fs; }); test('it calls FS.identify when FS is loaded', function(assert) {