mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #39082 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually https://github.com/user-attachments/assets/51ede24f-3317-455a-8995-fd50e9281a47 --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
125 lines
4.6 KiB
TypeScript
125 lines
4.6 KiB
TypeScript
import { getPastDate, getFutureDate } from "test/test-utils";
|
|
import type { IRegistrationFormData } from "interfaces/registration_form_data";
|
|
import helpers, {
|
|
removeOSPrefix,
|
|
compareVersions,
|
|
willExpireWithinXDays,
|
|
} from "./helpers";
|
|
|
|
describe("helpers utilities", () => {
|
|
describe("removeOSPrefix function", () => {
|
|
it("properly removes Apple prefix from a host's operating system version", () => {
|
|
expect(removeOSPrefix("macOS 14.1.2")).toEqual("14.1.2");
|
|
expect(removeOSPrefix("iOS 18.0")).toEqual("18.0");
|
|
expect(removeOSPrefix("iPadOS 17.5.1")).toEqual("17.5.1");
|
|
});
|
|
});
|
|
|
|
describe("compareVersions function", () => {
|
|
it("properly checks if a version is older than another", () => {
|
|
expect(compareVersions("14.4.1", "14.4.2")).toEqual(-1);
|
|
expect(compareVersions("14.4.1", "14.5")).toEqual(-1);
|
|
expect(compareVersions("14.4.1", "15")).toEqual(-1);
|
|
|
|
expect(compareVersions("14.4", "14.4.2")).toEqual(-1);
|
|
expect(compareVersions("14.4", "14.5")).toEqual(-1);
|
|
expect(compareVersions("14.4", "15")).toEqual(-1);
|
|
|
|
expect(compareVersions("14", "14.4.2")).toEqual(-1);
|
|
expect(compareVersions("14", "14.0.5")).toEqual(-1);
|
|
expect(compareVersions("14", "15")).toEqual(-1);
|
|
});
|
|
|
|
it("properly checks if a version is newer than another", () => {
|
|
expect(compareVersions("14.4.4", "14.4.3")).toEqual(1);
|
|
expect(compareVersions("14.3.4", "14.3")).toEqual(1);
|
|
expect(compareVersions("14.0.4", "14")).toEqual(1);
|
|
|
|
expect(compareVersions("14.5", "14.4.3")).toEqual(1);
|
|
expect(compareVersions("14.5", "14.3")).toEqual(1);
|
|
expect(compareVersions("14.5", "14")).toEqual(1);
|
|
|
|
expect(compareVersions("14", "13.9.21")).toEqual(1);
|
|
expect(compareVersions("14", "13.9")).toEqual(1);
|
|
expect(compareVersions("14", "13")).toEqual(1);
|
|
});
|
|
|
|
it("properly checks if a version is equal to another", () => {
|
|
expect(compareVersions("14.0.4", "14.0.4")).toEqual(0);
|
|
expect(compareVersions("14.3", "14.3")).toEqual(0);
|
|
expect(compareVersions("14", "14")).toEqual(0);
|
|
expect(compareVersions("14.3", "14.3.0")).toEqual(0);
|
|
expect(compareVersions("14", "14.0.0")).toEqual(0);
|
|
});
|
|
});
|
|
|
|
describe("willExpireWithinXDays function", () => {
|
|
it("will return true if the date is within x number of days", () => {
|
|
const fiveDaysFromNow = getFutureDate(5);
|
|
expect(willExpireWithinXDays(fiveDaysFromNow, 10)).toEqual(true);
|
|
|
|
const tenDaysFromNow = getFutureDate(10);
|
|
expect(willExpireWithinXDays(tenDaysFromNow, 30)).toEqual(true);
|
|
});
|
|
|
|
it("will return false if the date is not within x number of days", () => {
|
|
const thirtyDaysFromNow = getFutureDate(30);
|
|
expect(willExpireWithinXDays(thirtyDaysFromNow, 10)).toEqual(false);
|
|
|
|
const fiftyDaysFromNow = getFutureDate(50);
|
|
expect(willExpireWithinXDays(fiftyDaysFromNow, 30)).toEqual(false);
|
|
});
|
|
|
|
it("will return false if the date has already expired", () => {
|
|
const fiveDaysAgo = getPastDate(5);
|
|
expect(willExpireWithinXDays(fiveDaysAgo, 10)).toEqual(false);
|
|
|
|
const fiftyDaysAgo = getPastDate(50);
|
|
expect(willExpireWithinXDays(fiftyDaysAgo, 30)).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("setupData function", () => {
|
|
it("sets org_logo_url_light_background to the same value as org_logo_url", () => {
|
|
const formData: IRegistrationFormData = {
|
|
email: "admin@example.com",
|
|
name: "Admin",
|
|
password: "password123",
|
|
password_confirmation: "password123",
|
|
org_name: "Fleet",
|
|
org_web_url: "",
|
|
org_logo_url: "https://example.com/logo.png",
|
|
fleet_web_address: "",
|
|
server_url: "https://fleet.example.com",
|
|
};
|
|
|
|
const result = helpers.setupData(formData);
|
|
|
|
expect(result.org_info.org_logo_url).toEqual(
|
|
"https://example.com/logo.png"
|
|
);
|
|
expect(result.org_info.org_logo_url_light_background).toEqual(
|
|
"https://example.com/logo.png"
|
|
);
|
|
});
|
|
|
|
it("sets org_logo_url_light_background to empty string when org_logo_url is not provided", () => {
|
|
const formData: IRegistrationFormData = {
|
|
email: "admin@example.com",
|
|
name: "Admin",
|
|
password: "password123",
|
|
password_confirmation: "password123",
|
|
org_name: "Fleet",
|
|
org_web_url: "",
|
|
org_logo_url: "",
|
|
fleet_web_address: "",
|
|
server_url: "https://fleet.example.com",
|
|
};
|
|
|
|
const result = helpers.setupData(formData);
|
|
|
|
expect(result.org_info.org_logo_url).toEqual("");
|
|
expect(result.org_info.org_logo_url_light_background).toEqual("");
|
|
});
|
|
});
|
|
});
|