Skip to content

Commit

Permalink
refactor b64 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lbalmaceda committed Jan 30, 2020
1 parent 894b8dc commit 89e847b
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/jwt/__tests__/base64.spec.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import * as base64 from '../base64';

describe('helpers base64 url', function() {
it('padding', function() {
expect(base64.padding('')).toBe('');
expect(base64.padding('a')).toBe('a===');
expect(base64.padding('ab')).toBe('ab==');
expect(base64.padding('abc')).toBe('abc=');
expect(base64.padding('abcd')).toBe('abcd');
expect(base64.padding('abced')).toBe('abced===');
expect(base64.padding(base64.padding('abc'))).toBe('abc=');
describe('padding', function() {
it('does not add to multiple of 4', function() {
expect(base64.padding('')).toBe('');
expect(base64.padding('abcd')).toBe('abcd');
});
it('adds to non multiple of 4', function() {
expect(base64.padding('a')).toBe('a===');
expect(base64.padding('ab')).toBe('ab==');
expect(base64.padding('abc')).toBe('abc=');
expect(base64.padding('abced')).toBe('abced===');
});
it('does not change already padded value', function() {
const padded = base64.padding('abc');
expect(padded).toBe('abc=');
const again = base64.padding(padded);
expect(again).toBe('abc=');
});
});

it('decode to hex', function() {
expect(base64.decodeToHEX('AQAB')).toBe('010001');
describe('decoding to hex', function() {
it('should convert base64 input into hex output', function() {
expect(base64.decodeToHEX('AQAB')).toBe('010001');
expect(base64.decodeToHEX('uGbXWiK3dQTyCbX5')).toBe(
'b866d75a22b77504f209b5f9',
);
});
});
});

0 comments on commit 89e847b

Please sign in to comment.