Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't send change request info unless using the new form #7102

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ export const CreateProjectDialogue = ({
const clearDocumentationOverride = () =>
setDocumentation(generalDocumentation);

const projectPayload = getCreateProjectPayload({
omitId: true,
includeChangeRequestConfig: true,
});

const formatApiCode = () => {
return `curl --location --request POST '${uiConfig.unleashUrl}/api/admin/projects' \\
--header 'Authorization: INSERT_API_KEY' \\
--header 'Content-Type: application/json' \\
--data-raw '${JSON.stringify(getCreateProjectPayload(), undefined, 2)}'`;
--data-raw '${JSON.stringify(projectPayload, undefined, 2)}'`;
};

const handleSubmit = async (e: Event) => {
Expand All @@ -88,11 +93,8 @@ export const CreateProjectDialogue = ({
const validName = validateName();

if (validName) {
const payload = getCreateProjectPayload({
omitId: true,
});
try {
const createdProject = await createProject(payload);
const createdProject = await createProject(projectPayload);
refetchUser();
navigate(`/projects/${createdProject.id}`, { replace: true });
setToastData({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,29 @@ test(`adding a change request config for an env not in the project envs doesn't
'dev' in result.current.projectChangeRequestConfiguration,
).toBeFalsy();
});

describe('payload generation', () => {
test(`id is omitted only when explicitly asked to be`, () => {
const { result } = renderHook(() => useProjectForm());

const payloadWithId = result.current.getCreateProjectPayload();
expect('id' in payloadWithId).toBeTruthy();

const payloadWithoutId = result.current.getCreateProjectPayload({
omitId: true,
});
expect('id' in payloadWithoutId).toBeFalsy();
});
});

describe('name validation', () => {
test.each([
['An empty string', ''],
['Just whitespace', ' '],
])(`%s is not valid`, (_, value) => {
const { result } = renderHook(() => useProjectForm());

result.current.setProjectName(value);
expect(result.current.validateName()).toBeFalsy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ const useProjectForm = (
setProjectMode(initialProjectMode);
}, [initialProjectMode]);

const getCreateProjectPayload = (options?: { omitId?: boolean }) => {
const getCreateProjectPayload = (options?: {
omitId?: boolean;
includeChangeRequestConfig?: boolean;
}) => {
const environmentsPayload =
projectEnvironments.size > 0
? { environments: [...projectEnvironments] }
Expand All @@ -119,7 +122,9 @@ const useProjectForm = (
? {
...ossPayload,
mode: projectMode,
changeRequestEnvironments,
...(options?.includeChangeRequestConfig
? { changeRequestEnvironments }
: {}),
}
: ossPayload;
};
Expand Down
Loading