Created ServersExporter test

This commit is contained in:
Alejandro Celaya
2018-08-24 10:13:55 +02:00
parent 53650938f7
commit 12ac877e2d
2 changed files with 101 additions and 9 deletions

View File

@@ -1,9 +1,7 @@
import Storage from '../../utils/Storage';
import serversService from './ServersService';
import { dissoc, head, keys, values } from 'ramda';
import csvjson from 'csvjson';
const SERVERS_STORAGE_KEY = 'servers';
const saveCsv = (window, csv) => {
const { navigator, document } = window;
const filename = 'shlink-servers.csv';
@@ -27,16 +25,14 @@ const saveCsv = (window, csv) => {
};
export class ServersExporter {
constructor(storage, window, csvjson) {
this.storage = storage;
constructor(serversService, window, csvjson) {
this.serversService = serversService;
this.window = window;
this.csvjson = csvjson;
}
exportServers = async () => {
const servers = values(this.storage.get(SERVERS_STORAGE_KEY) || {}).map(
dissoc('id')
);
const servers = values(this.serversService.listServers()).map(dissoc('id'));
try {
const csv = this.csvjson.toCSV(servers, {
@@ -50,4 +46,5 @@ export class ServersExporter {
};
}
export default new ServersExporter(Storage, global.window, csvjson);
const serverExporter = new ServersExporter(serversService, global.window, csvjson);
export default serverExporter;