|
1 | 1 | import { expect, test } from 'vitest';
|
2 |
| -import { arraysEqualShallow, isRemotePath, excludeReposByName } from './utils'; |
| 2 | +import { arraysEqualShallow, isRemotePath, excludeReposByName, includeReposByTopic, excludeReposByTopic } from './utils'; |
3 | 3 | import { Repository } from './types';
|
4 | 4 |
|
5 | 5 | const testNames: string[] = [
|
@@ -125,3 +125,135 @@ test('isRemotePath should return false for non HTTP paths', () => {
|
125 | 125 | expect(isRemotePath('')).toBe(false);
|
126 | 126 | expect(isRemotePath(' ')).toBe(false);
|
127 | 127 | });
|
| 128 | + |
| 129 | + |
| 130 | +test('includeReposByTopic should return repos with matching topics', () => { |
| 131 | + const repos = [ |
| 132 | + { id: '1', topics: ['javascript', 'typescript'] }, |
| 133 | + { id: '2', topics: ['python', 'django'] }, |
| 134 | + { id: '3', topics: ['typescript', 'react'] } |
| 135 | + ].map(r => ({ |
| 136 | + ...createRepository(r.id), |
| 137 | + ...r, |
| 138 | + } satisfies Repository)); |
| 139 | + |
| 140 | + const result = includeReposByTopic(repos, ['typescript']); |
| 141 | + expect(result.length).toBe(2); |
| 142 | + expect(result.map(r => r.id)).toEqual(['1', '3']); |
| 143 | +}); |
| 144 | + |
| 145 | +test('includeReposByTopic should handle glob patterns in topic matching', () => { |
| 146 | + const repos = [ |
| 147 | + { id: '1', topics: ['frontend-app', 'backend-app'] }, |
| 148 | + { id: '2', topics: ['mobile-app', 'web-app'] }, |
| 149 | + { id: '3', topics: ['desktop-app', 'cli-app'] } |
| 150 | + ].map(r => ({ |
| 151 | + ...createRepository(r.id), |
| 152 | + ...r, |
| 153 | + } satisfies Repository)); |
| 154 | + |
| 155 | + const result = includeReposByTopic(repos, ['*-app']); |
| 156 | + expect(result.length).toBe(3); |
| 157 | +}); |
| 158 | + |
| 159 | +test('includeReposByTopic should handle repos with no topics', () => { |
| 160 | + const repos = [ |
| 161 | + { id: '1', topics: ['javascript'] }, |
| 162 | + { id: '2', topics: undefined }, |
| 163 | + { id: '3', topics: [] } |
| 164 | + ].map(r => ({ |
| 165 | + ...createRepository(r.id), |
| 166 | + ...r, |
| 167 | + } satisfies Repository)); |
| 168 | + |
| 169 | + const result = includeReposByTopic(repos, ['javascript']); |
| 170 | + expect(result.length).toBe(1); |
| 171 | + expect(result[0].id).toBe('1'); |
| 172 | +}); |
| 173 | + |
| 174 | +test('includeReposByTopic should return empty array when no repos match topics', () => { |
| 175 | + const repos = [ |
| 176 | + { id: '1', topics: ['frontend'] }, |
| 177 | + { id: '2', topics: ['backend'] } |
| 178 | + ].map(r => ({ |
| 179 | + ...createRepository(r.id), |
| 180 | + ...r, |
| 181 | + } satisfies Repository)); |
| 182 | + |
| 183 | + const result = includeReposByTopic(repos, ['mobile']); |
| 184 | + expect(result).toEqual([]); |
| 185 | +}); |
| 186 | + |
| 187 | + |
| 188 | +test('excludeReposByTopic should exclude repos with matching topics', () => { |
| 189 | + const repos = [ |
| 190 | + { id: '1', topics: ['javascript', 'typescript'] }, |
| 191 | + { id: '2', topics: ['python', 'django'] }, |
| 192 | + { id: '3', topics: ['typescript', 'react'] } |
| 193 | + ].map(r => ({ |
| 194 | + ...createRepository(r.id), |
| 195 | + ...r, |
| 196 | + } satisfies Repository)); |
| 197 | + |
| 198 | + const result = excludeReposByTopic(repos, ['typescript']); |
| 199 | + expect(result.length).toBe(1); |
| 200 | + expect(result[0].id).toBe('2'); |
| 201 | +}); |
| 202 | + |
| 203 | +test('excludeReposByTopic should handle glob patterns', () => { |
| 204 | + const repos = [ |
| 205 | + { id: '1', topics: ['test-lib', 'test-app'] }, |
| 206 | + { id: '2', topics: ['prod-lib', 'prod-app'] }, |
| 207 | + { id: '3', topics: ['dev-tool'] } |
| 208 | + ].map(r => ({ |
| 209 | + ...createRepository(r.id), |
| 210 | + ...r, |
| 211 | + } satisfies Repository)); |
| 212 | + |
| 213 | + const result = excludeReposByTopic(repos, ['test-*']); |
| 214 | + expect(result.length).toBe(2); |
| 215 | + expect(result.map(r => r.id)).toEqual(['2', '3']); |
| 216 | +}); |
| 217 | + |
| 218 | +test('excludeReposByTopic should handle multiple exclude patterns', () => { |
| 219 | + const repos = [ |
| 220 | + { id: '1', topics: ['frontend', 'react'] }, |
| 221 | + { id: '2', topics: ['backend', 'node'] }, |
| 222 | + { id: '3', topics: ['mobile', 'react-native'] } |
| 223 | + ].map(r => ({ |
| 224 | + ...createRepository(r.id), |
| 225 | + ...r, |
| 226 | + } satisfies Repository)); |
| 227 | + |
| 228 | + const result = excludeReposByTopic(repos, ['*end', '*native']); |
| 229 | + expect(result.length).toBe(0); |
| 230 | +}); |
| 231 | + |
| 232 | +test('excludeReposByTopic should not exclude repos when no topics match', () => { |
| 233 | + const repos = [ |
| 234 | + { id: '1', topics: ['frontend'] }, |
| 235 | + { id: '2', topics: ['backend'] }, |
| 236 | + { id: '3', topics: undefined } |
| 237 | + ].map(r => ({ |
| 238 | + ...createRepository(r.id), |
| 239 | + ...r, |
| 240 | + } satisfies Repository)); |
| 241 | + |
| 242 | + const result = excludeReposByTopic(repos, ['mobile']); |
| 243 | + expect(result.length).toBe(3); |
| 244 | + expect(result.map(r => r.id)).toEqual(['1', '2', '3']); |
| 245 | +}); |
| 246 | + |
| 247 | +test('excludeReposByTopic should handle empty exclude patterns array', () => { |
| 248 | + const repos = [ |
| 249 | + { id: '1', topics: ['frontend'] }, |
| 250 | + { id: '2', topics: ['backend'] } |
| 251 | + ].map(r => ({ |
| 252 | + ...createRepository(r.id), |
| 253 | + ...r, |
| 254 | + } satisfies Repository)); |
| 255 | + |
| 256 | + const result = excludeReposByTopic(repos, []); |
| 257 | + expect(result.length).toBe(2); |
| 258 | + expect(result).toEqual(repos); |
| 259 | +}); |
0 commit comments