Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite committed Dec 3, 2024
1 parent 676fdbd commit 6a14322
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
21 changes: 6 additions & 15 deletions src/__tests__/posthog-core.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Decide } from '../decide'

import { Info } from '../utils/event-utils'
import { document, window } from '../utils/globals'
import { uuidv7 } from '../uuidv7'
Expand All @@ -15,8 +13,6 @@ import { RequestQueue } from '../request-queue'
import { SessionRecording } from '../extensions/replay/sessionrecording'
import { PostHogFeatureFlags } from '../posthog-featureflags'

jest.mock('../decide')

describe('posthog core', () => {
const baseUTCDateTime = new Date(Date.UTC(2020, 0, 1, 0, 0, 0))
const eventName = '$event'
Expand Down Expand Up @@ -1141,21 +1137,15 @@ describe('posthog core', () => {
})

describe('/decide', () => {
beforeEach(() => {
const call = jest.fn()
;(Decide as any).mockImplementation(() => ({ call }))
})

afterEach(() => {
;(Decide as any).mockReset()
})

it('is called by default', async () => {
const instance = await createPosthogInstance(uuidv7())
instance.featureFlags.setReloadingPaused = jest.fn()
instance._send_request = jest.fn()
instance._loaded()

expect(new Decide(instance).call).toHaveBeenCalled()
expect(instance._send_request.mock.calls[0][0]).toMatchObject({
url: 'http://localhost/decide/?v=3',
})
expect(instance.featureFlags.setReloadingPaused).toHaveBeenCalledWith(true)
})

Expand All @@ -1164,9 +1154,10 @@ describe('posthog core', () => {
advanced_disable_decide: true,
})
instance.featureFlags.setReloadingPaused = jest.fn()
instance._send_request = jest.fn()
instance._loaded()

expect(new Decide(instance).call).not.toHaveBeenCalled()
expect(instance._send_request).not.toHaveBeenCalled()
expect(instance.featureFlags.setReloadingPaused).not.toHaveBeenCalled()
})
})
Expand Down
4 changes: 4 additions & 0 deletions src/decide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export class Decide {
return
}

if (disableRemoteCalls) {
return
}

/*
Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.
*/
Expand Down

0 comments on commit 6a14322

Please sign in to comment.