bugfix: Proper error thrown in plugin-azure-devops-backend when gitRepository is not found.

Signed-off-by: NIKUNJ LALITKUMAR HUDKA <nikunjhudka123@gmail.com>
This commit is contained in:
NIKUNJ LALITKUMAR HUDKA
2024-04-17 17:39:41 -03:00
parent 96ee5194b5
commit 88191bb54e
3 changed files with 62 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-azure-devops-backend': minor
---
Fixed bug in plugin-azure-devops-backend where proper error was not thrown when gitRepository was not found.
@@ -465,6 +465,43 @@ describe('AzureDevOpsApi', () => {
]);
});
it('should throw error when gitRepository is undefined', async () => {
const mockApi = {
getGitApi: jest.fn().mockReturnValue({}),
serverUrl: 'serverUrl',
};
(WebApi as unknown as jest.Mock).mockImplementation(() => mockApi);
const api = AzureDevOpsApi.fromConfig(mockConfig, {
logger: mockLogger,
urlReader: mockUrlReader,
});
const pullRequestOptions: PullRequestOptions = {
top: 10,
status: PullRequestStatus.Active,
};
api.getGitRepository = jest.fn().mockResolvedValue(undefined);
const temp = async () => {
try {
await api.getPullRequests('project', 'repo', pullRequestOptions);
return null;
} catch (error) {
return error;
}
};
const error = await temp();
expect(error).toHaveProperty(
'message',
'No repository found for Project "project" with Repository "repo" on host "undefined" under organization "undefined".',
);
});
it('should get build definitions', async () => {
const mockBuilds: Build[] = [
{
@@ -231,6 +231,11 @@ export class AzureDevOpsApi {
host,
org,
);
if (!gitRepository) {
throw new Error(
`No repository found for Project "${projectName}" with Repository "${repoName}" on host "${host}" under organization "${org}".`,
);
}
const buildList = await this.getBuildList(
projectName,
gitRepository.id as string,
@@ -262,6 +267,11 @@ export class AzureDevOpsApi {
host,
org,
);
if (!gitRepository) {
throw new Error(
`No repository found for Project "${projectName}" with Repository "${repoName}" on host "${host}" under organization "${org}".`,
);
}
const webApi = await this.getWebApi(host, org);
const client = await webApi.getGitApi();
const tagRefs: GitRef[] = await client.getRefs(
@@ -304,6 +314,11 @@ export class AzureDevOpsApi {
host,
org,
);
if (!gitRepository) {
throw new Error(
`No repository found for Project "${projectName}" with Repository "${repoName}" on host "${host}" under organization "${org}".`,
);
}
const webApi = await this.getWebApi(host, org);
const client = await webApi.getGitApi();
const searchCriteria: GitPullRequestSearchCriteria = {
@@ -514,6 +529,11 @@ export class AzureDevOpsApi {
host,
org,
);
if (!gitRepository) {
throw new Error(
`No repository found for Project "${projectName}" with Repository "${repoName}" on host "${host}" under organization "${org}".`,
);
}
repoId = gitRepository.id;
}