posthog-node 2.0.0-alpha6 → 2.0.0-alpha9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,7 +17,7 @@ const getLastBatchEvents = (): any[] | undefined => {
17
17
  return JSON.parse((call[1] as any).body as any).batch
18
18
  }
19
19
 
20
- describe('PostHog Core', () => {
20
+ describe('PostHog Node.js', () => {
21
21
  let posthog: PostHog
22
22
 
23
23
  jest.useFakeTimers()
@@ -37,7 +37,7 @@ describe('PostHog Core', () => {
37
37
  } as any)
38
38
  })
39
39
 
40
- describe('legacy methods', () => {
40
+ describe('core methods', () => {
41
41
  it('should capture an event to shared queue', async () => {
42
42
  expect(mockedUndici.fetch).toHaveBeenCalledTimes(0)
43
43
  posthog.capture({ distinctId: '123', event: 'test-event', properties: { foo: 'bar' }, groups: { org: 123 } })
@@ -89,4 +89,49 @@ describe('PostHog Core', () => {
89
89
  ])
90
90
  })
91
91
  })
92
+
93
+ describe('feature flags', () => {
94
+ beforeEach(() => {
95
+ const mockFeatureFlags = {
96
+ 'feature-1': true,
97
+ 'feature-2': true,
98
+ 'feature-variant': 'variant',
99
+ }
100
+
101
+ mockedUndici.fetch.mockImplementation((url) => {
102
+ if ((url as any).includes('/decide/')) {
103
+ return Promise.resolve({
104
+ status: 200,
105
+ text: () => Promise.resolve('ok'),
106
+ json: () =>
107
+ Promise.resolve({
108
+ featureFlags: mockFeatureFlags,
109
+ }),
110
+ }) as any
111
+ }
112
+
113
+ return Promise.resolve({
114
+ status: 200,
115
+ text: () => Promise.resolve('ok'),
116
+ json: () =>
117
+ Promise.resolve({
118
+ status: 'ok',
119
+ }),
120
+ }) as any
121
+ })
122
+ })
123
+
124
+ it('should do getFeatureFlag', async () => {
125
+ expect(mockedUndici.fetch).toHaveBeenCalledTimes(0)
126
+ await expect(posthog.getFeatureFlag('feature-variant', '123', { org: '123' })).resolves.toEqual('variant')
127
+ expect(mockedUndici.fetch).toHaveBeenCalledTimes(1)
128
+ })
129
+
130
+ it('should do isFeatureEnabled', async () => {
131
+ expect(mockedUndici.fetch).toHaveBeenCalledTimes(0)
132
+ await expect(posthog.isFeatureEnabled('feature-1', '123', false, { org: '123' })).resolves.toEqual(true)
133
+ await expect(posthog.isFeatureEnabled('feature-4', '123', false, { org: '123' })).resolves.toEqual(false)
134
+ expect(mockedUndici.fetch).toHaveBeenCalledTimes(2)
135
+ })
136
+ })
92
137
  })