|
| 1 | +import { expect } from 'chai'; |
| 2 | +import { serializeQueryTags } from '../../../lib/utils/queryTags'; |
| 3 | + |
| 4 | +describe('serializeQueryTags', () => { |
| 5 | + it('should return undefined for null input', () => { |
| 6 | + expect(serializeQueryTags(null)).to.be.undefined; |
| 7 | + }); |
| 8 | + |
| 9 | + it('should return undefined for undefined input', () => { |
| 10 | + expect(serializeQueryTags(undefined)).to.be.undefined; |
| 11 | + }); |
| 12 | + |
| 13 | + it('should return undefined for empty object', () => { |
| 14 | + expect(serializeQueryTags({})).to.be.undefined; |
| 15 | + }); |
| 16 | + |
| 17 | + it('should serialize a single tag', () => { |
| 18 | + expect(serializeQueryTags({ team: 'engineering' })).to.equal('team:engineering'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('should serialize multiple tags', () => { |
| 22 | + const result = serializeQueryTags({ team: 'engineering', app: 'etl' }); |
| 23 | + expect(result).to.equal('team:engineering,app:etl'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('should omit colon for null value', () => { |
| 27 | + expect(serializeQueryTags({ team: null })).to.equal('team'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should omit colon for undefined value', () => { |
| 31 | + expect(serializeQueryTags({ team: undefined })).to.equal('team'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should mix null and non-null values', () => { |
| 35 | + const result = serializeQueryTags({ team: 'eng', flag: null, app: 'etl' }); |
| 36 | + expect(result).to.equal('team:eng,flag,app:etl'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should escape backslash in value', () => { |
| 40 | + expect(serializeQueryTags({ path: 'a\\b' })).to.equal('path:a\\\\b'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should escape colon in value', () => { |
| 44 | + expect(serializeQueryTags({ url: 'http://host' })).to.equal('url:http\\://host'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('should escape comma in value', () => { |
| 48 | + expect(serializeQueryTags({ list: 'a,b' })).to.equal('list:a\\,b'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should escape multiple special characters in value', () => { |
| 52 | + expect(serializeQueryTags({ val: 'a\\b:c,d' })).to.equal('val:a\\\\b\\:c\\,d'); |
| 53 | + }); |
| 54 | + |
| 55 | + it('should not escape special characters in keys', () => { |
| 56 | + expect(serializeQueryTags({ 'key:name': 'value' })).to.equal('key:name:value'); |
| 57 | + }); |
| 58 | +}); |
0 commit comments