1- import { WorkOS } from './index.public' ;
1+ import { userManagement , sso , webhooks , actions } from './index.public' ;
22
3- describe ( 'WorkOS Public API' , ( ) => {
4- let workosPublic : WorkOS ;
5-
6- beforeEach ( ( ) => {
7- workosPublic = new WorkOS ( {
8- clientId : 'client_123' ,
9- apiHostname : 'api.workos.dev' ,
10- } ) ;
11- } ) ;
12-
13- describe ( 'instantiation' , ( ) => {
14- it ( 'should instantiate without requiring an API key' , ( ) => {
15- expect ( ( ) => new WorkOS ( ) ) . not . toThrow ( ) ;
16- } ) ;
17-
18- it ( 'should accept public configuration options' , ( ) => {
19- const client = new WorkOS ( {
20- clientId : 'test_client' ,
21- apiHostname : 'test.api.com' ,
22- https : false ,
23- port : 3000 ,
24- } ) ;
25-
26- expect ( client ) . toBeDefined ( ) ;
27- expect ( client . version ) . toBeDefined ( ) ;
28- } ) ;
29- } ) ;
30-
31- describe ( 'exposed services' , ( ) => {
32- it ( 'should expose webhooks service' , ( ) => {
33- expect ( workosPublic . webhooks ) . toBeDefined ( ) ;
34- expect ( workosPublic . webhooks . verifyHeader ) . toBeDefined ( ) ;
35- expect ( workosPublic . webhooks . computeSignature ) . toBeDefined ( ) ;
36- expect ( workosPublic . webhooks . constructEvent ) . toBeDefined ( ) ;
37- } ) ;
38-
39- it ( 'should expose actions service' , ( ) => {
40- expect ( workosPublic . actions ) . toBeDefined ( ) ;
41- expect ( workosPublic . actions . verifyHeader ) . toBeDefined ( ) ;
42- expect ( workosPublic . actions . signResponse ) . toBeDefined ( ) ;
43- expect ( workosPublic . actions . constructAction ) . toBeDefined ( ) ;
3+ describe ( 'Public Exports' , ( ) => {
4+ describe ( 'userManagement exports' , ( ) => {
5+ it ( 'should expose getAuthorizationUrl' , ( ) => {
6+ expect ( userManagement . getAuthorizationUrl ) . toBeDefined ( ) ;
7+ expect ( typeof userManagement . getAuthorizationUrl ) . toBe ( 'function' ) ;
448 } ) ;
459
46- it ( 'should expose client-safe user management methods' , ( ) => {
47- expect ( workosPublic . userManagement ) . toBeDefined ( ) ;
48- expect (
49- workosPublic . userManagement . authenticateWithCodeAndVerifier ,
50- ) . toBeDefined ( ) ;
51- expect ( workosPublic . userManagement . getAuthorizationUrl ) . toBeDefined ( ) ;
52- expect ( workosPublic . userManagement . getLogoutUrl ) . toBeDefined ( ) ;
53- expect ( workosPublic . userManagement . getJwksUrl ) . toBeDefined ( ) ;
10+ it ( 'should expose getLogoutUrl' , ( ) => {
11+ expect ( userManagement . getLogoutUrl ) . toBeDefined ( ) ;
12+ expect ( typeof userManagement . getLogoutUrl ) . toBe ( 'function' ) ;
5413 } ) ;
5514
56- it ( 'should expose client-safe SSO methods ' , ( ) => {
57- expect ( workosPublic . sso ) . toBeDefined ( ) ;
58- expect ( workosPublic . sso . getAuthorizationUrl ) . toBeDefined ( ) ;
15+ it ( 'should expose getJwksUrl ' , ( ) => {
16+ expect ( userManagement . getJwksUrl ) . toBeDefined ( ) ;
17+ expect ( typeof userManagement . getJwksUrl ) . toBe ( 'function' ) ;
5918 } ) ;
6019
61- it ( 'should expose version' , ( ) => {
62- expect ( workosPublic . version ) . toBeDefined ( ) ;
63- expect ( typeof workosPublic . version ) . toBe ( 'string' ) ;
64- } ) ;
65- } ) ;
66-
67- describe ( 'method behavior' , ( ) => {
68- it ( 'should be able to call URL generation methods' , ( ) => {
69- const authUrl = workosPublic . userManagement . getAuthorizationUrl ( {
20+ it ( 'should generate authorization URLs correctly' , ( ) => {
21+ const url = userManagement . getAuthorizationUrl ( {
7022 clientId : 'client_123' ,
7123 redirectUri : 'https://example.com/callback' ,
72- provider : 'GoogleOAuth ' ,
24+ provider : 'authkit ' ,
7325 } ) ;
7426
75- expect ( authUrl ) . toContain ( 'api.workos.dev' ) ;
76- expect ( authUrl ) . toContain ( 'client_id=client_123' ) ;
77- expect ( authUrl ) . toContain ( 'provider=GoogleOAuth' ) ;
78- } ) ;
79-
80- it ( 'should be able to call JWKS URL generation' , ( ) => {
81- const jwksUrl = workosPublic . userManagement . getJwksUrl ( 'client_123' ) ;
82- expect ( jwksUrl ) . toBe ( 'https://api.workos.dev/sso/jwks/client_123' ) ;
27+ expect ( url ) . toContain ( 'client_id=client_123' ) ;
28+ expect ( url ) . toContain ( 'redirect_uri=https%3A%2F%2Fexample.com%2Fcallback' ) ;
29+ expect ( url ) . toContain ( 'provider=authkit' ) ;
8330 } ) ;
8431
85- it ( 'should be able to call logout URL generation ' , ( ) => {
86- const logoutUrl = workosPublic . userManagement . getLogoutUrl ( {
32+ it ( 'should generate logout URLs correctly ' , ( ) => {
33+ const url = userManagement . getLogoutUrl ( {
8734 sessionId : 'session_123' ,
8835 returnTo : 'https://example.com' ,
8936 } ) ;
9037
91- expect ( logoutUrl ) . toContain ( 'api.workos.dev ' ) ;
92- expect ( logoutUrl ) . toContain ( 'session_id=session_123 ' ) ;
38+ expect ( url ) . toContain ( 'session_id=session_123 ' ) ;
39+ expect ( url ) . toContain ( 'return_to=https%3A%2F%2Fexample.com ' ) ;
9340 } ) ;
9441
95- it ( 'should be able to call SSO authorization URL generation' , ( ) => {
96- const authUrl = workosPublic . sso . getAuthorizationUrl ( {
97- clientId : 'client_123' ,
98- redirectUri : 'https://example.com/callback' ,
99- provider : 'GoogleOAuth' ,
100- } ) ;
101-
102- expect ( authUrl ) . toContain ( 'api.workos.dev' ) ;
103- expect ( authUrl ) . toContain ( 'client_id=client_123' ) ;
42+ it ( 'should generate JWKS URLs correctly' , ( ) => {
43+ const url = userManagement . getJwksUrl ( 'client_123' ) ;
44+ expect ( url ) . toBe ( 'https://api.workos.com/sso/jwks/client_123' ) ;
10445 } ) ;
10546 } ) ;
10647
107- describe ( 'server-only methods should not be exposed' , ( ) => {
108- it ( 'should not expose getUser on userManagement' , ( ) => {
109- expect ( ( workosPublic . userManagement as any ) . getUser ) . toBeUndefined ( ) ;
110- } ) ;
111-
112- it ( 'should not expose createUser on userManagement' , ( ) => {
113- expect ( ( workosPublic . userManagement as any ) . createUser ) . toBeUndefined ( ) ;
48+ describe ( 'sso exports' , ( ) => {
49+ it ( 'should expose getAuthorizationUrl' , ( ) => {
50+ expect ( sso . getAuthorizationUrl ) . toBeDefined ( ) ;
51+ expect ( typeof sso . getAuthorizationUrl ) . toBe ( 'function' ) ;
11452 } ) ;
11553
116- it ( 'should not expose listUsers on userManagement' , ( ) => {
117- expect ( ( workosPublic . userManagement as any ) . listUsers ) . toBeUndefined ( ) ;
118- } ) ;
54+ it ( 'should generate SSO authorization URLs correctly' , ( ) => {
55+ const url = sso . getAuthorizationUrl ( {
56+ clientId : 'client_123' ,
57+ redirectUri : 'https://example.com/callback' ,
58+ provider : 'GoogleOAuth' ,
59+ } ) ;
11960
120- it ( 'should not expose updateUser on userManagement' , ( ) => {
121- expect ( ( workosPublic . userManagement as any ) . updateUser ) . toBeUndefined ( ) ;
61+ expect ( url ) . toContain ( 'client_id=client_123' ) ;
62+ expect ( url ) . toContain ( 'provider=GoogleOAuth' ) ;
12263 } ) ;
64+ } ) ;
12365
124- it ( 'should not expose server-only authentication methods' , ( ) => {
125- expect (
126- ( workosPublic . userManagement as any ) . authenticateWithPassword ,
127- ) . toBeUndefined ( ) ;
128- expect (
129- ( workosPublic . userManagement as any ) . authenticateWithMagicAuth ,
130- ) . toBeUndefined ( ) ;
131- expect (
132- ( workosPublic . userManagement as any ) . authenticateWithRefreshToken ,
133- ) . toBeUndefined ( ) ;
66+ describe ( 'webhooks exports' , ( ) => {
67+ it ( 'should expose webhooks service' , ( ) => {
68+ expect ( webhooks ) . toBeDefined ( ) ;
69+ expect ( webhooks . verifyHeader ) . toBeDefined ( ) ;
70+ expect ( webhooks . computeSignature ) . toBeDefined ( ) ;
71+ expect ( webhooks . constructEvent ) . toBeDefined ( ) ;
13472 } ) ;
13573 } ) ;
13674
137- describe ( 'type safety' , ( ) => {
138- it ( 'should provide proper TypeScript types for exposed methods' , ( ) => {
139- // These should compile without errors
140- const authUrl : string = workosPublic . userManagement . getAuthorizationUrl ( {
141- clientId : 'test' ,
142- redirectUri : 'https://example.com' ,
143- provider : 'GoogleOAuth' ,
144- } ) ;
145-
146- const jwksUrl : string =
147- workosPublic . userManagement . getJwksUrl ( 'client_id' ) ;
148-
149- expect ( typeof authUrl ) . toBe ( 'string' ) ;
150- expect ( typeof jwksUrl ) . toBe ( 'string' ) ;
75+ describe ( 'actions exports' , ( ) => {
76+ it ( 'should expose actions service' , ( ) => {
77+ expect ( actions ) . toBeDefined ( ) ;
78+ expect ( actions . verifyHeader ) . toBeDefined ( ) ;
79+ expect ( actions . signResponse ) . toBeDefined ( ) ;
80+ expect ( actions . constructAction ) . toBeDefined ( ) ;
15181 } ) ;
15282 } ) ;
153- } ) ;
83+ } ) ;
0 commit comments