Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
aschwenn committed Dec 3, 2024
1 parent 7cc34e6 commit 9bb1336
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/helpers/get-changed-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const mock_data1 = [
contents_url: 'https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e',
patch: '@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test'
}
];
] as const;
const mock_data2 = [
{
sha: 'bbcd538c8e72b8c175046e27cc8f907076331401',
Expand All @@ -60,7 +60,7 @@ const mock_data2 = [
contents_url: 'https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e',
patch: '@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test'
}
];
] as const;
const mock_data3 = [
{
sha: 'bbcd538c8e72b8c175046e27cc8f907076331401',
Expand All @@ -86,7 +86,7 @@ const mock_data3 = [
contents_url: 'https://api.github.com/repos/octocat/Hello-World/contents/file1.txt?ref=6dcb09b5b57875f334f61aebed695e2e4193db5e',
patch: '@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test'
}
];
] as const;
const mock_data4 = [
{
sha: 'bbcd538c8e72b8c175046e27cc8f907076331401',
Expand All @@ -113,7 +113,7 @@ const mock_data4 = [
patch: '@@ -132,7 +132,7 @@ module Test @@ -1000,7 +1000,7 @@ module Test',
previous_filename: 'original/file/location/file2.txt'
}
];
] as const;
(octokit.pulls.listFiles as unknown as Mocktokit).mockImplementation(async ({ page }) => ({
data: page === 1 ? mock_data1 : page === 2 ? mock_data2 : []
}));
Expand All @@ -122,13 +122,13 @@ describe('getChangedFiles', () => {
it('case where one of the file paths match the file paths that octokit returns', async () => {
const result = await getChangedFiles({});

expect(result).toEqual(`${mock_data1[0]!.filename},${mock_data1[1]!.filename},${mock_data2[0]!.filename}`);
expect(result).toEqual([mock_data1[0].filename, mock_data1[1].filename, mock_data2[0].filename].join(','));
});

it('case where files returned from getChangedFiles matches the provided regex pattern', async () => {
const result = await getChangedFiles({ pattern: 'file/path/1/file[0-9].txt' });

expect(result).toEqual(`${mock_data1[0]!.filename}`);
expect(result).toEqual(mock_data1[0].filename);
});

it('case where files returned from getChangedFiles does not match the provided regex pattern', async () => {
Expand All @@ -143,7 +143,7 @@ describe('getChangedFiles', () => {
}));
const result = await getChangedFiles({ ignore_deleted: 'true' });

expect(result).toEqual(mock_data3[0]!.filename);
expect(result).toEqual(mock_data3[0].filename);
});

it('should include original location of renamed files, as if rename was an addition and deletion', async () => {
Expand All @@ -152,6 +152,6 @@ describe('getChangedFiles', () => {
}));
const result = await getChangedFiles({ ignore_deleted: 'true' });

expect(result).toEqual([mock_data4[0]!.filename, mock_data4[1]!.filename, mock_data4[1]!.previous_filename].join(','));
expect(result).toEqual([mock_data4[0].filename, mock_data4[1].filename, mock_data4[1].previous_filename].join(','));
});
});

0 comments on commit 9bb1336

Please sign in to comment.