|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { formatContractName, formatSubgraphName, getSubgraphBasename } from './subgraph'; |
| 3 | + |
| 4 | +describe('getSubgraphBasename', () => { |
| 5 | + it('returns the last segment of a subgraph name', () => { |
| 6 | + expect(getSubgraphBasename('user/my-subgraph')).toBe('my-subgraph'); |
| 7 | + expect(getSubgraphBasename('org/project')).toBe('project'); |
| 8 | + }); |
| 9 | + |
| 10 | + it('returns the full name if no slash is present', () => { |
| 11 | + expect(getSubgraphBasename('single-name')).toBe('single-name'); |
| 12 | + }); |
| 13 | +}); |
| 14 | + |
| 15 | +describe('formatSubgraphName', () => { |
| 16 | + it('converts to lowercase', () => { |
| 17 | + expect(formatSubgraphName('MySubGraph')).toBe('mysubgraph'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('replaces spaces with hyphens', () => { |
| 21 | + expect(formatSubgraphName('my subgraph name')).toBe('my-subgraph-name'); |
| 22 | + expect(formatSubgraphName('multiple spaces')).toBe('multiple-spaces'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('removes special characters', () => { |
| 26 | + expect(formatSubgraphName('my$special@subgraph!')).toBe('myspecialsubgraph'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('keeps alphanumeric characters, hyphens and underscores', () => { |
| 30 | + expect(formatSubgraphName('my-subgraph_123')).toBe('my-subgraph_123'); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe('formatContractName', () => { |
| 35 | + it('replaces spaces and dots with underscores', () => { |
| 36 | + expect(formatContractName('My Contract')).toBe('My_Contract'); |
| 37 | + expect(formatContractName('contract.name')).toBe('contract_name'); |
| 38 | + expect(formatContractName('multiple...dots')).toBe('multiple_dots'); |
| 39 | + }); |
| 40 | + |
| 41 | + it('removes special characters but keeps alphanumeric, hyphens and underscores', () => { |
| 42 | + expect(formatContractName('Contract$$$Name')).toBe('ContractName'); |
| 43 | + expect(formatContractName('My-Contract_123')).toBe('My-Contract_123'); |
| 44 | + expect(formatContractName('My Contract $$$$')).toBe('My_Contract_'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('preserves case', () => { |
| 48 | + expect(formatContractName('MyContractName')).toBe('MyContractName'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments