1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 15:53:27 +00:00
Files
browser/spec/common/importers/onepasswordCsvImporter.spec.ts
Matt Gibson 6fb0646481 Fix 1password importer (#217)
* Fix import of 1password csv

* 1password is using '\' as a quote escape character.

* 1password's csv headers are sometimes capitalized. We want to identify
them case insensitively

* Change cipher type based on csv type header

* Translate 1password data to correct fields

* Test identity and credit card import

* linter fixes

* Do not use node 'fs' module

Karma is being used for automated tests so node modules are not available

Co-authored-by: Matt Gibson <mdgibson@Matts-MBP.lan>
2020-12-04 12:29:31 -06:00

51 lines
1.7 KiB
TypeScript

import { OnePasswordWinCsvImporter as Importer } from '../../../src/importers/onepasswordWinCsvImporter';
import { CipherType } from '../../../src/enums';
import { data as creditCardData } from './testData/onePasswordCsv/creditCard.csv'
import { data as identityData } from './testData/onePasswordCsv/identity.csv'
describe('1Password CSV Importer', () => {
it('should parse identity imports', () => {
const importer = new Importer();
const result = importer.parse(identityData);
expect(result).not.toBeNull();
expect(result.success).toBe(true);
expect(result.ciphers.length).toBe(1);
const cipher = result.ciphers[0];
expect(cipher.type).toBe(CipherType.Identity)
expect(cipher.identity).toEqual(jasmine.objectContaining({
firstName: 'first name',
middleName: 'mi',
lastName: 'last name',
username: 'userNam3',
company: 'bitwarden',
phone: '8005555555',
email: 'email@bitwarden.com'
}));
expect(cipher.notes).toContain('address\ncity state zip\nUnited States');
});
it('should parse credit card imports', () => {
const importer = new Importer();
const result = importer.parse(creditCardData);
expect(result).not.toBeNull();
expect(result.success).toBe(true);
expect(result.ciphers.length).toBe(1);
const cipher = result.ciphers[0];
expect(cipher.type).toBe(CipherType.Card);
expect(cipher.card).toEqual(jasmine.objectContaining({
number: '4111111111111111',
code: '111',
cardholderName: 'test',
expMonth: '1',
expYear: '2030',
}));
});
});