Skip to content

Commit

Permalink
Add error handling for various scenarios in Repoverse synchronization
Browse files Browse the repository at this point in the history
  • Loading branch information
RajVarsani committed Dec 23, 2023
1 parent 0f227c8 commit c41c8e2
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,25 @@ describe('Repoverse', () => {
reviewers: [targetRepositoryConfigs[index].owner],
});
}

// reset get commit mock to default implementation
mocks.repos.getCommit.mockResolvedValue({
data: {
files: [
{
filename: `${faker.system.filePath()}${faker.system.fileName()}`,
sha: faker.git.commitSha(),
status: ['added', 'modified', 'removed', 'renamed'][
faker.datatype.number({
min: 0,
max: 3,
})
],
previous_filename: faker.system.fileName(),
},
],
},
});
});

it('should throw an error for invalid source repository format', async () => {
Expand All @@ -263,5 +282,50 @@ describe('Repoverse', () => {
'Source repository nonexistent/owner-repo is not in the list of repositories to sync'
);
});

it('should handle error when fetching the latest commit SHA fails', async () => {
const sourceRepository = `${exampleConfig.repositories[0].owner}/${exampleConfig.repositories[0].repo}`;
const commits = [
generateFakeGitHubCommitInfo({ override: { distinct: true } }),
];

mocks.git.getRef.mockRejectedValueOnce(
new Error('Error fetching latest commit SHA')
);

await expect(
repoverse.synchronize(sourceRepository, commits)
).rejects.toThrow('Error fetching latest commit SHA');
});

it('should handle error when creating a branch reference fails', async () => {
const sourceRepository = `${exampleConfig.repositories[0].owner}/${exampleConfig.repositories[0].repo}`;
const commits = [
generateFakeGitHubCommitInfo({ override: { distinct: true } }),
];

mocks.git.createRef.mockRejectedValueOnce(
new Error('Error creating branch reference')
);

await expect(
repoverse.synchronize(sourceRepository, commits)
).rejects.toThrow('Error creating branch reference');
});

it('should handle error during commit data caching', async () => {
const sourceRepository = `${exampleConfig.repositories[0].owner}/${exampleConfig.repositories[0].repo}`;
const commits = [
generateFakeGitHubCommitInfo({ override: { distinct: true } }),
];

mocks.repos.getCommit.mockImplementationOnce(() => {
throw new Error('Error caching commit data');
});

await expect(
repoverse.synchronize(sourceRepository, commits)
).rejects.toThrow('Error caching commit data');
});
});
});

0 comments on commit c41c8e2

Please sign in to comment.