forked from bitwarden/clients
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
120 additions
and
9 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,84 @@ | ||
import { LogMeOnceCsvImporter } from "../src/importers/logmeonce-csv-importer"; | ||
import { ImportResult } from "../src/models/import-result"; | ||
|
||
import { invalidRowData } from "./test-data/logmeonce-csv/invalid-row.csv"; | ||
import { invalidUrlData } from "./test-data/logmeonce-csv/invalid-url.csv"; | ||
import { missingNameData } from "./test-data/logmeonce-csv/missing-name.csv"; | ||
import { mixedData } from "./test-data/logmeonce-csv/mixed-data.csv"; | ||
import { multipleEntriesData } from "./test-data/logmeonce-csv/multiple-entries.csv"; | ||
import { validData } from "./test-data/logmeonce-csv/valid-data.csv"; | ||
|
||
describe("LogMeOnceCsvImporter", () => { | ||
let importer: LogMeOnceCsvImporter; | ||
|
||
beforeEach(() => { | ||
importer = new LogMeOnceCsvImporter(); | ||
}); | ||
|
||
it("should return success false if CSV data is null", async () => { | ||
try { | ||
const result: ImportResult = await importer.parse(null); | ||
expect(result.success).toBe(false); | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(TypeError); | ||
expect(error.message).toMatch(/Cannot read properties of null/); | ||
} | ||
}); | ||
|
||
it("should return success false if CSV data is empty", async () => { | ||
const result: ImportResult = await importer.parse(""); | ||
expect(result.success).toBe(false); | ||
}); | ||
|
||
it("should parse valid CSV data correctly", async () => { | ||
const result = await importer.parse(validData); | ||
expect(result.success).toBe(true); | ||
expect(result.ciphers.length).toBe(1); | ||
const cipher = result.ciphers[0]; | ||
expect(cipher.name).toBe("Example"); | ||
expect(cipher.login.uris[0].uri).toBe("https://example.com"); | ||
expect(cipher.notes).toBe("Some notes"); | ||
expect(cipher.login.username).toBe("[email protected]"); | ||
expect(cipher.login.password).toBe("password123"); | ||
}); | ||
|
||
it("should skip rows with insufficient columns", async () => { | ||
const result = await importer.parse(invalidRowData); | ||
expect(result.success).toBe(true); | ||
expect(result.ciphers.length).toBe(1); | ||
const cipher = result.ciphers[0]; | ||
expect(cipher.name).toBe("Example"); | ||
}); | ||
|
||
it("should handle CSV data with multiple entries", async () => { | ||
const result = await importer.parse(multipleEntriesData); | ||
expect(result.success).toBe(true); | ||
expect(result.ciphers.length).toBe(2); | ||
expect(result.ciphers[0].name).toBe("Example1"); | ||
expect(result.ciphers[1].name).toBe("Example2"); | ||
}); | ||
|
||
it("should handle CSV data with multiple entries and invalid rows", async () => { | ||
const result = await importer.parse(mixedData); | ||
expect(result.success).toBe(true); | ||
expect(result.ciphers.length).toBe(2); | ||
expect(result.ciphers[0].name).toBe("Example1"); | ||
expect(result.ciphers[1].name).toBe("Example2"); | ||
}); | ||
|
||
it("should use default values for missing columns", async () => { | ||
const result = await importer.parse(missingNameData); | ||
expect(result.success).toBe(true); | ||
expect(result.ciphers.length).toBe(1); | ||
const cipher = result.ciphers[0]; | ||
expect(cipher.name).toBe("--"); | ||
}); | ||
|
||
it("should handle invalid URLs gracefully", async () => { | ||
const result = await importer.parse(invalidUrlData); | ||
expect(result.success).toBe(true); | ||
expect(result.ciphers.length).toBe(1); | ||
const cipher = result.ciphers[0]; | ||
expect(cipher.login.uris[0].uri).toBe("invalid-url"); | ||
}); | ||
}); |
4 changes: 4 additions & 0 deletions
4
libs/importer/spec/test-data/logmeonce-csv/invalid-row.csv.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,4 @@ | ||
/* eslint-disable */ | ||
export const invalidRowData = `name,url,note,group,username,password,extra | ||
Example,https://example.com,Some notes,,[email protected],password123, | ||
InvalidRow,https://invalid.com`; |
3 changes: 3 additions & 0 deletions
3
libs/importer/spec/test-data/logmeonce-csv/invalid-url.csv.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,3 @@ | ||
/* eslint-disable */ | ||
export const invalidUrlData = `name,url,note,group,username,password,extra | ||
Example,invalid-url,Some notes,,[email protected],password123,`; |
3 changes: 3 additions & 0 deletions
3
libs/importer/spec/test-data/logmeonce-csv/missing-name.csv.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,3 @@ | ||
/* eslint-disable */ | ||
export const missingNameData = `name,url,note,group,username,password,extra | ||
,,Some notes,,[email protected],password123,`; |
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 @@ | ||
/* eslint-disable */ | ||
export const mixedData = `name,url,note,group,username,password,extra | ||
Example1,https://example1.com,Notes1,,[email protected],password1, | ||
InvalidRow,https://invalid.com | ||
Example2,https://example2.com,Notes2,,[email protected],password2,`; |
4 changes: 4 additions & 0 deletions
4
libs/importer/spec/test-data/logmeonce-csv/multiple-entries.csv.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,4 @@ | ||
/* eslint-disable */ | ||
export const multipleEntriesData = `name,url,note,group,username,password,extra | ||
Example1,https://example1.com,Notes1,,[email protected],password1, | ||
Example2,https://example2.com,Notes2,,[email protected],password2,`; |
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,3 @@ | ||
/* eslint-disable */ | ||
export const validData = `name,url,note,group,username,password,extra | ||
Example,https://example.com,Some notes,,[email protected],password123,`; |
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