mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-02 08:40:08 +01:00
fix lastpass importer tests
This commit is contained in:
parent
3c6f6dbe2f
commit
76f60dd99e
@ -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
|
||||||
@ -24,19 +28,26 @@ Expiration Date:June,2020
|
|||||||
Notes:some text
|
Notes:some text
|
||||||
",Credit-card,,0`,
|
",Credit-card,,0`,
|
||||||
expected: Object.assign(new CipherView(), {
|
expected: Object.assign(new CipherView(), {
|
||||||
id: null,
|
id: null,
|
||||||
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',
|
||||||
number: '1234567812345678',
|
number: '1234567812345678',
|
||||||
code: '123',
|
code: '123',
|
||||||
expYear: '2020',
|
expYear: '2020',
|
||||||
expMonth: '6',
|
expMonth: '6',
|
||||||
},
|
},
|
||||||
|
fields: [
|
||||||
|
Object.assign(new FieldView(), {
|
||||||
|
name: 'Start Date',
|
||||||
|
value: 'October,2017',
|
||||||
|
type: FieldType.Text,
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -51,13 +62,22 @@ Start Date:,
|
|||||||
Expiration Date:,
|
Expiration Date:,
|
||||||
Notes:",empty,,0`,
|
Notes:",empty,,0`,
|
||||||
expected: Object.assign(new CipherView(), {
|
expected: Object.assign(new CipherView(), {
|
||||||
id: null,
|
id: null,
|
||||||
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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -72,19 +92,30 @@ Start Date:,
|
|||||||
Expiration Date:January,
|
Expiration Date:January,
|
||||||
Notes:",noyear,,0`,
|
Notes:",noyear,,0`,
|
||||||
expected: Object.assign(new CipherView(), {
|
expected: Object.assign(new CipherView(), {
|
||||||
id: null,
|
id: null,
|
||||||
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',
|
number: '1234567887654321',
|
||||||
number: '1234567887654321',
|
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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -99,19 +130,31 @@ Start Date:,
|
|||||||
Expiration Date:,2020
|
Expiration Date:,2020
|
||||||
Notes:",nomonth,,0`,
|
Notes:",nomonth,,0`,
|
||||||
expected: Object.assign(new CipherView(), {
|
expected: Object.assign(new CipherView(), {
|
||||||
id: null,
|
id: null,
|
||||||
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,
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
@ -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;
|
||||||
|
Loading…
Reference in New Issue
Block a user