Skip to content
Open
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
42 changes: 42 additions & 0 deletions js/apps/admin-ui/src/organizations/OrganizationForm.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, expect, it } from "vitest";
import { convertToOrg, OrganizationFormType } from "./OrganizationForm";

describe("convertToOrg", () => {
it("omits blank domain entries", () => {
const form: OrganizationFormType = {
name: "test-org",
alias: "test-org",
domains: [""],
} as OrganizationFormType;

const result = convertToOrg(form);

expect(result.domains).toEqual([]);
});

it("keeps valid domains and drops blanks mixed in", () => {
const form: OrganizationFormType = {
name: "test-org",
alias: "test-org",
domains: ["example.com", "", "acme.com"],
} as OrganizationFormType;

const result = convertToOrg(form);

expect(result.domains).toEqual([
{ name: "example.com", verified: false },
{ name: "acme.com", verified: false },
]);
});

it("handles undefined domains", () => {
const form: OrganizationFormType = {
name: "test-org",
alias: "test-org",
} as OrganizationFormType;

const result = convertToOrg(form);

expect(result.domains).toBeUndefined();
});
});
5 changes: 3 additions & 2 deletions js/apps/admin-ui/src/organizations/OrganizationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ export type OrganizationFormType = AttributeForm &
Omit<OrganizationRepresentation, "domains" | "attributes"> & {
domains?: string[];
};

export const convertToOrg = (
org: OrganizationFormType,
): OrganizationRepresentation => ({
...org,
domains: org.domains?.map((d) => ({ name: d, verified: false })),
domains: org.domains
?.filter((d) => d.trim() !== "")
.map((d) => ({ name: d, verified: false })),
Comment on lines +24 to +26
Comment on lines +24 to +26
attributes: keyValueToArray(org.attributes),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static int getDomainPartsSize(String domain) {
}

public static void validateDomain(String rawDomain) {
if (rawDomain == null) {
if (isBlank(rawDomain)) {
return;
}

Expand Down