|
1 | | -import { checkResourceAllowed, resourceUrlFromServerUrl } from '../../src/shared/authUtils.js'; |
| 1 | +import { checkResourceAllowed, mergeScopes, resourceUrlFromServerUrl } from '../../src/shared/authUtils.js'; |
2 | 2 |
|
3 | 3 | describe('auth-utils', () => { |
4 | 4 | describe('resourceUrlFromServerUrl', () => { |
@@ -87,4 +87,31 @@ describe('auth-utils', () => { |
87 | 87 | ).toBe(false); |
88 | 88 | }); |
89 | 89 | }); |
| 90 | + |
| 91 | + describe('mergeScopes', () => { |
| 92 | + it('should return undefined when both inputs are undefined', () => { |
| 93 | + expect(mergeScopes(undefined, undefined)).toBeUndefined(); |
| 94 | + }); |
| 95 | + |
| 96 | + it('should return existing when incoming is undefined', () => { |
| 97 | + expect(mergeScopes('read write', undefined)).toBe('read write'); |
| 98 | + }); |
| 99 | + |
| 100 | + it('should return incoming when existing is undefined', () => { |
| 101 | + expect(mergeScopes(undefined, 'read write')).toBe('read write'); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should merge and deduplicate scopes', () => { |
| 105 | + expect(mergeScopes('read write', 'write execute')).toBe('read write execute'); |
| 106 | + }); |
| 107 | + |
| 108 | + it('should return undefined for empty strings', () => { |
| 109 | + expect(mergeScopes('', '')).toBeUndefined(); |
| 110 | + expect(mergeScopes('', undefined)).toBeUndefined(); |
| 111 | + }); |
| 112 | + |
| 113 | + it('should handle multiple whitespace separators', () => { |
| 114 | + expect(mergeScopes('read write', 'write\texecute')).toBe('read write execute'); |
| 115 | + }); |
| 116 | + }); |
90 | 117 | }); |
0 commit comments