1
1
import Sinon from 'sinon' ;
2
2
import { expect } from 'chai' ;
3
- import { AtlasService , getTrackingUserInfo , throwIfNotOk } from './main' ;
3
+ import { AtlasService , throwIfNotOk } from './main' ;
4
+ import * as util from './util' ;
4
5
import { EventEmitter } from 'events' ;
5
6
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model' ;
6
7
import type { PreferencesAccess } from 'compass-preferences-model' ;
7
8
import type { AtlasUserConfigStore } from './user-config-store' ;
8
- import type { AtlasUserInfo } from './util' ;
9
9
10
10
function getListenerCount ( emitter : EventEmitter ) {
11
11
return emitter . eventNames ( ) . reduce ( ( acc , name ) => {
@@ -74,6 +74,14 @@ describe('AtlasServiceMain', function () {
74
74
75
75
let preferences : PreferencesAccess ;
76
76
77
+ let getTrackingUserInfoStub : Sinon . SinonStubbedMember <
78
+ typeof util . getTrackingUserInfo
79
+ > ;
80
+
81
+ before ( function ( ) {
82
+ getTrackingUserInfoStub = sandbox . stub ( util , 'getTrackingUserInfo' ) ;
83
+ } ) ;
84
+
77
85
beforeEach ( async function ( ) {
78
86
AtlasService [ 'ipcMain' ] = {
79
87
handle : sandbox . stub ( ) ,
@@ -114,8 +122,15 @@ describe('AtlasServiceMain', function () {
114
122
sandbox . resetHistory ( ) ;
115
123
} ) ;
116
124
125
+ after ( function ( ) {
126
+ sandbox . restore ( ) ;
127
+ } ) ;
128
+
117
129
describe ( 'signIn' , function ( ) {
118
130
it ( 'should sign in using oidc plugin' , async function ( ) {
131
+ const atlasUid = 'abcdefgh' ;
132
+ getTrackingUserInfoStub . returns ( { auid : atlasUid } ) ;
133
+
119
134
const userInfo = await AtlasService . signIn ( ) ;
120
135
expect (
121
136
mockOidcPlugin . mongoClientOptions . authMechanismProperties
@@ -124,6 +139,9 @@ describe('AtlasServiceMain', function () {
124
139
// proper error message from oidc plugin in case of failed sign in
125
140
) . to . have . been . calledTwice ;
126
141
expect ( userInfo ) . to . have . property ( 'sub' , '1234' ) ;
142
+ expect ( preferences . getPreferences ( ) . telemetryAtlasUserId ) . to . equal (
143
+ atlasUid
144
+ ) ;
127
145
} ) ;
128
146
129
147
it ( 'should debounce inflight sign in requests' , async function ( ) {
@@ -522,19 +540,6 @@ describe('AtlasServiceMain', function () {
522
540
} ) ;
523
541
} ) ;
524
542
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
-
538
543
describe ( 'setupAIAccess' , function ( ) {
539
544
beforeEach ( async function ( ) {
540
545
await preferences . savePreferences ( {
0 commit comments