Skip to content

Commit

Permalink
Merge branch 'fix/recording-domains' into feat/rollout-remote-config-…
Browse files Browse the repository at this point in the history
…via-decide

# Conflicts:
#	posthog/api/decide.py
  • Loading branch information
benjackwhite committed Dec 16, 2024
2 parents a269518 + 8b5ad65 commit c20208d
Show file tree
Hide file tree
Showing 14 changed files with 1,049 additions and 911 deletions.
14 changes: 5 additions & 9 deletions cypress/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@

The Cypress tests run with a PostHog instance that has no feature flags set up.

To test feature flags you can intercept the call to the `decide` endpoint
To test feature flags you can intercept the call to the `decide` endpoint using this helper

```javascript
// sometimes the system under test calls `/decide`
// and sometimes it calls https://app.posthog.com/decide
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
// add feature flags here, for e.g.
// 'feature-flag-key': true,
})
)
)
setupFeatureFlags({
// add feature flags here, for e.g.
'feature-flag-key': true,
})
```
12 changes: 4 additions & 8 deletions cypress/e2e/alerts.cy.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { decideResponse } from '../fixtures/api/decide'
import { createInsight, createInsightWithBreakdown } from '../productAnalytics'
import { setupFeatureFlags } from '../support/decide'

describe('Alerts', () => {
beforeEach(() => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
alerts: true,
})
)
)
setupFeatureFlags({
alerts: true,
})
createInsight('insight')
})

Expand Down
13 changes: 5 additions & 8 deletions cypress/e2e/experiments.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

describe('Experiments', () => {
let randomNum
Expand Down Expand Up @@ -47,13 +47,10 @@ describe('Experiments', () => {
})

const createExperimentInNewUi = (): void => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
'new-experiments-ui': true,
})
)
)
setupFeatureFlags({
'new-experiments-ui': true,
})

cy.visit('/experiments')

// Name, flag key, description
Expand Down
12 changes: 4 additions & 8 deletions cypress/e2e/exports.cy.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { urls } from 'scenes/urls'

import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

// NOTE: As the API data is randomly generated, we are only really testing here that the overall output is correct
// The actual graph is not under test
describe('Exporting Insights', () => {
beforeEach(() => {
cy.intercept('https://us.i.posthog.com/decide/*', (req) =>
req.reply(
decideResponse({
'export-dashboard-insights': true,
})
)
)
setupFeatureFlags({
'export-dashboard-insights': true,
})
cy.visit(urls.insightNew())
// apply filter
cy.get('[data-attr$=add-filter-group]').click()
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/featureFlags.cy.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

describe('Feature Flags', () => {
let name

beforeEach(() => {
cy.intercept('**/decide/*', (req) => req.reply(decideResponse({})))
setupFeatureFlags({})

cy.intercept('/api/projects/*/property_definitions?type=person*', {
fixture: 'api/feature-flags/property_definition',
Expand Down
13 changes: 4 additions & 9 deletions cypress/e2e/onboarding.cy.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

describe('Onboarding', () => {
beforeEach(() => {
cy.intercept('/api/billing/', { fixture: 'api/billing/billing-unsubscribed.json' })

cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
'product-intro-pages': 'test',
})
)
)
setupFeatureFlags({
'product-intro-pages': 'test',
})
})

it('Navigate between /products to /onboarding to a product intro page', () => {
Expand Down
12 changes: 4 additions & 8 deletions cypress/e2e/signup.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from '../support/decide'

const VALID_PASSWORD = 'hedgE-hog-123%'

Expand Down Expand Up @@ -171,13 +171,9 @@ describe('Signup', () => {
})

it('Shows redirect notice if redirecting for maintenance', () => {
cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
'redirect-signups-to-instance': 'us',
})
)
)
setupFeatureFlags({
'redirect-signups-to-instance': 'us',
})

cy.visit('/logout')
cy.location('pathname').should('include', '/login')
Expand Down
1 change: 1 addition & 0 deletions cypress/fixtures/api/decide.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export function decideResponse(featureFlags) {
},
isAuthenticated: true,
supportedCompression: ['gzip', 'gzip-js', 'lz64'],
hasFeatureFlags: Object.keys(featureFlags).length > 0,
featureFlags,
sessionRecording: {
endpoint: '/s/',
Expand Down
28 changes: 28 additions & 0 deletions cypress/support/decide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { decideResponse } from '../fixtures/api/decide'

export const setupFeatureFlags = (overrides: Record<string, any> = {}): void => {
// Tricky - the new RemoteConfig endpoint is optimised to not load decide if there are no feature flags in the DB.
// We need to intercept both the RemoteConfig and the decide endpoint to ensure that the feature flags are always loaded.

cy.intercept('**/array/*/config', (req) =>
req.reply(
decideResponse({
...overrides,
})
)
)

cy.intercept('**/array/*/config.js', (req) =>
req.continue((res) => {
res.send(res.body)
})
)

cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
...overrides,
})
)
)
}
11 changes: 2 additions & 9 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'cypress-axe'

import { urls } from 'scenes/urls'

import { decideResponse } from '../fixtures/api/decide'
import { setupFeatureFlags } from './decide'

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -86,14 +86,7 @@ beforeEach(() => {
Cypress.env('POSTHOG_PROPERTY_GITHUB_ACTION_RUN_URL', process.env.GITHUB_ACTION_RUN_URL)
cy.useSubscriptionStatus('subscribed')

cy.intercept('**/decide/*', (req) =>
req.reply(
decideResponse({
// Feature flag to be treated as rolled out in E2E tests, e.g.:
// 'toolbar-launch-side-action': true,
})
)
)
setupFeatureFlags({})

// un-intercepted sometimes this doesn't work and the page gets stuck on the SpinnerOverlay
cy.intercept(/app.posthog.com\/api\/projects\/@current\/feature_flags\/my_flags.*/, (req) => req.reply([]))
Expand Down
1 change: 1 addition & 0 deletions frontend/src/loadPostHogJS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function loadPostHogJS(): void {
capture_copied_text: true,
},
person_profiles: 'always',
__preview_remote_config: true,

// Helper to capture events for assertions in Cypress
_onCapture: (window as any)._cypress_posthog_captures
Expand Down
4 changes: 2 additions & 2 deletions plugin-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
"repository": "https://github.com/PostHog/posthog-plugin-server",
"license": "MIT",
"dependencies": {
"@aws-sdk/client-s3": "^3.315.0",
"@aws-sdk/lib-storage": "^3.315.0",
"@aws-sdk/client-s3": "^3.709.0",
"@aws-sdk/lib-storage": "^3.709.0",
"@babel/core": "^7.18.10",
"@babel/plugin-transform-react-jsx": "^7.18.10",
"@babel/preset-env": "^7.18.10",
Expand Down
Loading

0 comments on commit c20208d

Please sign in to comment.