Skip to content

Commit 13e2eae

Browse files
committed
test(hooks): add test to ensure signIn can be called without redirectUri now
1 parent 5bcae4d commit 13e2eae

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/hooks/src/useYVAuth.test.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const renderAuthHook = async () => {
150150

151151
describe('useYVAuth', () => {
152152
beforeEach(() => {
153-
vi.clearAllMocks();
153+
vi.resetAllMocks();
154154

155155
// Setup window mock
156156
vi.stubGlobal('window', mockWindow);
@@ -248,6 +248,30 @@ describe('useYVAuth', () => {
248248
}),
249249
).rejects.toThrow('Sign in failed');
250250
});
251+
252+
it('should use redirectUri from provider when redirectUrl is not passed', async () => {
253+
const { result } = await renderAuthHook();
254+
255+
await act(async () => {
256+
await result.current.signIn();
257+
});
258+
259+
expect(vi.mocked(YouVersionAPIUsers.signIn)).toHaveBeenCalledWith('http://test.example.com');
260+
});
261+
262+
it('should use redirectUri from provider with scopes when redirectUrl is not passed', async () => {
263+
const { result } = await renderAuthHook();
264+
const scopes: AuthenticationScopes[] = ['profile', 'email'];
265+
266+
await act(async () => {
267+
await result.current.signIn({ scopes });
268+
});
269+
270+
expect(vi.mocked(YouVersionAPIUsers.signIn)).toHaveBeenCalledWith(
271+
'http://test.example.com',
272+
scopes,
273+
);
274+
});
251275
});
252276

253277
describe('processCallback', () => {

0 commit comments

Comments
 (0)