1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-16 02:27:00 +02:00

fix lastpass importer tests

This commit is contained in:
Kyle Spearrin 2020-02-06 15:28:17 -05:00
parent 3c6f6dbe2f
commit 76f60dd99e
2 changed files with 92 additions and 49 deletions

View File

@ -1,8 +1,12 @@
import { LastPassCsvImporter as Importer } from '../../../src/importers/lastpassCsvImporter';
import { CipherView } from '../../../src/models/view/cipherView';
import { FieldView } from '../../../src/models/view/fieldView';
import { Utils } from '../../../src/misc/utils';
import { FieldType } from '../../../src/enums';
if (Utils.isNode) {
// Polyfills
// tslint:disable-next-line
@ -28,7 +32,7 @@ Notes:some text
organizationId: null,
folderId: null,
name: 'Credit-card',
notes: 'Start Date: October,2017\nsome text\n',
notes: 'some text\n',
type: 3,
card: {
cardholderName: 'John Doe',
@ -37,6 +41,13 @@ Notes:some text
expYear: '2020',
expMonth: '6',
},
fields: [
Object.assign(new FieldView(), {
name: 'Start Date',
value: 'October,2017',
type: FieldType.Text,
}),
],
}),
},
{
@ -55,9 +66,18 @@ Notes:",empty,,0`,
organizationId: null,
folderId: null,
name: 'empty',
notes: `Start Date: ,`,
notes: null,
type: 3,
card: {},
card: {
expMonth: undefined,
},
fields: [
Object.assign(new FieldView(), {
name: 'Start Date',
value: ',',
type: FieldType.Text,
}),
],
}),
},
{
@ -76,8 +96,7 @@ Notes:",noyear,,0`,
organizationId: null,
folderId: null,
name: 'noyear',
notes: `Type: Visa
Start Date: ,`,
notes: null,
type: 3,
card: {
cardholderName: 'John Doe',
@ -85,6 +104,18 @@ Start Date: ,`,
code: '321',
expMonth: '1',
},
fields: [
Object.assign(new FieldView(), {
name: 'Type',
value: 'Visa',
type: FieldType.Text,
}),
Object.assign(new FieldView(), {
name: 'Start Date',
value: ',',
type: FieldType.Text,
}),
],
}),
},
{
@ -103,15 +134,27 @@ Notes:",nomonth,,0`,
organizationId: null,
folderId: null,
name: 'nomonth',
notes: `Type: Mastercard
Start Date: ,`,
notes: null,
type: 3,
card: {
cardholderName: 'John Doe',
number: '8765432112345678',
code: '987',
expYear: '2020',
expMonth: undefined,
},
fields: [
Object.assign(new FieldView(), {
name: 'Type',
value: 'Mastercard',
type: FieldType.Text,
}),
Object.assign(new FieldView(), {
name: 'Start Date',
value: ',',
type: FieldType.Text,
}),
],
}),
},
];

View File

@ -177,19 +177,19 @@ export class LastPassCsvImporter extends BaseImporter implements Importer {
if (this.isNullOrWhitespace(mappedData.expMonth) || mappedData.expMonth === ',') {
// No expiration data
mappedData.expMonth = null;
mappedData.expMonth = undefined;
} else {
const [monthString, year] = mappedData.expMonth.split(',');
// Parse month name into number
if (!this.isNullOrWhitespace(monthString)) {
const month = new Date(Date.parse(monthString.trim() + ' 1, 2012')).getMonth() + 1;
if (isNaN(month)) {
mappedData.expMonth = null;
mappedData.expMonth = undefined;
} else {
mappedData.expMonth = month.toString();
}
} else {
mappedData.expMonth = null;
mappedData.expMonth = undefined;
}
if (!this.isNullOrWhitespace(year)) {
mappedData.expYear = year;