All files / src/__tests__ scope.ts

100% Statements 13/13
100% Branches 0/0
100% Functions 3/3
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48    1x 1x               1x   1x                     1x 1x 1x   1x                       1x 1x 1x 1x 1x      
import { AuthScope } from '../';
 
describe('Auth Scope', () => {
  const scope = new AuthScope({
    read: 'r',
    write: 'w',
    admin: 'a',
    posts: 'p',
    web: 'we'
  });
 
  const scopeStr = 'a:r:w|p:r:w|we:w:r:edit:something';
 
  const scopeArr = [
    'admin:read',
    'admin:write',
    'posts:read',
    'posts:write',
    'web:write',
    'web:read',
    'web:edit',
    'web:something'
  ];
 
  it('Creates a valid scope', () => {
    expect(scope.create([])).toBe('');
    expect(scope.create(scopeArr)).toBe(scopeStr);
    // This is a scope with some permissions mixed, but it should work too
    expect(
      scope.create([
        'admin:read',
        'admin:write',
        'posts:read:write',
        'web:write',
        'web:read',
        'web:edit:something'
      ])
    ).toBe(scopeStr);
  });
 
  it('Parses a scope', () => {
    expect(scope.parse('')).toEqual([]);
    expect(scope.parse('invalidstring')).toEqual([]);
    expect(scope.parse('invalid|string')).toEqual([]);
    expect(scope.parse(scopeStr)).toEqual(scopeArr);
  });
});