Skip to content

Commit

Permalink
Merge pull request #1 from ExpediaGroup/update
Browse files Browse the repository at this point in the history
update test cases
  • Loading branch information
bherrmann2 authored Jul 9, 2024
2 parents 57d81ac + b2c844e commit 7aaf77c
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 82 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/file/path/1 @ExpediaGroup/test-owners-1
/file/path/2 @ExpediaGroup/test-owners-2
/file/path/shared @ExpediaGroup/test-shared-owners-1 @ExpediaGroup/test-shared-owners-2
/file/path/users @user1 @user2
2 changes: 1 addition & 1 deletion dist/431.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/431.index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/676.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/676.index.js.map

Large diffs are not rendered by default.

47 changes: 25 additions & 22 deletions dist/974.index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/974.index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/helpers/approvals-satisfied.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const approvalsSatisfied = async ({
if (isTeam(teamOrUsers)) {
return await fetchTeamLogins(teamOrUsers);
} else {
return teamOrUsers.split(',');
return teamOrUsers.replaceAll('@', '').split(',');
}
});
const codeOwnerLogins = uniq(loginsLists.flat());
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/remove-pr-from-merge-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ limitations under the License.
*/

import * as core from '@actions/core';
import { orderBy } from 'lodash';
import { FIRST_QUEUED_PR_LABEL, QUEUED_FOR_MERGE_PREFIX, READY_FOR_MERGE_PR_LABEL } from '../constants';
import { HelperInputs } from '../types/generated';
import { context } from '@actions/github';
Expand Down Expand Up @@ -54,8 +55,8 @@ export const removePrFromMergeQueue = async ({ seconds }: RemovePrFromMergeQueue
ref: sha,
...context.repo
});
const status = data.find(status => status.state === 'failure' || status.state === 'success');
if (status && timestampIsStale(status.created_at, seconds)) {
const mostRecentStatus = orderBy(data, 'created_at', 'desc')[0];
if (mostRecentStatus && timestampIsStale(mostRecentStatus.created_at, seconds)) {
core.info('Removing stale PR from first queued position...');
return Promise.all([removeLabelIfExists(READY_FOR_MERGE_PR_LABEL, number), removeLabelIfExists(FIRST_QUEUED_PR_LABEL, number)]);
}
Expand Down
28 changes: 26 additions & 2 deletions test/helpers/approvals-satisfied.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ describe('approvalsSatisfied', () => {
]
});
const result = await approvalsSatisfied({
users: 'user1,user2',
users: '@user1,@user2',
pull_number: '12345'
});
expect(octokit.pulls.listReviews).toHaveBeenCalledWith({ pull_number: 12345, repo: 'repo', owner: 'owner', page: 1, per_page: 100 });
Expand All @@ -543,11 +543,35 @@ describe('approvalsSatisfied', () => {
]
});
const result = await approvalsSatisfied({
users: 'user1,user2',
users: '@user1,@user2',
pull_number: '12345'
});
expect(octokit.pulls.listReviews).toHaveBeenCalledWith({ pull_number: 12345, repo: 'repo', owner: 'owner', page: 1, per_page: 100 });
expect(getRequiredCodeOwnersEntries).not.toHaveBeenCalled();
expect(result).toBe(false);
});

it('should return true when approvals are satisfied and users are explicitly defined in CODEOWNERS', async () => {
(getRequiredCodeOwnersEntries as jest.Mock).mockResolvedValue([{ owners: ['@user1', '@user2'] }]);
mockPagination({
data: [
{
state: 'APPROVED',
user: { login: 'user1' }
},
{
state: 'APPROVED',
user: { login: 'user2' }
},
{
state: 'APPROVED',
user: { login: 'user3' }
}
]
});
const result = await approvalsSatisfied({
number_of_reviewers: '2'
});
expect(result).toBe(true);
});
});
51 changes: 1 addition & 50 deletions test/helpers/remove-pr-from-merge-queue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,12 @@ describe('removePrFromMergeQueue', () => {
beforeEach(() => {
(octokit.repos.listCommitStatusesForRef as unknown as Mocktokit).mockImplementation(async () => ({
data: [
{
created_at: '2022-01-01T10:00:00Z',
state: 'success'
},
{
created_at: '2022-01-01T08:59:00Z',
state: 'failure'
},
{
created_at: '2022-01-01T10:00:00Z',
created_at: '2022-01-01T08:00:00Z',
state: 'success'
}
]
Expand Down Expand Up @@ -99,10 +95,6 @@ describe('removePrFromMergeQueue', () => {
beforeEach(() => {
(octokit.repos.listCommitStatusesForRef as unknown as Mocktokit).mockImplementation(async () => ({
data: [
{
created_at: '2022-01-01T10:00:00Z',
state: 'success'
},
{
created_at: '2022-01-01T09:01:00Z',
state: 'failure'
Expand Down Expand Up @@ -136,47 +128,6 @@ describe('removePrFromMergeQueue', () => {
});
});

describe('should not remove pr case with no failure status', () => {
beforeEach(async () => {
(octokit.repos.listCommitStatusesForRef as unknown as Mocktokit).mockImplementation(async () => ({
data: [
{
created_at: '2022-01-01T10:00:00Z',
state: 'success'
},
{
created_at: '2022-01-01T09:01:00Z',
state: 'pending'
},
{
created_at: '2022-01-01T10:00:00Z',
state: 'success'
}
]
}));
await removePrFromMergeQueue({ seconds });
});

it('should call pulls.list with correct params', () => {
expect(octokit.pulls.list).toHaveBeenCalledWith({
state: 'open',
per_page: 100,
...context.repo
});
});

it('should call listCommitStatusesForRef with correct params', () => {
expect(octokit.repos.listCommitStatusesForRef).toHaveBeenCalledWith({
ref: 'correct sha',
...context.repo
});
});

it('should not call removeLabelIfExists', () => {
expect(removeLabelIfExists).not.toHaveBeenCalled();
});
});

describe('should remove stray PRs in the queue', () => {
beforeEach(async () => {
(octokit.pulls.list as unknown as Mocktokit).mockImplementation(async () => ({
Expand Down
7 changes: 7 additions & 0 deletions test/utils/get-core-member-logins.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ describe('getCoreMemberLogins', () => {
},
{
filename: sharedFile
},
{
filename: 'file/path/users/file.ts'
}
]
: []
Expand All @@ -126,6 +129,10 @@ describe('getCoreMemberLogins', () => {
{
pattern: '/file/path/shared',
owners: ['@ExpediaGroup/test-shared-owners-1', '@ExpediaGroup/test-shared-owners-2']
},
{
pattern: '/file/path/users',
owners: ['@user1', '@user2']
}
]);
});
Expand Down

0 comments on commit 7aaf77c

Please sign in to comment.