11import Sinon from 'sinon' ;
22import { expect } from 'chai' ;
3- import { AtlasService , getTrackingUserInfo , throwIfNotOk } from './main' ;
3+ import { AtlasService , throwIfNotOk } from './main' ;
4+ import * as util from './util' ;
45import { EventEmitter } from 'events' ;
56import { createSandboxFromDefaultPreferences } from 'compass-preferences-model' ;
67import type { PreferencesAccess } from 'compass-preferences-model' ;
78import type { AtlasUserConfigStore } from './user-config-store' ;
8- import type { AtlasUserInfo } from './util' ;
99
1010function getListenerCount ( emitter : EventEmitter ) {
1111 return emitter . eventNames ( ) . reduce ( ( acc , name ) => {
@@ -74,6 +74,14 @@ describe('AtlasServiceMain', function () {
7474
7575 let preferences : PreferencesAccess ;
7676
77+ let getTrackingUserInfoStub : Sinon . SinonStubbedMember <
78+ typeof util . getTrackingUserInfo
79+ > ;
80+
81+ before ( function ( ) {
82+ getTrackingUserInfoStub = sandbox . stub ( util , 'getTrackingUserInfo' ) ;
83+ } ) ;
84+
7785 beforeEach ( async function ( ) {
7886 AtlasService [ 'ipcMain' ] = {
7987 handle : sandbox . stub ( ) ,
@@ -114,8 +122,15 @@ describe('AtlasServiceMain', function () {
114122 sandbox . resetHistory ( ) ;
115123 } ) ;
116124
125+ after ( function ( ) {
126+ sandbox . restore ( ) ;
127+ } ) ;
128+
117129 describe ( 'signIn' , function ( ) {
118130 it ( 'should sign in using oidc plugin' , async function ( ) {
131+ const atlasUid = 'abcdefgh' ;
132+ getTrackingUserInfoStub . returns ( { auid : atlasUid } ) ;
133+
119134 const userInfo = await AtlasService . signIn ( ) ;
120135 expect (
121136 mockOidcPlugin . mongoClientOptions . authMechanismProperties
@@ -124,6 +139,9 @@ describe('AtlasServiceMain', function () {
124139 // proper error message from oidc plugin in case of failed sign in
125140 ) . to . have . been . calledTwice ;
126141 expect ( userInfo ) . to . have . property ( 'sub' , '1234' ) ;
142+ expect ( preferences . getPreferences ( ) . telemetryAtlasUserId ) . to . equal (
143+ atlasUid
144+ ) ;
127145 } ) ;
128146
129147 it ( 'should debounce inflight sign in requests' , async function ( ) {
@@ -522,19 +540,6 @@ describe('AtlasServiceMain', function () {
522540 } ) ;
523541 } ) ;
524542
525- describe ( 'getTrackingUserInfo' , function ( ) {
526- it ( 'should return required tracking info from user info' , function ( ) {
527- expect (
528- getTrackingUserInfo ( {
529- sub : '1234' ,
530- primaryEmail :
'[email protected] ' , 531- } as AtlasUserInfo )
532- ) . to . deep . eq ( {
533- auid : '03ac674216f3e15c761ee1a5e255f067953623c8b388b4459e13f978d7c846f4' ,
534- } ) ;
535- } ) ;
536- } ) ;
537-
538543 describe ( 'setupAIAccess' , function ( ) {
539544 beforeEach ( async function ( ) {
540545 await preferences . savePreferences ( {
0 commit comments