-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: export parseContainmentPath for use in apps
- Loading branch information
Showing
6 changed files
with
71 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { parseContainmentPath } from "../../src"; | ||
|
||
describe("parseContainmentPath:", () => { | ||
it("path needs even number of parts", () => { | ||
const path = "/sites/00b/initiatives"; | ||
|
||
const result = parseContainmentPath(path); | ||
expect(result.valid).toBeFalsy(); | ||
expect(result.reason).toBe( | ||
"Path does not contain an even number of parts." | ||
); | ||
}); | ||
|
||
it("path needs less than 10 parts", () => { | ||
const path = | ||
"sites/00a/initiatives/00b/projects/00c/content/00d/content/00c/content/00e"; | ||
|
||
const result = parseContainmentPath(path); | ||
expect(result.valid).toBeFalsy(); | ||
expect(result.reason).toBe("Path is > 5 entities deep."); | ||
}); | ||
|
||
it("path needs valid paths", () => { | ||
const path = "sites/00a/initiatives/00b/projects/00c/wallaby/00d"; | ||
|
||
const result = parseContainmentPath(path); | ||
expect(result.valid).toBeFalsy(); | ||
expect(result.reason).toBe("Path contains invalid segment: wallaby."); | ||
}); | ||
|
||
it("good path parses clean", () => { | ||
const path = "sites/00a/initiatives/00b/projects/00c"; | ||
const result = parseContainmentPath(path); | ||
expect(result.valid).toBeTruthy(); | ||
expect(result.reason).toBe(""); | ||
expect(result.parts).toEqual(path.split("/")); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters