-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(atlas-service): add sign in tracking for atlas-service COMPASS-…
…7112 (#4774) * chore(atlas-service): add tracking for sign in and sign out * chore(atlas-service): add comment explaining what AUID is
- Loading branch information
1 parent
1513126
commit 0b36060
Showing
2 changed files
with
56 additions
and
14 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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import Sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
import { AtlasService, throwIfNotOk } from './main'; | ||
import { AtlasService, getTrackingUserInfo, throwIfNotOk } from './main'; | ||
import { EventEmitter } from 'events'; | ||
import preferencesAccess from 'compass-preferences-model'; | ||
import type { AtlasUserConfigStore } from './user-config-store'; | ||
import type { AtlasUserInfo } from './util'; | ||
|
||
function getListenerCount(emitter: EventEmitter) { | ||
return emitter.eventNames().reduce((acc, name) => { | ||
|
@@ -22,6 +23,9 @@ describe('AtlasServiceMain', function () { | |
return { sub: '1234' }; | ||
}, | ||
}, | ||
'http://example.com/v1/revoke?client_id=1234abcd': { | ||
ok: true, | ||
}, | ||
}[url]; | ||
}); | ||
|
||
|
@@ -468,30 +472,47 @@ describe('AtlasServiceMain', function () { | |
describe('signOut', function () { | ||
it('should reset service state, revoke tokens, and destroy plugin', async function () { | ||
const logger = new EventEmitter(); | ||
const plugin = { | ||
destroy: sandbox.stub().resolves(), | ||
}; | ||
AtlasService['openExternal'] = sandbox.stub().resolves(); | ||
AtlasService['createMongoDBOIDCPlugin'] = (() => { | ||
return plugin; | ||
}) as any; | ||
AtlasService['fetch'] = sandbox.stub().resolves({ ok: true }) as any; | ||
AtlasService['oidcPluginLogger'] = logger; | ||
|
||
await AtlasService.init(); | ||
expect(getListenerCount(logger)).to.eq(25); | ||
// We did all preparations, reset sinon history for easier assertions | ||
sandbox.resetHistory(); | ||
|
||
expect(getListenerCount(logger)).to.eq(25); | ||
|
||
await AtlasService.signOut(); | ||
expect(getListenerCount(logger)).to.eq(0); | ||
expect(logger).to.not.eq(AtlasService['oidcPluginLogger']); | ||
expect(plugin.destroy).to.have.been.calledOnce; | ||
expect(mockOidcPlugin.destroy).to.have.been.calledOnce; | ||
expect(AtlasService['fetch']).to.have.been.calledOnceWith( | ||
'http://example.com/v1/revoke?client_id=1234abcd' | ||
); | ||
expect(AtlasService['openExternal']).to.have.been.calledOnce; | ||
}); | ||
|
||
it('should throw when called before sign in', async function () { | ||
try { | ||
await AtlasService.signOut(); | ||
expect.fail('Expected signOut to throw'); | ||
} catch (err) { | ||
expect(err).to.have.property( | ||
'message', | ||
"Can't sign out if not signed in yet" | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
describe('getTrackingUserInfo', function () { | ||
it('should return required tracking info from user info', function () { | ||
expect( | ||
getTrackingUserInfo({ | ||
sub: '1234', | ||
primaryEmail: '[email protected]', | ||
} as AtlasUserInfo) | ||
).to.deep.eq({ | ||
auid: '03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4', | ||
email: '[email protected]', | ||
}); | ||
}); | ||
}); | ||
}); |
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