"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const ava_1 = require("ava");
const library_cleaner_1 = require("./library-cleaner");
const PouchDB = require('pouchdb').defaults({ adapter: 'memory' });
PouchDB.plugin(require('pouchdb-adapter-memory'));
const models = {
    artists: [{
            _id: 'library/foo',
            name: 'Foo'
        }, {
            _id: 'library/bar',
            name: 'Bar'
        }, {
            _id: 'library/flatbush-zombies',
            name: 'Flatbush Zombies'
        }],
    albums: [{
            _id: 'library/flatbush-zombies/betteroffdead',
            name: 'BetterOffDead',
            artist: 'library/flatbush-zombies'
        }, {
            _id: 'library/bar/test',
            name: 'Test',
            artist: 'library/bar'
        }],
    tracks: [{
            _id: 'library/flatbush-zombies/betteroffdead/palm-trees',
            name: 'Palm Trees',
            album: 'library/flatbush-zombies/betteroffdead',
            artist: 'library/flatbush-zombies'
        }],
    files: [{
            _id: 'library/flatbush-zombies/betteroffdead/palm-trees/file',
            name: 'Palm Trees.mp3',
            file: 'library/flatbush-zombies/betteroffdead/palm-trees',
            album: 'library/flatbush-zombies/betteroffdead',
            artist: 'library/flatbush-zombies'
        }]
};
ava_1.default('should remove only widows', (t) => __awaiter(this, void 0, void 0, function* () {
    const artists = new PouchDB('artists');
    const albums = new PouchDB('albums');
    const tracks = new PouchDB('tracks');
    const files = new PouchDB('files');
    yield Promise.all(models.artists.map(doc => artists.put(doc)));
    yield Promise.all(models.albums.map(doc => albums.put(doc)));
    yield Promise.all(models.tracks.map(doc => tracks.put(doc)));
    yield Promise.all(models.files.map(doc => files.put(doc)));
    yield library_cleaner_1.default(PouchDB, false);
    t.deepEqual({
        artists: ['library/flatbush-zombies'],
        albums: ['library/flatbush-zombies/betteroffdead'],
        tracks: ['library/flatbush-zombies/betteroffdead/palm-trees']
    }, {
        artists: (yield artists.allDocs({})).rows.map((doc) => doc.id),
        albums: (yield albums.allDocs()).rows.map((doc) => doc.id),
        tracks: (yield tracks.allDocs()).rows.map((doc) => doc.id)
    });
}));
//# sourceMappingURL=library-cleaner.test.js.map