Skip to content

Commit 4c0b4b0

Browse files
committed
Update deriveInitialStep tests
1 parent f4c97d0 commit 4c0b4b0

1 file changed

Lines changed: 55 additions & 37 deletions

File tree

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { EnterpriseConnectionResource } from '@clerk/shared/types';
1+
import type { EnterpriseConnectionResource, SamlAccountConnectionResource } from '@clerk/shared/types';
22
import { describe, expect, it } from 'vitest';
33

44
import { deriveInitialStep } from '../deriveInitialStep';
@@ -25,65 +25,83 @@ const makeConnection = (overrides: Partial<EnterpriseConnectionResource> = {}):
2525
...overrides,
2626
}) as EnterpriseConnectionResource;
2727

28+
const makeSamlConnection = (overrides: Partial<SamlAccountConnectionResource> = {}): SamlAccountConnectionResource =>
29+
({
30+
id: 'saml_1',
31+
name: 'acme.com',
32+
active: false,
33+
idpEntityId: '',
34+
idpSsoUrl: '',
35+
idpCertificate: '',
36+
idpMetadataUrl: '',
37+
idpMetadata: '',
38+
acsUrl: 'https://clerk.example.com/acs',
39+
spEntityId: 'https://clerk.example.com',
40+
spMetadataUrl: 'https://clerk.example.com/sp-metadata',
41+
allowSubdomains: false,
42+
allowIdpInitiated: false,
43+
forceAuthn: false,
44+
...overrides,
45+
}) as SamlAccountConnectionResource;
46+
47+
const defaultOptions = { isDomainTakenByOtherOrg: false, hasSuccessfulTestRun: false };
48+
2849
describe('deriveInitialStep', () => {
29-
const cases: Array<{ name: string; input: EnterpriseConnectionResource | undefined; expected: WizardStepId }> = [
50+
const cases: Array<{
51+
name: string;
52+
input: EnterpriseConnectionResource | undefined;
53+
options?: Partial<typeof defaultOptions>;
54+
expected: WizardStepId;
55+
}> = [
56+
{
57+
name: 'domain taken by other org → verify-domain',
58+
input: makeConnection(),
59+
options: { isDomainTakenByOtherOrg: true },
60+
expected: 'verify-domain',
61+
},
3062
{
3163
name: 'no connection → select-provider',
3264
input: undefined,
3365
expected: 'select-provider',
3466
},
3567
{
36-
name: 'connection without samlConnection → configure',
37-
input: makeConnection({ samlConnection: null }),
68+
name: 'active connection → confirmation',
69+
input: makeConnection({ active: true, samlConnection: makeSamlConnection() }),
70+
expected: 'confirmation',
71+
},
72+
{
73+
name: 'connection with empty SAML IdP config → configure',
74+
input: makeConnection({ samlConnection: makeSamlConnection() }),
3875
expected: 'configure',
3976
},
4077
{
41-
name: 'connection with empty samlConnection.idpSsoUrl → configure',
78+
name: 'configured connection without successful test run → test',
4279
input: makeConnection({
43-
samlConnection: {
44-
id: 'saml_1',
45-
name: 'acme.com',
46-
active: false,
47-
idpEntityId: '',
48-
idpSsoUrl: '',
49-
idpCertificate: '',
50-
idpMetadataUrl: '',
51-
idpMetadata: '',
52-
acsUrl: 'https://clerk.example.com/acs',
53-
spEntityId: 'https://clerk.example.com',
54-
spMetadataUrl: 'https://clerk.example.com/sp-metadata',
55-
allowSubdomains: false,
56-
allowIdpInitiated: false,
57-
forceAuthn: false,
58-
},
80+
samlConnection: makeSamlConnection({
81+
idpEntityId: 'https://idp.example.com/entity',
82+
idpSsoUrl: 'https://idp.example.com/sso',
83+
idpCertificate: 'CERT',
84+
idpMetadataUrl: 'https://idp.example.com/metadata',
85+
}),
5986
}),
60-
expected: 'configure',
87+
expected: 'test',
6188
},
6289
{
63-
name: 'connection with samlConnection.idpSsoUrl populated → confirmation',
90+
name: 'configured connection with successful test run → confirmation',
6491
input: makeConnection({
65-
samlConnection: {
66-
id: 'saml_1',
67-
name: 'acme.com',
68-
active: true,
92+
samlConnection: makeSamlConnection({
6993
idpEntityId: 'https://idp.example.com/entity',
7094
idpSsoUrl: 'https://idp.example.com/sso',
7195
idpCertificate: 'CERT',
7296
idpMetadataUrl: 'https://idp.example.com/metadata',
73-
idpMetadata: '',
74-
acsUrl: 'https://clerk.example.com/acs',
75-
spEntityId: 'https://clerk.example.com',
76-
spMetadataUrl: 'https://clerk.example.com/sp-metadata',
77-
allowSubdomains: false,
78-
allowIdpInitiated: false,
79-
forceAuthn: false,
80-
},
97+
}),
8198
}),
99+
options: { hasSuccessfulTestRun: true },
82100
expected: 'confirmation',
83101
},
84102
];
85103

86-
it.each(cases)('$name', ({ input, expected }) => {
87-
expect(deriveInitialStep(input)).toBe(expected);
104+
it.each(cases)('$name', ({ input, options, expected }) => {
105+
expect(deriveInitialStep(input, { ...defaultOptions, ...options })).toBe(expected);
88106
});
89107
});

0 commit comments

Comments
 (0)