-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: started work on snyk api client tests
- Loading branch information
Showing
3 changed files
with
536 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { SnykApiClient } from './index'; | ||
import {MockConfigApi, MockFetchApi} from "@backstage/test-utils"; | ||
import { UrlPatternDiscovery } from '@backstage/core-app-api'; | ||
|
||
const EXAMPLE_ORG_ID = '361fd3c0-41d4-4ea4-ba77-09bb17890967'; | ||
|
||
describe('SnykApiClient', () => { | ||
const mockBaseUrl = 'http://localhost:3000'; | ||
const configApi = new MockConfigApi({ 'snyk.mocked': false }); | ||
const discoveryApi = UrlPatternDiscovery.compile(mockBaseUrl); | ||
const fetchApi = new MockFetchApi({}); | ||
const snykApiClient = new SnykApiClient({ discoveryApi, configApi, fetchApi }); | ||
describe('getCompleteProjectsListFromAnnotations', () => { | ||
describe('when there are no annotations', () => { | ||
it('should return an empty array', async () => { | ||
const result = await snykApiClient.getCompleteProjectsListFromAnnotations(EXAMPLE_ORG_ID, {}); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
describe('when there is a single annotation', () => { | ||
describe('and the annotation is snyk.io/org-id', () => { | ||
it('should return an empty array', async () => { | ||
const result = await snykApiClient.getCompleteProjectsListFromAnnotations(EXAMPLE_ORG_ID, { | ||
'snyk.io/org-id': EXAMPLE_ORG_ID, | ||
}); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
describe('and the annotation is snyk.io/org-ids', () => { | ||
it('should return an empty array', async () => { | ||
const result = await snykApiClient.getCompleteProjectsListFromAnnotations(EXAMPLE_ORG_ID, { | ||
'snyk.io/org-ids': EXAMPLE_ORG_ID, | ||
}); | ||
expect(result).toEqual([]); | ||
}); | ||
}); | ||
describe('and the annotation is github.com/project-slug (target name)', () => { | ||
it('should return a full project by the provided target name', async () => { | ||
const result = await snykApiClient.getCompleteProjectsListFromAnnotations(EXAMPLE_ORG_ID, { | ||
'github.com/project-slug': 'Snyk Demo/java-goof', | ||
}); | ||
//TODO: fix to include the actual expected result | ||
expect(result).toContainEqual([ | ||
{ | ||
id: EXAMPLE_ORG_ID, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.