Skip to content

Commit

Permalink
fix sign up test
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Oct 11, 2023
1 parent 4a9f51e commit 5f3da5e
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 99 deletions.
25 changes: 16 additions & 9 deletions cypress/e2e/signup.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,28 @@ describe('Signup', () => {
cy.get('.Toastify [data-attr="error-toast"]').contains('Inactive social login session.')
})

// skip this because it seems to be missing necessary setup feature flag, preflight cloud check...
it.skip('Shows redirect notice if redirecting for maintenance', () => {
cy.visit('/logout')
cy.location('pathname').should('include', '/login')
it('Shows redirect notice if redirecting for maintenance', () => {
cy.intercept('https://app.posthog.com/decide/*', (req) =>
req.reply(
decideResponse({
'redirect-signups-to-instance': 'us',
})
)
)
cy.visit('/signup?maintenanceRedirect=true')
cy.get('.Toastify__toast-body').should(
'contain',
`You have been redirected to signup on our US instance while we perform maintenance on our other instance.`
)

cy.visit('/logout')
cy.location('pathname').should('include', '/login')

cy.visit('/signup?maintenanceRedirect=true', {
onLoad(win: Cypress.AUTWindow) {
win.POSTHOG_APP_CONTEXT.preflight.cloud = true
},
})

cy.get('[data-attr="info-toast"]')
.contains(
`You've been redirected to signup on our US instance while we perform maintenance on our other instance.`
)
.should('be.visible')
})
})
5 changes: 3 additions & 2 deletions frontend/src/lib/components/Support/supportLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getSessionReplayLink(): string {

function getDjangoAdminLink(
user: UserType | null,
cloudRegion: Region | undefined,
cloudRegion: Region | null | undefined,
currentTeamId: TeamType['id'] | null
): string {
if (!user || !cloudRegion) {
Expand All @@ -33,7 +33,7 @@ function getDjangoAdminLink(
return `Admin: ${link} (Organization: '${user.organization?.name}'; Project: ${currentTeamId}:'${user.team?.name}')`
}

function getSentryLink(user: UserType | null, cloudRegion: Region | undefined): string {
function getSentryLink(user: UserType | null, cloudRegion: Region | null | undefined): string {
if (!user || !cloudRegion) {
return ''
}
Expand Down Expand Up @@ -209,6 +209,7 @@ export const supportLogic = kea<supportLogicType>([
zendesk_ticket_uuid +
')'
const cloudRegion = preflightLogic.values.preflight?.region

const payload = {
request: {
requester: { name: name, email: email },
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ export function objectsEqual(obj1: any, obj2: any): boolean {
return equal(obj1, obj2)
}

export function isString(candidate: unknown): candidate is string {
return typeof candidate === 'string'
}

export function isObject(candidate: unknown): candidate is Record<string, unknown> {
return typeof candidate === 'object' && candidate !== null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { CLOUD_HOSTNAMES, FEATURE_FLAGS } from 'lib/constants'
import { lemonToast } from '@posthog/lemon-ui'
import { urls } from 'scenes/urls'
import { isString } from '@tiptap/core'

export interface AccountResponse {
success: boolean
Expand Down Expand Up @@ -107,8 +108,20 @@ export const signupLogic = kea<signupLogicType>([
if (values.preflight?.cloud) {
// Redirect to a different region if we are doing maintenance on one of them
const regionOverrideFlag = values.featureFlags[FEATURE_FLAGS.REDIRECT_SIGNUPS_TO_INSTANCE]
const isRegionOverrideValid = regionOverrideFlag === 'eu' || regionOverrideFlag === 'us'
if (isRegionOverrideValid && regionOverrideFlag !== values.preflight?.region.toLowerCase()) {
const regionsAllowList = ['eu', 'us']
const isRegionOverrideValid =
isString(regionOverrideFlag) && regionsAllowList.includes(regionOverrideFlag)
// KLUDGE: the backend can technically return null
// but definitely does in Cypress tests
// and, we don't want to redirect to the app unless the preflight region is valid
const isPreflightRegionValid =
values.preflight?.region && regionsAllowList.includes(values.preflight?.region)

if (
isRegionOverrideValid &&
isPreflightRegionValid &&
regionOverrideFlag !== values.preflight?.region?.toLowerCase()
) {
window.location.href = `https://${
CLOUD_HOSTNAMES[regionOverrideFlag.toUpperCase()]
}${urls.signup()}?maintenanceRedirect=true`
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2317,7 +2317,7 @@ export interface PreflightStatus {
demo: boolean
celery: boolean
realm: Realm
region: Region
region: Region | null
available_social_auth_providers: AuthBackends
available_timezones?: Record<string, number>
opt_out_capture?: boolean
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@
"concurrently": "^5.3.0",
"css-loader": "^3.4.2",
"cssnano": "^4.1.10",
"cypress": "^12.12.0",
"cypress-axe": "^1.4.0",
"cypress-terminal-report": "^5.1.1",
"cypress": "^13.3.0",
"cypress-axe": "^1.5.0",
"cypress-terminal-report": "^5.3.7",
"eslint": "^7.8.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-compat": "^4.2.0",
Expand Down
Loading

0 comments on commit 5f3da5e

Please sign in to comment.