mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-11 01:53:51 +00:00
Implemented short URLs exporting
This commit is contained in:
47
test/common/services/ReportExporter.test.ts
Normal file
47
test/common/services/ReportExporter.test.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Mock } from 'ts-mockery';
|
||||
import { CsvJson } from 'csvjson';
|
||||
import { ReportExporter } from '../../../src/common/services/ReportExporter';
|
||||
import { NormalizedVisit } from '../../../src/visits/types';
|
||||
import { windowMock } from '../../mocks/WindowMock';
|
||||
|
||||
describe('ReportExporter', () => {
|
||||
const toCSV = jest.fn();
|
||||
const csvToJsonMock = Mock.of<CsvJson>({ toCSV });
|
||||
let exporter: ReportExporter;
|
||||
|
||||
beforeEach(jest.clearAllMocks);
|
||||
beforeEach(() => {
|
||||
(global as any).Blob = class Blob {}; // eslint-disable-line @typescript-eslint/no-extraneous-class
|
||||
(global as any).URL = { createObjectURL: () => '' };
|
||||
|
||||
exporter = new ReportExporter(windowMock, csvToJsonMock);
|
||||
});
|
||||
|
||||
describe('exportVisits', () => {
|
||||
it('parses provided visits to CSV', () => {
|
||||
const visits: NormalizedVisit[] = [
|
||||
{
|
||||
browser: 'browser',
|
||||
city: 'city',
|
||||
country: 'country',
|
||||
date: 'date',
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
os: 'os',
|
||||
referer: 'referer',
|
||||
potentialBot: false,
|
||||
},
|
||||
];
|
||||
|
||||
exporter.exportVisits('my_visits.csv', visits);
|
||||
|
||||
expect(toCSV).toHaveBeenCalledWith(visits, { headers: 'key', wrap: true });
|
||||
});
|
||||
|
||||
it('skips execution when list of visits is empty', () => {
|
||||
exporter.exportVisits('my_visits.csv', []);
|
||||
|
||||
expect(toCSV).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user