Skip to content

Commit

Permalink
Merge branch 'main' into deps-update-cci-3-82-0
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmreed authored Dec 1, 2023
2 parents f26f57d + 0027952 commit b429721
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/js/components/orgs/cards/orgInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const OrgInfo = ({
// synced status for orgs
if (baseCommit) {
// eslint-disable-next-line max-len
compareChangesUrl = `${repoUrl}/compare/${org.latest_commit}...${baseCommit}`;
compareChangesUrl = `${repoUrl}/compare/${baseCommit}...${org.latest_commit}`;
}
outOfDateMsg = (
<li>
Expand Down
12 changes: 10 additions & 2 deletions src/js/components/orgs/playgroundCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ const PlaygroundOrgCard = ({
const readyToDeleteOrg =
isWaitingToDeleteOrg && !org.currently_refreshing_changes;
const action = isWaitingToDeleteOrg;

if (readyToDeleteOrg) {
setIsWaitingToDeleteOrg(null);
if (org.has_unsaved_changes) {
Expand All @@ -132,7 +131,16 @@ const PlaygroundOrgCard = ({
doDeleteOrg();
}
}
}, [doDeleteOrg, doRefreshOrg, isWaitingToDeleteOrg, org]);
}, [doDeleteOrg, doRefreshOrg, isWaitingToDeleteOrg, org, dispatch]);
useEffect(() => {
if (
org &&
org?.expires_at !== null &&
new Date(org?.expires_at) < new Date()
) {
doDeleteOrg();
}
}, []);

/* istanbul ignore next */
if (!(project || epic || task)) {
Expand Down
13 changes: 11 additions & 2 deletions src/js/components/orgs/taskOrgCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Card from '@salesforce/design-system-react/components/card';
import classNames from 'classnames';
import React, { ReactNode, useCallback, useState } from 'react';
import React, { ReactNode, useCallback, useEffect, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';

import AssignTaskRoleModal from '@/js/components/githubUsers/assignTaskRole';
Expand Down Expand Up @@ -180,6 +180,7 @@ const TaskOrgCard = ({
handleRefresh?.(org);
}
}, [handleRefresh, org]);

const doCreateOrg = useCallback(() => {
handleCreate(type);
}, [handleCreate, type]);
Expand All @@ -202,7 +203,15 @@ const TaskOrgCard = ({
// We consider an org out-of-date if it is not based on the first commit.
const orgOutOfDate = Boolean(org && orgCommitIdx !== 0);
const testOrgOutOfDate = type === ORG_TYPES.QA && orgOutOfDate;

useEffect(() => {
if (
org &&
org?.expires_at !== null &&
new Date(org?.expires_at) < new Date()
) {
doDeleteOrg();
}
}, []);
return (
<div
className="slds-size_1-of-1
Expand Down
2 changes: 1 addition & 1 deletion test/js/components/epics/detail.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const defaultOrg = {
owner: sampleUser1.id,
owner_gh_username: sampleGitHubUser1.username,
owner_gh_id: sampleGitHubUser1.id,
expires_at: '2019-09-16T12:58:53.721Z',
expires_at: new Date(new Date().getTime() + 86400000).toISOString(),
latest_commit: '617a51',
latest_commit_url: '/test/commit/url/',
latest_commit_at: '2019-08-16T12:58:53.721Z',
Expand Down
23 changes: 22 additions & 1 deletion test/js/components/orgs/playgroundCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const defaultOrg = {
owner: 'user-id',
owner_gh_username: 'user-name',
owner_gh_id: 123456,
expires_at: '2019-09-16T12:58:53.721Z',
expires_at: new Date(new Date().getTime() + 86400000).toISOString(),
latest_commit: '617a512',
latest_commit_url: '/test/commit/url/',
latest_commit_at: '2019-08-16T12:58:53.721Z',
Expand Down Expand Up @@ -236,6 +236,27 @@ describe('<PlaygroundOrgCard/>', () => {

const args = deleteObject.mock.calls[0][0];

expect(args.objectType).toBe('scratch_org');
expect(args.object.id).toEqual(defaultOrg.id);
});
});
describe('delete expired org', () => {
test('checks for expiry status and then deletes org', async () => {
const org = {
...defaultOrg,
expires_at: new Date().toISOString(),
unsaved_changes: {},
total_unsaved_changes: 0,
has_unsaved_changes: false,
};
const { findByText } = setup({ org });
expect.assertions(3);
await findByText('Deleting Org…');

expect(deleteObject).toHaveBeenCalledTimes(1);

const args = deleteObject.mock.calls[0][0];

expect(args.objectType).toBe('scratch_org');
expect(args.object.id).toEqual(defaultOrg.id);
});
Expand Down
23 changes: 22 additions & 1 deletion test/js/components/orgs/taskOrgCards.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const defaultOrgs = {
owner: sampleUser1.id,
owner_gh_username: sampleGitHubUser1.username,
owner_gh_id: sampleGitHubUser1.id,
expires_at: '2019-09-16T12:58:53.721Z',
expires_at: new Date(new Date().getTime() + 86400000).toISOString(),
latest_commit: '617a512-longlong',
latest_commit_url: '/test/commit/url/',
latest_commit_at: '2019-08-16T12:58:53.721Z',
Expand Down Expand Up @@ -913,7 +913,28 @@ describe('<TaskOrgCards/>', () => {
expect(args.object.id).toBe('org-id');
});
});
test('checks and then deletes expired org', async () => {
const { findByText } = setup({
orgs: {
...defaultOrgs,
Dev: {
...defaultOrgs.Dev,
expires_at: new Date().toISOString(),
unsaved_changes: {},
total_unsaved_changes: 0,
has_unsaved_changes: false,
},
},
});
await findByText('Deleting Org…');
expect.assertions(3);
expect(deleteObject).toHaveBeenCalledTimes(1);

const deleteArgs = deleteObject.mock.calls[0][0];

expect(deleteArgs.objectType).toBe('scratch_org');
expect(deleteArgs.object.id).toBe('org-id');
});
describe('Dev org', () => {
test('refreshes and then deletes org', async () => {
const { findByText, getByText } = setup({
Expand Down
2 changes: 1 addition & 1 deletion test/js/components/projects/detail.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const defaultOrg = {
owner: 'my-user',
owner_gh_username: 'currentUser',
owner_gh_id: 123456,
expires_at: '2019-09-16T12:58:53.721Z',
expires_at: new Date(new Date().getTime() + 86400000).toISOString(),
latest_commit: '617a51',
latest_commit_url: '/test/commit/url/',
latest_commit_at: '2019-08-16T12:58:53.721Z',
Expand Down
2 changes: 1 addition & 1 deletion test/js/components/tasks/detail.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const defaultOrg = {
owner: sampleUser1.id,
owner_gh_username: sampleGitHubUser1.username,
owner_gh_id: sampleGitHubUser1.id,
expires_at: '2019-09-16T12:58:53.721Z',
expires_at: new Date(new Date().getTime() + 86400000).toISOString(),
latest_commit: '617a51',
latest_commit_url: '/test/commit/url/',
latest_commit_at: '2019-08-16T12:58:53.721Z',
Expand Down

0 comments on commit b429721

Please sign in to comment.