-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* changes configuration to implement frontendAPI and backendAPI * fixes tests * setting backend api in constructor * resolves comments * fixes test
- Loading branch information
Showing
9 changed files
with
56 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
CORBADO_PROJECT_ID=pro-xxxxxxxxxxxxxxxxxxx | ||
CORBADO_API_SECRET=corbado1_xxxxxxxxxxxxxxxxxxxxxxxxxx | ||
CORBADO_BACKEND_API=https://backendapi.cloud.corbado.io/v2 | ||
CORBADO_BACKEND_API=https://backendapi.cloud.corbado.io | ||
CORBADO_FRONTEND_API=https://[project-id].frontendapi.cloud.corbado.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,70 @@ | ||
import { DefaultBackendAPI, DefaultCacheMaxAge, DefaultShortSessionCookieName } from '../src/config.js'; | ||
import { DefaultCacheMaxAge, DefaultShortSessionCookieName } from '../src/config.js'; | ||
import { BaseError } from '../src/errors/index.js'; | ||
import { Config } from '../src/index.js'; | ||
|
||
describe('Configuration class', () => { | ||
let projectID: string; | ||
let apiSecret: string; | ||
let frontendAPI: string; | ||
let backendAPI: string; | ||
|
||
beforeEach(() => { | ||
projectID = process.env.CORBADO_PROJECT_ID as string; // necessary to mitigate TS error | ||
apiSecret = process.env.CORBADO_API_SECRET as string; // Same here | ||
frontendAPI = process.env.CORBADO_FRONTEND_API as string; // Same here | ||
backendAPI = process.env.CORBADO_BACKEND_API as string; // Same here | ||
|
||
if (!projectID || !apiSecret) { | ||
throw new BaseError('Env Error', 5001, 'Both projectID and apiSecret must be defined', true); | ||
} | ||
}); | ||
|
||
const createAndAssertConfig = (config: Config) => { | ||
expect(config).toBeInstanceOf(Config); | ||
expect(config.ProjectID).toBe(projectID); | ||
expect(config.APISecret).toBe(apiSecret); | ||
expect(config.FrontendAPI).toBe(`https://${projectID}.frontendapi.cloud.corbado.io`); | ||
expect(config.BackendAPI).toBe(DefaultBackendAPI); | ||
expect(config.BackendAPI).toBe(backendAPI); | ||
expect(config.ShortSessionCookieName).toBe(DefaultShortSessionCookieName); | ||
expect(config.CacheMaxAge).toBe(DefaultCacheMaxAge); | ||
}; | ||
|
||
it('should instantiate Configuration with valid project ID and API secret', () => { | ||
const config = new Config(projectID, apiSecret); | ||
it('should instantiate Configuration with valid project ID and API secret and APIs', () => { | ||
const config = new Config(projectID, apiSecret, frontendAPI, backendAPI); | ||
createAndAssertConfig(config); | ||
}); | ||
|
||
it('should assign default values to BackendAPI, ShortSessionCookieName, CacheMaxAge, and JWTIssuer', () => { | ||
const config = new Config(projectID, apiSecret); | ||
expect(config.BackendAPI).toBe(DefaultBackendAPI); | ||
const config = new Config(projectID, apiSecret, frontendAPI, backendAPI); | ||
expect(config.BackendAPI).toBe(backendAPI); | ||
expect(config.FrontendAPI).toBe(frontendAPI); | ||
expect(config.ShortSessionCookieName).toBe(DefaultShortSessionCookieName); | ||
expect(config.CacheMaxAge).toBe(DefaultCacheMaxAge); | ||
}); | ||
|
||
it('should generate DefaultFrontendAPI using process.env.CORBADO_PROJECT_ID and provided project ID', () => { | ||
const config = new Config(projectID, apiSecret); | ||
expect(config.FrontendAPI).toBe(`https://${projectID}.frontendapi.cloud.corbado.io`); | ||
}); | ||
|
||
it('should throw an error when instantiated with an invalid project ID', () => { | ||
expect(() => new Config('invalid', apiSecret)).toThrow('ProjectID must not be empty and must start with "pro-".'); | ||
expect(() => new Config('invalid', apiSecret, frontendAPI, backendAPI)).toThrow( | ||
'ProjectID must not be empty and must start with "pro-".', | ||
); | ||
}); | ||
|
||
it('should throw an error when instantiated with an invalid API secret', () => { | ||
expect(() => new Config(projectID, 'invalid')).toThrow( | ||
expect(() => new Config(projectID, 'invalid', frontendAPI, backendAPI)).toThrow( | ||
'APISecret must not be empty and must start with "corbado1_".', | ||
); | ||
}); | ||
|
||
it('should throw an error when project ID is undefined', () => { | ||
expect(() => new Config(undefined as unknown as string, apiSecret)).toThrow( | ||
expect(() => new Config(undefined as unknown as string, apiSecret, frontendAPI, backendAPI)).toThrow( | ||
'ProjectID must not be empty and must start with "pro-".', | ||
); | ||
}); | ||
|
||
it('should throw an error when frontendAPI is wrong', () => { | ||
expect(() => new Config(projectID, apiSecret, `${frontendAPI}/v2`, backendAPI)).toThrow('path needs to be empty'); | ||
}); | ||
|
||
it('should throw an error when backendAPI is wrong', () => { | ||
expect(() => new Config(projectID, apiSecret, frontendAPI, `${backendAPI}/v2`)).toThrow('path needs to be empty'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters