-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-11882] Handled identity item and unsupported items during ProtonP…
…ass import. (#10967)
- Loading branch information
1 parent
3b63854
commit 1b2cc7a
Showing
6 changed files
with
504 additions
and
6 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
66 changes: 66 additions & 0 deletions
66
libs/importer/src/importers/protonpass/protonpass-import-utils.spec.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,66 @@ | ||
import { processNames } from "./protonpass-import-utils"; | ||
|
||
describe("processNames", () => { | ||
it("should use only fullName to map names if it contains at least three words, ignoring individual name fields", () => { | ||
const result = processNames("Alice Beth Carter", "Kevin", "", ""); | ||
expect(result).toEqual({ | ||
mappedFirstName: "Alice", | ||
mappedMiddleName: "Beth", | ||
mappedLastName: "Carter", | ||
}); | ||
}); | ||
|
||
it("should map extra words to the middle name if fullName contains more than three words", () => { | ||
const result = processNames("Alice Beth Middle Carter", "", "", ""); | ||
expect(result).toEqual({ | ||
mappedFirstName: "Alice", | ||
mappedMiddleName: "Beth Middle", | ||
mappedLastName: "Carter", | ||
}); | ||
}); | ||
|
||
it("should map names correctly even if fullName has words separated by more than one space", () => { | ||
const result = processNames("Alice Carter", "", "", ""); | ||
expect(result).toEqual({ | ||
mappedFirstName: "Alice", | ||
mappedMiddleName: "", | ||
mappedLastName: "Carter", | ||
}); | ||
}); | ||
|
||
it("should handle a single name in fullName and use middleName and lastName to populate rest of names", () => { | ||
const result = processNames("Alice", "", "Beth", "Carter"); | ||
expect(result).toEqual({ | ||
mappedFirstName: "Alice", | ||
mappedMiddleName: "Beth", | ||
mappedLastName: "Carter", | ||
}); | ||
}); | ||
|
||
it("should correctly map fullName when it only contains two words", () => { | ||
const result = processNames("Alice Carter", "", "", ""); | ||
expect(result).toEqual({ | ||
mappedFirstName: "Alice", | ||
mappedMiddleName: "", | ||
mappedLastName: "Carter", | ||
}); | ||
}); | ||
|
||
it("should map middle name from middleName if fullName only contains two words", () => { | ||
const result = processNames("Alice Carter", "", "Beth", ""); | ||
expect(result).toEqual({ | ||
mappedFirstName: "Alice", | ||
mappedMiddleName: "Beth", | ||
mappedLastName: "Carter", | ||
}); | ||
}); | ||
|
||
it("should fall back to firstName, middleName, and lastName if fullName is empty", () => { | ||
const result = processNames("", "Alice", "Beth", "Carter"); | ||
expect(result).toEqual({ | ||
mappedFirstName: "Alice", | ||
mappedMiddleName: "Beth", | ||
mappedLastName: "Carter", | ||
}); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
libs/importer/src/importers/protonpass/protonpass-import-utils.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 @@ | ||
export function processNames( | ||
fullname: string | null, | ||
firstname: string | null, | ||
middlename: string | null, | ||
lastname: string | null, | ||
) { | ||
let mappedFirstName = firstname; | ||
let mappedMiddleName = middlename; | ||
let mappedLastName = lastname; | ||
|
||
if (fullname) { | ||
const parts = fullname.trim().split(/\s+/); | ||
|
||
// Assign parts to first, middle, and last name based on the number of parts | ||
mappedFirstName = parts[0] || firstname; | ||
mappedLastName = parts.length > 1 ? parts[parts.length - 1] : lastname; | ||
mappedMiddleName = parts.length > 2 ? parts.slice(1, -1).join(" ") : middlename; | ||
} | ||
|
||
return { mappedFirstName, mappedMiddleName, mappedLastName }; | ||
} |
Oops, something went wrong.