Skip to content

Commit

Permalink
Refactor CSV test data imports for clarity and consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
dlfi committed Nov 5, 2024
1 parent b69e123 commit eceda84
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions libs/importer/spec/logmeonce-csv-importer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { LogMeOnceCsvImporter } from "../src/importers/logmeonce-csv-importer";
import { ImportResult } from "../src/models/import-result";

import { data as logmeonceData2 } from "./test-data/logmeonce-csv/logmeonce.test.invalidRow.csv";
import { data as logmeonceData6 } from "./test-data/logmeonce-csv/logmeonce.test.invalidUrl.csv";
import { data as logmeonceData5 } from "./test-data/logmeonce-csv/logmeonce.test.missingName.csv";
import { data as logmeonceData4 } from "./test-data/logmeonce-csv/logmeonce.test.mixedData.csv";
import { data as logmeonceData3 } from "./test-data/logmeonce-csv/logmeonce.test.multipleEntries.csv";
import { data as logmeonceData } from "./test-data/logmeonce-csv/logmeonce.test.validData.csv";
import { invalidRowData } from "./test-data/logmeonce-csv/logmeonce.test.invalidRow.csv";
import { invalidUrlData } from "./test-data/logmeonce-csv/logmeonce.test.invalidUrl.csv";
import { missingNameData } from "./test-data/logmeonce-csv/logmeonce.test.missingName.csv";
import { mixedData } from "./test-data/logmeonce-csv/logmeonce.test.mixedData.csv";
import { multipleEntriesData } from "./test-data/logmeonce-csv/logmeonce.test.multipleEntries.csv";
import { validData } from "./test-data/logmeonce-csv/logmeonce.test.validData.csv";

describe("LogMeOnceCsvImporter", () => {
let importer: LogMeOnceCsvImporter;
Expand All @@ -31,7 +31,7 @@ describe("LogMeOnceCsvImporter", () => {
});

it("should parse valid CSV data correctly", async () => {
const result = await importer.parse(logmeonceData);
const result = await importer.parse(validData);
expect(result.success).toBe(true);
expect(result.ciphers.length).toBe(1);
const cipher = result.ciphers[0];
Expand All @@ -43,39 +43,39 @@ describe("LogMeOnceCsvImporter", () => {
});

it("should skip rows with insufficient columns", async () => {
const result = await importer.parse(logmeonceData2);
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(logmeonceData3);
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(logmeonceData4);
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(logmeonceData5);
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(logmeonceData6);
const result = await importer.parse(invalidUrlData);
expect(result.success).toBe(true);
expect(result.ciphers.length).toBe(1);
const cipher = result.ciphers[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
export const data = `name,url,note,group,username,password,extra
export const invalidRowData = `name,url,note,group,username,password,extra
Example,https://example.com,Some notes,,[email protected],password123,
InvalidRow,https://invalid.com`;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* eslint-disable */
export const data = `name,url,note,group,username,password,extra
export const invalidUrlData = `name,url,note,group,username,password,extra
Example,invalid-url,Some notes,,[email protected],password123,`;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* eslint-disable */
export const data = `name,url,note,group,username,password,extra
export const missingNameData = `name,url,note,group,username,password,extra
,,Some notes,,[email protected],password123,`;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
export const data = `name,url,note,group,username,password,extra
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,`;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable */
export const data = `name,url,note,group,username,password,extra
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,`;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* eslint-disable */
export const data = `name,url,note,group,username,password,extra
export const validData = `name,url,note,group,username,password,extra
Example,https://example.com,Some notes,,[email protected],password123,`;

0 comments on commit eceda84

Please sign in to comment.