"use strict";

const path = require("path");

const { importFromLastPass } = require("../../source/index.js");
const { Archive } = require("buttercup");

const lpcsvPath = path.resolve(__dirname, "../resources/lastpass.csv");

module.exports = {
    export: {
        createsArchive: test => {
            importFromLastPass(lpcsvPath).then(archive => {
                test.ok(
                    archive instanceof Archive,
                    "Archive should be a Buttercup archive instance"
                );
                test.done();
            });
        },
        containsGroups: test => {
            importFromLastPass(lpcsvPath).then(archive => {
                const groups = archive.toObject().groups.map(g => g.title);
                test.ok(groups.length === 2, "There should be two groups");
                test.ok(
                    groups.includes("General"),
                    "General Group should exist"
                );
                test.ok(groups.includes("FooBar"), "FooBar Group should exist");
                test.done();
            });
        },
        containsEntries: test => {
            importFromLastPass(lpcsvPath).then(archive => {
                const entries = archive
                    .toObject()
                    .groups.map(g => g.entries)
                    .reduce((a, b) => a.concat(b));
                test.ok(entries.length === 4, "There should be four entries");
                test.ok(
                    entries[0].meta.URL === "https://foo.com",
                    "meta.URL is set correctly"
                );
                test.ok(
                    entries[0].meta.Notes === "This is extra data",
                    "meta.Notes is set correctly"
                );
                test.ok(
                    entries[0].properties.password === "thisisasecret",
                    "properties.password is set correctly"
                );
                test.ok(
                    entries[0].properties.title === "foo.com",
                    "properties.title is set correctly"
                );
                test.ok(
                    entries[0].properties.username === "user@foo.com",
                    "properties.username is set correctly"
                );
                test.done();
            });
        },
        doesntImportEmptyNotes: test => {
            importFromLastPass(lpcsvPath).then(archive => {
                const entries = archive
                    .toObject()
                    .groups.map(g => g.entries)
                    .reduce((a, b) => a.concat(b));
                test.ok(entries[1].meta.Notes === undefined);
                test.ok(entries[2].meta.Notes === undefined);
                test.done();
            });
        },
        importsMultiLineNotes: test => {
            importFromLastPass(lpcsvPath).then(archive => {
                const entries = archive
                    .toObject()
                    .groups.map(g => g.entries)
                    .reduce((a, b) => a.concat(b));
                test.ok(
                    entries[3].meta.Notes === "This is a\nmultiline string"
                );
                test.done();
            });
        }
    }
};

@@ -1490,20 +1490,26 @@
 ries%5B0%5D.
-meta
+properties
 .URL ===
@@ -1651,20 +1651,26 @@
 ries%5B0%5D.
-meta
+properties
 .Notes =
@@ -2640,20 +2640,26 @@
 ries%5B1%5D.
-meta
+properties
 .Notes =
@@ -2708,20 +2708,26 @@
 ries%5B2%5D.
-meta
+properties
 .Notes =
@@ -3130,22 +3130,52 @@
 %5B3%5D.
-meta.Notes ===
+properties.Notes ===%0A                       
  %22Th

Fix tests for core 2.0