Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razvantomegea committed Nov 11, 2024
1 parent 03b9ca2 commit 4fa0be9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/services/nativeAuth/nativeAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export const nativeAuth = (config?: NativeAuthConfigType) => {
initProps?.noCache
));

if (!response) {
return '';
}

const { hash, timestamp } = response;
const encodedExtraInfo = nativeAuthClient.encodeValue(
JSON.stringify({
Expand All @@ -64,8 +68,8 @@ export const nativeAuth = (config?: NativeAuthConfigType) => {
const encodedOrigin = nativeAuthClient.encodeValue(origin);

return `${encodedOrigin}.${hash}.${expirySeconds}.${encodedExtraInfo}`;
} catch (err) {
console.error('Error getting native auth token: ', err);
} catch (err: any) {
console.error('Error getting native auth token: ', err.toString());
return '';
}
};
Expand Down
6 changes: 4 additions & 2 deletions src/services/nativeAuth/tests/nativeAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,21 @@ describe('Native Auth', () => {
expect(token).toStrictEqual(TOKEN);
});

it('Internal server error', async () => {
it('should return empty string when API call fails', async () => {
server.use(...handlers.serverError);

//this will make sure to expire the cache
jest
.useFakeTimers()
.setSystemTime(new Date().setSeconds(new Date().getSeconds() + 60));

const client = nativeAuth({
origin: ORIGIN,
apiAddress: API_URL
});

await expect(client.initialize()).rejects.toThrow();
const nativeAuthToken = await client.initialize();
expect(nativeAuthToken).toStrictEqual('');
});

it('Generate Access token', () => {
Expand Down

0 comments on commit 4fa0be9

Please sign in to comment.