Skip to content

Commit

Permalink
Merge pull request #2831 from Tahi-project/tasks/APERTA-8551-add-full…
Browse files Browse the repository at this point in the history
…-story-user-details

APERTA-8551 add user details to FullStory
  • Loading branch information
JackLaBarba committed Jan 19, 2017
2 parents 2a7c44c + a5af151 commit e1c97f9
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions client/app/instance-initializers/full-story-config.js
Original file line number Diff line number Diff line change
@@ -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
};
55 changes: 55 additions & 0 deletions client/tests/unit/instance-initializers/full-story-config-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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';

const currentUser = Ember.Object.create({
username: 'pikachu',
email: '[email protected]',
fullName: 'Pikachu Pokémon'
});

module('Unit | Instance Initializer | full story config', {
beforeEach() {
Ember.run(() => {
this.application = startApp();
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) {
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) {
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;
});

0 comments on commit e1c97f9

Please sign in to comment.