Skip to content

Commit

Permalink
Added more edge cases to utils.test.ts for base64 encode/decode
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 25, 2024
1 parent d33fffa commit ce52bfb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/ably/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('Utils', () => {
expect(tokenDetails.issued).toBe(1654634212000);
expect(tokenDetails.token).toBe(token);
});

test('should throw error for invalid JWT', () => {
const invalidToken = 'invalid.token.string';
expect(() => parseJwt(invalidToken)).toThrow('Unexpected token');
});
});

describe('Base64 URL encoding/decoding', () => {
Expand All @@ -41,7 +46,9 @@ describe('Utils', () => {
// edge cases
expect(toBase64UrlEncoded('')).toBe('');
expect(toBase64UrlEncoded('Hello, 世界! 🌍')).toBe('SGVsbG8sIOS4lueVjCEg8J-MjQ');
expect(toBase64UrlEncoded('Hello+World/123')).toBe('SGVsbG8rV29ybGQvMTIz');
expect(toBase64UrlEncoded('a')).toBe('YQ'); // Would be 'YQ==' in standard Base64
expect(toBase64UrlEncoded('\x8EÇdwïìvÇ')).toBe('wo7Dh2R3w6_DrHbDhw');
});

test('should decode Base64UrlEncoded string into text', () => {
Expand All @@ -52,7 +59,9 @@ describe('Utils', () => {
// edge cases
expect(fromBase64UrlEncoded('')).toBe('');
expect(fromBase64UrlEncoded('SGVsbG8sIOS4lueVjCEg8J-MjQ')).toBe('Hello, 世界! 🌍');
expect(fromBase64UrlEncoded('SGVsbG8rV29ybGQvMTIz')).toBe('Hello+World/123');
expect(fromBase64UrlEncoded('YQ')).toBe('a'); // No padding in Base64Url
expect(fromBase64UrlEncoded('wo7Dh2R3w6_DrHbDhw')).toBe('\x8EÇdwïìvÇ');
});
});
});

0 comments on commit ce52bfb

Please sign in to comment.