Skip to content

Commit 5b55fe7

Browse files
RahulHereRahulHere
authored andcommitted
Resolve test failures: scope isolation, error imports, config validation order (#9)
- Add export {} to 5 test files to isolate variable scope (TS2451) - Move error class imports outside native availability check in gopher-auth.test.ts (InsufficientScopesError/TokenValidationError) - Move config validation before native lib init in gopher-auth.ts so ConfigurationError is thrown before generic Error
1 parent babdb34 commit 5b55fe7

7 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/auth/gopher-auth.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ export class GopherAuth {
5757
return;
5858
}
5959

60+
// Validate configuration before loading native library
61+
if (!this._options.configPath && !this._options.config) {
62+
throw new ConfigurationError(
63+
'Either configPath or config must be provided'
64+
);
65+
}
66+
6067
gopherInitAuthLibrary();
6168

6269
// Load configuration
@@ -82,28 +89,27 @@ export class GopherAuth {
8289
if (c.jwksCacheDuration)
8390
pairs['jwks_cache_duration'] = String(c.jwksCacheDuration);
8491
this._config = GopherAuthConfig.loadFromPairs(pairs);
85-
} else {
86-
throw new ConfigurationError(
87-
'Either configPath or config must be provided'
88-
);
8992
}
9093

94+
// _config is guaranteed non-null by the early validation check above
95+
const config = this._config!;
96+
9197
// Create auth client
92-
const jwksUri = this._config.getString('jwks_uri');
93-
const issuer = this._config.getString('issuer');
98+
const jwksUri = config.getString('jwks_uri');
99+
const issuer = config.getString('issuer');
94100
if (jwksUri && issuer) {
95101
this._authClient = new GopherAuthClient(jwksUri, issuer);
96102

97-
const cacheDuration = this._config.getString('jwks_cache_duration');
103+
const cacheDuration = config.getString('jwks_cache_duration');
98104
if (cacheDuration) {
99105
this._authClient.setOption('cache_duration', cacheDuration);
100106
}
101107
}
102108

103109
// Create OAuth client
104-
const tokenEndpoint = this._config.getString('token_endpoint');
105-
const clientId = this._config.getString('client_id');
106-
const clientSecret = this._config.getString('client_secret');
110+
const tokenEndpoint = config.getString('token_endpoint');
111+
const clientId = config.getString('client_id');
112+
const clientSecret = config.getString('client_secret');
107113
if (tokenEndpoint && clientId) {
108114
this._oauthClient = new GopherOAuthClient(
109115
tokenEndpoint,

tests/auto-refresh.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export {};
2+
13
/**
24
* Tests for gopherAuthAutoRefresh FFI binding
35
*/

tests/gopher-auth.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ let TokenValidationError: typeof import('../src/auth/errors').TokenValidationErr
1515
let ConfigurationError: typeof import('../src/auth/errors').ConfigurationError;
1616
let nativeAvailable = false;
1717

18+
// Error classes are pure JS — load unconditionally
19+
const errors = require('../src/auth/errors');
20+
InsufficientScopesError = errors.InsufficientScopesError;
21+
TokenValidationError = errors.TokenValidationError;
22+
ConfigurationError = errors.ConfigurationError;
23+
1824
try {
1925
const loader = require('../src/ffi/auth/loader');
2026
nativeAvailable = loader.loadLibrary();
@@ -24,10 +30,6 @@ try {
2430
hasScope = helpers.hasScope;
2531
hasAllScopes = helpers.hasAllScopes;
2632
hasAnyScope = helpers.hasAnyScope;
27-
const errors = require('../src/auth/errors');
28-
InsufficientScopesError = errors.InsufficientScopesError;
29-
TokenValidationError = errors.TokenValidationError;
30-
ConfigurationError = errors.ConfigurationError;
3133
}
3234
} catch {
3335
nativeAvailable = false;

tests/oauth-client.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export {};
2+
13
/**
24
* Tests for GopherOAuthClient FFI binding
35
*/

tests/session-manager.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export {};
2+
13
/**
24
* Tests for GopherSessionManager FFI binding
35
*/

tests/url-metadata-http.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export {};
2+
13
/**
24
* Tests for URL Utils, Metadata Builders, and HTTP Parsing FFI bindings
35
*/

tests/validation.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export {};
2+
13
/**
24
* Tests for IDP and multi-scope validation FFI bindings
35
*/

0 commit comments

Comments
 (0)