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 { LastPassCsvImporter as Importer } from '../../../src/importers/lastpassCsvImporter';
import { CipherView } from '../../../src/models/view/cipherView'; import { CipherView } from '../../../src/models/view/cipherView';
import { FieldView } from '../../../src/models/view/fieldView';
import { Utils } from '../../../src/misc/utils'; import { Utils } from '../../../src/misc/utils';
import { FieldType } from '../../../src/enums';
if (Utils.isNode) { if (Utils.isNode) {
// Polyfills // Polyfills
// tslint:disable-next-line // tslint:disable-next-line
@ -28,7 +32,7 @@ Notes:some text
organizationId: null, organizationId: null,
folderId: null, folderId: null,
name: 'Credit-card', name: 'Credit-card',
notes: 'Start Date: October,2017\nsome text\n', notes: 'some text\n',
type: 3, type: 3,
card: { card: {
cardholderName: 'John Doe', cardholderName: 'John Doe',
@ -37,6 +41,13 @@ Notes:some text
expYear: '2020', expYear: '2020',
expMonth: '6', 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, organizationId: null,
folderId: null, folderId: null,
name: 'empty', name: 'empty',
notes: `Start Date: ,`, notes: null,
type: 3, 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, organizationId: null,
folderId: null, folderId: null,
name: 'noyear', name: 'noyear',
notes: `Type: Visa notes: null,
Start Date: ,`,
type: 3, type: 3,
card: { card: {
cardholderName: 'John Doe', cardholderName: 'John Doe',
@ -85,6 +104,18 @@ Start Date: ,`,
code: '321', code: '321',
expMonth: '1', 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, organizationId: null,
folderId: null, folderId: null,
name: 'nomonth', name: 'nomonth',
notes: `Type: Mastercard notes: null,
Start Date: ,`,
type: 3, type: 3,
card: { card: {
cardholderName: 'John Doe', cardholderName: 'John Doe',
number: '8765432112345678', number: '8765432112345678',
code: '987', code: '987',
expYear: '2020', 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 === ',') { if (this.isNullOrWhitespace(mappedData.expMonth) || mappedData.expMonth === ',') {
// No expiration data // No expiration data
mappedData.expMonth = null; mappedData.expMonth = undefined;
} else { } else {
const [monthString, year] = mappedData.expMonth.split(','); const [monthString, year] = mappedData.expMonth.split(',');
// Parse month name into number // Parse month name into number
if (!this.isNullOrWhitespace(monthString)) { if (!this.isNullOrWhitespace(monthString)) {
const month = new Date(Date.parse(monthString.trim() + ' 1, 2012')).getMonth() + 1; const month = new Date(Date.parse(monthString.trim() + ' 1, 2012')).getMonth() + 1;
if (isNaN(month)) { if (isNaN(month)) {
mappedData.expMonth = null; mappedData.expMonth = undefined;
} else { } else {
mappedData.expMonth = month.toString(); mappedData.expMonth = month.toString();
} }
} else { } else {
mappedData.expMonth = null; mappedData.expMonth = undefined;
} }
if (!this.isNullOrWhitespace(year)) { if (!this.isNullOrWhitespace(year)) {
mappedData.expYear = year; mappedData.expYear = year;