mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
I added the "Do you know how to code?" question (Yes / No, optional) to the onboarding survey on the new organization form and in the follow-up dialog. The answer is sent as `can_code` in the same survey request as the other answers. I removed an earlier version of this question before the survey shipped because the platform didn't store it; the platform now accepts `can_code`. **Changed:** - **New question, always visible**: it shows on both surfaces without waiting on another answer, so it can be answered on its own. Only the `org_form` arm of the experiment shows the survey. - **Follow-up dialog shows every question at once**: "What are you building?" used to appear only after "Who is this org for?" was answered. "How many people?" still appears only for the Company org type. - **Follow-up card above other banners**: I raised its priority in the banner stack so it sits in front of the project-page cards for its five-minute window. - **Telemetry**: I added a `hasCanCode` boolean to `onboarding_survey_submit_button_clicked` and `onboarding_survey_submit_failed`. **Note:** Merge only after the platform change that accepts `can_code` is in production: before that, the API drops the key and still returns 204, so answers are lost with no error. The change is live once `can_code` is listed under `OnboardingSurveyBody` in the production platform OpenAPI spec. I widened `OnboardingSurveyBody` locally because `packages/api-types` can only be regenerated once the production spec has the field. ## To test Setup: sign in and set the `onboardingSurveyPlacement` flag to `org_form` with the dev toolbar. Tested on the PR preview: - [x] Open `/new`: expect "Do you know how to code?" below "What are you building?" with Yes then No, before any other question is answered. Answer both and create the org: expect one `POST /platform/organizations/onboarding-survey` whose body has `building` and `can_code`. Observed: both questions on the untouched form, options Yes then No; one request, 204, body has `"can_code":"yes"`. - [x] Create an org with only "Do you know how to code?" answered: expect one request whose body has `can_code` and no `building` key. Observed: one request, 204, `"can_code":"no"`, no `building` key, and no follow-up card on the new org's page. - [x] Create an org with the org type changed to Company, a size picked and "Do you know how to code?" answered, leaving "What are you building?" blank: expect one request with `kind`, `size` and `can_code`, and no follow-up card on the new org's page. Observed: one request, 204, `"kind":"COMPANY","size":"50","can_code":"yes"`; no follow-up card. - [x] Create an org with "What are you building?" answered and the new question left blank: expect the request body to have no `can_code` key, and the org to be created. Observed: one request, 204, no `can_code` key. - [x] Create an org without touching the survey, then open the new org's page: expect the "Help improve Supabase" card. Click Answer: expect all three questions in the dialog right away. Answer all three questions and send: expect one request with `kind`, `building` and `can_code`. Observed: no survey request at creation; the card shows on the org page; the dialog opens with all three questions blank; one request, 204, body has `"can_code":"yes"`. - [x] Set the flag to `control` and open `/new`: expect no survey questions. Observed: none of the survey questions render. - [x] Added check: `onboarding_survey_submit_button_clicked` carries `hasCanCode`. Observed: `true` when answered on both surfaces, `false` when left blank. ## Linear - fixes GROWTH-1487
66 lines
2.2 KiB
TypeScript
66 lines
2.2 KiB
TypeScript
import { platformComponents as components } from 'api-types'
|
|
import { HttpResponse } from 'msw'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { submitOnboardingSurvey } from './onboarding-survey-mutation'
|
|
import { addAPIMock, type APIErrorBody } from '@/tests/lib/msw'
|
|
|
|
type OnboardingSurveyBody = components['schemas']['OnboardingSurveyBody']
|
|
|
|
const mockSurveyEndpoint = (status: 204 | 500 = 204) => {
|
|
const requests: OnboardingSurveyBody[] = []
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/organizations/onboarding-survey',
|
|
response: async ({ request }) => {
|
|
requests.push((await request.json()) as OnboardingSurveyBody)
|
|
if (status === 500) {
|
|
return HttpResponse.json<APIErrorBody>({ message: 'Boom' }, { status: 500 })
|
|
}
|
|
return new HttpResponse(null, { status: 204 })
|
|
},
|
|
})
|
|
return requests
|
|
}
|
|
|
|
describe('submitOnboardingSurvey', () => {
|
|
it('leaves unanswered questions out of the request', async () => {
|
|
const requests = mockSurveyEndpoint()
|
|
|
|
await submitOnboardingSurvey({ slug: 'acme', kind: 'COMPANY', size: '10', building: '' })
|
|
await submitOnboardingSurvey({ slug: 'acme', kind: ' ', building: ' b2b_saas ' })
|
|
|
|
expect(requests).toEqual([
|
|
{ slug: 'acme', kind: 'COMPANY', size: '10' },
|
|
{ slug: 'acme', building: 'b2b_saas' },
|
|
])
|
|
})
|
|
|
|
it('sends can_code in the same request as the other answers', async () => {
|
|
const requests = mockSurveyEndpoint()
|
|
|
|
await submitOnboardingSurvey({ slug: 'acme', building: 'b2b_saas', can_code: 'no' })
|
|
await submitOnboardingSurvey({ slug: 'acme', building: 'b2b_saas', can_code: '' })
|
|
|
|
expect(requests).toEqual([
|
|
{ slug: 'acme', building: 'b2b_saas', can_code: 'no' },
|
|
{ slug: 'acme', building: 'b2b_saas' },
|
|
])
|
|
})
|
|
|
|
it('rejects when the request fails, so callers can keep the answers', async () => {
|
|
mockSurveyEndpoint(500)
|
|
|
|
await expect(submitOnboardingSurvey({ slug: 'acme', kind: 'COMPANY' })).rejects.toThrow('Boom')
|
|
})
|
|
|
|
it('sends nothing without an org slug', async () => {
|
|
const requests = mockSurveyEndpoint()
|
|
|
|
await expect(submitOnboardingSurvey({ slug: '' })).rejects.toThrow(
|
|
'Organization slug is required'
|
|
)
|
|
expect(requests).toEqual([])
|
|
})
|
|
})
|