Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/rtn-web-browser/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module.exports = {
...require('../../jest.config'),
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
branches: 25,
functions: 25,
lines: 35,
statements: 35,
},
},
};
2 changes: 1 addition & 1 deletion packages/rtn-web-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"access": "public"
},
"scripts": {
"test": "echo 'no-op'",
"test": "jest -w 1 --coverage --logHeapUsage",
"test:android": "./android/gradlew test -p ./android",
"build-with-test": "npm run clean && npm test && tsc",
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Platform } from 'react-native';

import { nativeModule } from '../../nativeModule';
import { isChromebook, openAuthSessionAsync } from '../openAuthSessionAsync';

jest.mock('react-native', () => ({
Platform: { OS: 'ios' },
AppState: { addEventListener: jest.fn() },
Linking: { addEventListener: jest.fn() },
NativeModules: {},
}));

jest.mock('../../nativeModule', () => ({
nativeModule: { openAuthSessionAsync: jest.fn() },
}));

const mockPlatform = Platform as jest.Mocked<typeof Platform>;
const mockNativeModule = nativeModule as jest.Mocked<typeof nativeModule>;

describe('openAuthSessionAsync', () => {
beforeEach(() => {
jest.clearAllMocks();
mockPlatform.OS = 'ios';
});

describe('isChromebook', () => {
it('returns false by default', async () => {
const result = await isChromebook();
expect(result).toBe(false);
});
});

describe('openAuthSessionAsync', () => {
it('enforces HTTPS on URLs', async () => {
mockNativeModule.openAuthSessionAsync.mockResolvedValue('result');

await openAuthSessionAsync('http://example.com', ['myapp://callback']);

expect(mockNativeModule.openAuthSessionAsync).toHaveBeenCalledWith(
'https://example.com',
'myapp://callback',
false,
);
});

it('calls iOS implementation', async () => {
mockNativeModule.openAuthSessionAsync.mockResolvedValue('result');

const result = await openAuthSessionAsync(
'https://example.com',
['myapp://callback'],
true,
);

expect(result).toBe('result');
expect(mockNativeModule.openAuthSessionAsync).toHaveBeenCalledWith(
'https://example.com',
'myapp://callback',
true,
);
});

it('finds first non-web URL for redirect', async () => {
const redirectUrls = ['https://web.com', 'myapp://deep'];

await openAuthSessionAsync('https://example.com', redirectUrls);

expect(mockNativeModule.openAuthSessionAsync).toHaveBeenCalledWith(
'https://example.com',
'myapp://deep',
false,
);
});
});
});
Loading