|
15 | 15 | */ |
16 | 16 |
|
17 | 17 | import { ConfigReader } from '@backstage/config'; |
| 18 | +import { CATALOG_FILTER_EXISTS } from '@backstage/catalog-client'; |
18 | 19 | import type { Entity } from '@backstage/catalog-model'; |
19 | 20 | import { DependabotMetricProvider } from './DependabotMetricProvider'; |
20 | 21 | import { DEPENDABOT_SEVERITY_METRIC } from './DependabotConfig'; |
@@ -86,6 +87,8 @@ describe('DependabotMetricProvider', () => { |
86 | 87 | expect(metric.description).toBe( |
87 | 88 | DEPENDABOT_SEVERITY_METRIC[severity].description, |
88 | 89 | ); |
| 90 | + expect(metric.type).toBe('number'); |
| 91 | + expect(metric.history).toBe(true); |
89 | 92 | }, |
90 | 93 | ); |
91 | 94 | }); |
@@ -131,11 +134,10 @@ describe('DependabotMetricProvider', () => { |
131 | 134 | mockLogger, |
132 | 135 | 'critical', |
133 | 136 | ); |
134 | | - const filter = provider.getCatalogFilter(); |
135 | | - expect( |
136 | | - filter['metadata.annotations.github.com/project-slug'], |
137 | | - ).toBeDefined(); |
138 | | - expect(filter['metadata.annotations.github.com/dependabot']).toBe('true'); |
| 137 | + expect(provider.getCatalogFilter()).toEqual({ |
| 138 | + 'metadata.annotations.github.com/project-slug': CATALOG_FILTER_EXISTS, |
| 139 | + 'metadata.annotations.github.com/dependabot': 'true', |
| 140 | + }); |
139 | 141 | }); |
140 | 142 | }); |
141 | 143 |
|
@@ -175,6 +177,20 @@ describe('DependabotMetricProvider', () => { |
175 | 177 | "Invalid format of 'github.com/project-slug'", |
176 | 178 | ); |
177 | 179 | }); |
| 180 | + |
| 181 | + it.each(['/repo', 'owner/'])( |
| 182 | + 'throws when project-slug has an empty owner or repo segment: %s', |
| 183 | + projectSlug => { |
| 184 | + const provider = new DependabotMetricProvider( |
| 185 | + mockConfig, |
| 186 | + mockLogger, |
| 187 | + 'critical', |
| 188 | + ); |
| 189 | + expect(() => provider.getRepository(entity(projectSlug))).toThrow( |
| 190 | + "Invalid format of 'github.com/project-slug'", |
| 191 | + ); |
| 192 | + }, |
| 193 | + ); |
178 | 194 | }); |
179 | 195 |
|
180 | 196 | describe('calculateMetric', () => { |
@@ -214,5 +230,23 @@ describe('DependabotMetricProvider', () => { |
214 | 230 | ); |
215 | 231 | expect(await provider.calculateMetric(entity())).toBe(0); |
216 | 232 | }); |
| 233 | + |
| 234 | + it('propagates errors when getAlerts fails', async () => { |
| 235 | + mockGetAlerts.mockRejectedValueOnce(new Error('dependabot unavailable')); |
| 236 | + const provider = new DependabotMetricProvider( |
| 237 | + mockConfig, |
| 238 | + mockLogger, |
| 239 | + 'critical', |
| 240 | + ); |
| 241 | + |
| 242 | + await expect(provider.calculateMetric(entity())).rejects.toThrow( |
| 243 | + 'dependabot unavailable', |
| 244 | + ); |
| 245 | + expect(mockGetAlerts).toHaveBeenCalledWith( |
| 246 | + 'https://github.com/owner/repo', |
| 247 | + { owner: 'owner', repo: 'repo' }, |
| 248 | + 'critical', |
| 249 | + ); |
| 250 | + }); |
217 | 251 | }); |
218 | 252 | }); |
0 commit comments