Skip to content

Commit

Permalink
fix: misc fixes for project archive (#7948)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew authored Aug 21, 2024
1 parent 89f3f09 commit ee1d8ee
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const ProjectArchived: FC<{ name: string }> = ({ name }) => {
<p>
The project <strong>{name}</strong> has been archived. You can find
it on the{' '}
<Link to={`/projects-archive`}>projects archive page</Link>.
<Link to={`/projects-archive`}>archive page for projects</Link>.
</p>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ArchiveProjectForm = ({ featureCount }: IDeleteProjectForm) => {
const { uiConfig } = useUiConfig();
const { loading } = useProjectApi();
const formatProjectArchiveApiCode = () => {
return `curl --location --request DELETE '${uiConfig.unleashUrl}/api/admin/projects/${id}/archive' \\
return `curl --location --request POST '${uiConfig.unleashUrl}/api/admin/projects/archive/${id}' \\
--header 'Authorization: INSERT_API_KEY' '`;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import useProjectApi from 'hooks/api/actions/useProjectApi/useProjectApi';
import useProjects from 'hooks/api/getters/useProjects/useProjects';
import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { useNavigate } from 'react-router-dom';

type ReviveProjectDialogProps = {
name: string;
Expand All @@ -27,6 +28,7 @@ export const ReviveProjectDialog = ({
const { refetch: refetchProjects } = useProjects();
const { refetch: refetchProjectArchive } = useProjects({ archived: true });
const { setToastData, setToastApiError } = useToast();
const navigate = useNavigate();

const onClick = async (e: React.SyntheticEvent) => {
e.preventDefault();
Expand All @@ -35,6 +37,7 @@ export const ReviveProjectDialog = ({
await reviveProject(id);
refetchProjects();
refetchProjectArchive();
navigate(`/projects/${id}`);
setToastData({
title: 'Revive project',
type: 'success',
Expand Down
35 changes: 34 additions & 1 deletion src/lib/features/project/project-service.limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const alwaysOnFlagResolver = {
},
} as unknown as IFlagResolver;

test('Should not allow to exceed project limit', async () => {
test('Should not allow to exceed project limit on create', async () => {
const LIMIT = 1;
const projectService = createFakeProjectService({
...createTestConfig(),
Expand All @@ -31,3 +31,36 @@ test('Should not allow to exceed project limit', async () => {
"Failed to create project. You can't create more than the established limit of 1.",
);
});

test('Should not allow to exceed project limit on revive', async () => {
const LIMIT = 1;
const projectService = createFakeProjectService({
...createTestConfig(),
flagResolver: alwaysOnFlagResolver,
resourceLimits: {
projects: LIMIT,
},
eventBus: {
emit: () => {},
},
} as unknown as IUnleashConfig);

const createProject = (name: string) =>
projectService.createProject(
{ name, id: name },
{} as IUser,
{} as IAuditUser,
);
const archiveProject = (id: string) =>
projectService.archiveProject(id, {} as IAuditUser);
const reviveProject = (id: string) =>
projectService.reviveProject(id, {} as IAuditUser);

await createProject('projectA');
await archiveProject('projectA');
await createProject('projectB');

await expect(() => reviveProject('projectA')).rejects.toThrow(
"Failed to create project. You can't create more than the established limit of 1.",
);
});
2 changes: 2 additions & 0 deletions src/lib/features/project/project-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ export default class ProjectService {
}

async reviveProject(id: string, auditUser: IAuditUser): Promise<void> {
await this.validateProjectLimit();

await this.projectStore.revive(id);

await this.eventService.storeEvent(
Expand Down

0 comments on commit ee1d8ee

Please sign in to comment.