Skip to content

Commit

Permalink
Add env var for test mode (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos authored Oct 2, 2024
1 parent 9a736fb commit da49993
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/CroctProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('<CroctProvider />', () => {

delete process.env.NEXT_PUBLIC_CROCT_APP_ID;
delete process.env.NEXT_PUBLIC_CROCT_DEBUG;
delete process.env.NEXT_PUBLIC_CROCT_TEST;
delete process.env.NEXT_PUBLIC_CROCT_BASE_ENDPOINT_URL;
delete process.env.NEXT_PUBLIC_CROCT_DEFAULT_FETCH_TIMEOUT;
delete process.env.NEXT_PUBLIC_CROCT_DEFAULT_PREFERRED_LOCALE;
Expand Down Expand Up @@ -69,13 +70,15 @@ describe('<CroctProvider />', () => {
it('should allow overriding the environment configuration', () => {
process.env.NEXT_PUBLIC_CROCT_APP_ID = '00000000-0000-0000-0000-000000000000';
process.env.NEXT_PUBLIC_CROCT_DEBUG = 'true';
process.env.NEXT_PUBLIC_CROCT_TEST = 'true';
process.env.NEXT_PUBLIC_CROCT_BASE_ENDPOINT_URL = 'https://example.com';
process.env.NEXT_PUBLIC_CROCT_DEFAULT_FETCH_TIMEOUT = '3000';
process.env.NEXT_PUBLIC_CROCT_DEFAULT_PREFERRED_LOCALE = 'es';

const config = {
appId: '11111111-1111-1111-1111-111111111111',
debug: false,
test: false,
baseEndpointUrl: 'https://override.com',
defaultFetchTimeout: 2000,
defaultPreferredLocale: 'en',
Expand All @@ -101,6 +104,7 @@ describe('<CroctProvider />', () => {
{
appId: config.appId,
debug: config.debug,
test: config.test,
cookie: config.cookie,
baseEndpointUrl: config.baseEndpointUrl,
defaultFetchTimeout: config.defaultFetchTimeout,
Expand Down Expand Up @@ -138,6 +142,20 @@ describe('<CroctProvider />', () => {
);
});

it('should detect the test mode from the environment', () => {
process.env.NEXT_PUBLIC_CROCT_APP_ID = '00000000-0000-0000-0000-000000000000';
process.env.NEXT_PUBLIC_CROCT_TEST = 'true';

render(<CroctProvider />);

expect(UnderlyingProvider).toHaveBeenCalledWith<[ResolvedProviderProps, any]>(
expect.objectContaining({
test: true,
}),
expect.anything(),
);
});

it('should detect the base endpoint URL from the environment', () => {
process.env.NEXT_PUBLIC_CROCT_APP_ID = '00000000-0000-0000-0000-000000000000';
process.env.NEXT_PUBLIC_CROCT_BASE_ENDPOINT_URL = 'https://example.com';
Expand Down
1 change: 1 addition & 0 deletions src/CroctProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const CroctProvider: FunctionComponent<CroctProviderProps> = props => {
appId={appId}
disableCidMirroring
{...getEnvEntryFlag('debug', process.env.NEXT_PUBLIC_CROCT_DEBUG)}
{...getEnvEntryFlag('test', process.env.NEXT_PUBLIC_CROCT_TEST)}
{...getEnvEntry('baseEndpointUrl', process.env.NEXT_PUBLIC_CROCT_BASE_ENDPOINT_URL)}
{...getEnvEntry('defaultPreferredLocale', process.env.NEXT_PUBLIC_CROCT_DEFAULT_PREFERRED_LOCALE)}
{...(defaultTimeout !== undefined ? {defaultFetchTimeout: defaultTimeout} : {})}
Expand Down

0 comments on commit da49993

Please sign in to comment.