-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: algolia index name resolving * chore: changeset
- Loading branch information
Showing
4 changed files
with
45 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"composable-cli": patch | ||
--- | ||
|
||
algolia index name resolving fixed |
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
21 changes: 21 additions & 0 deletions
21
packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.test.ts
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,21 @@ | ||
import { resolveIndexName } from "./resolve-index-name" | ||
|
||
describe("resolveIndexName", () => { | ||
it("should resolve index name with escaped catalog name and first block of catalogId", () => { | ||
const catalogName = "Flora standard catalog" | ||
const catalogId = "7b479b7c-05b7-4a25-ae3a-dae4787b0811" | ||
|
||
const result = resolveIndexName(catalogName, catalogId) | ||
|
||
expect(result).toBe("Flora_standard_catalog_7b479b7c") | ||
}) | ||
|
||
it("should handle catalog names with leading/trailing spaces", () => { | ||
const catalogName = " Flora catalog with spaces " | ||
const catalogId = "7b479b7c-05b7-4a25-ae3a-dae4787b0811" | ||
|
||
const result = resolveIndexName(catalogName, catalogId) | ||
|
||
expect(result).toBe("Flora_catalog_with_spaces_7b479b7c") | ||
}) | ||
}) |
14 changes: 14 additions & 0 deletions
14
packages/composable-cli/src/commands/integration/algolia/utility/resolve-index-name.ts
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,14 @@ | ||
export function resolveIndexName( | ||
catalogName: string, | ||
catalogId: string, | ||
): string { | ||
const escapedName = escapeCatalogName(catalogName) | ||
const resolvedId = catalogId.split("-")[0] | ||
|
||
return `${escapedName}_${resolvedId}` | ||
} | ||
|
||
function escapeCatalogName(catalogName: string): string { | ||
// Replace leading and trailing spaces and then replace spaces with underscores | ||
return catalogName.trim().replace(/\s/g, "_") | ||
} |