-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2831 from Tahi-project/tasks/APERTA-8551-add-full…
…-story-user-details APERTA-8551 add user details to FullStory
- Loading branch information
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
client/tests/unit/instance-initializers/full-story-config-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |