File tree Expand file tree Collapse file tree 2 files changed +21
-11
lines changed
packages/compass-intercom/src Expand file tree Collapse file tree 2 files changed +21
-11
lines changed Original file line number Diff line number Diff line change 22import type { SinonStub } from 'sinon' ;
33import sinon from 'sinon' ;
44
5- import { setupIntercom } from './setup-intercom' ;
5+ import { setupIntercom , resetIntercomAllowedCache } from './setup-intercom' ;
66import { expect } from 'chai' ;
77import type { IntercomScript } from './intercom-script' ;
88import type { PreferencesAccess } from 'compass-preferences-model' ;
@@ -100,6 +100,7 @@ describe('setupIntercom', function () {
100100 process . env . HADRON_APP_VERSION = backupEnv . HADRON_APP_VERSION as any ;
101101 process . env . NODE_ENV = backupEnv . NODE_ENV ;
102102 fetchMock . restore ( ) ;
103+ resetIntercomAllowedCache ( ) ;
103104 } ) ;
104105
105106 describe ( 'when it can be enabled' , function ( ) {
Original file line number Diff line number Diff line change @@ -89,17 +89,26 @@ export async function setupIntercom(
8989 ) ;
9090}
9191
92+ let isIntercomAllowedPromise : Promise < boolean > | null = null ;
93+
9294function isIntercomAllowed ( ) : Promise < boolean > {
93- return fetchIntegrations ( ) . then (
94- ( { intercom } ) => intercom ,
95- ( error ) => {
96- debug (
97- 'Failed to fetch intercom integration status, defaulting to false' ,
98- { error }
99- ) ;
100- return false ;
101- }
102- ) ;
95+ if ( ! isIntercomAllowedPromise ) {
96+ isIntercomAllowedPromise = fetchIntegrations ( ) . then (
97+ ( { intercom } ) => intercom ,
98+ ( error ) => {
99+ debug (
100+ 'Failed to fetch intercom integration status, defaulting to false' ,
101+ { error }
102+ ) ;
103+ return false ;
104+ }
105+ ) ;
106+ }
107+ return isIntercomAllowedPromise ;
108+ }
109+
110+ export function resetIntercomAllowedCache ( ) : void {
111+ isIntercomAllowedPromise = null ;
103112}
104113
105114/**
You can’t perform that action at this time.
0 commit comments