mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-02 22:01:52 +00:00
Ensure forwardCredentials is included when exporting servers as CSV
This commit is contained in:
@@ -1,27 +1,35 @@
|
||||
import { fromPartial } from '@total-typescript/shoehorn';
|
||||
import type { ServersMap } from '../../../src/servers/data';
|
||||
import { serializeServer } from '../../../src/servers/data';
|
||||
import { ServersExporter } from '../../../src/servers/services/ServersExporter';
|
||||
import type { LocalStorage } from '../../../src/utils/services/LocalStorage';
|
||||
import { appendChild, removeChild, windowMock } from '../../__mocks__/Window.mock';
|
||||
|
||||
describe('ServersExporter', () => {
|
||||
const servers: ServersMap = {
|
||||
abc123: {
|
||||
id: 'abc123',
|
||||
name: 'foo',
|
||||
url: 'https://foo.com',
|
||||
apiKey: 'foo_api_key',
|
||||
autoConnect: true,
|
||||
},
|
||||
def456: {
|
||||
id: 'def456',
|
||||
name: 'bar',
|
||||
url: 'https://bar.com',
|
||||
apiKey: 'bar_api_key',
|
||||
forwardCredentials: true,
|
||||
autoConnect: false,
|
||||
},
|
||||
};
|
||||
const storageMock = fromPartial<LocalStorage>({
|
||||
get: vi.fn(() => ({
|
||||
abc123: {
|
||||
id: 'abc123',
|
||||
name: 'foo',
|
||||
autoConnect: true,
|
||||
},
|
||||
def456: {
|
||||
id: 'def456',
|
||||
name: 'bar',
|
||||
autoConnect: false,
|
||||
},
|
||||
} as any)),
|
||||
get: vi.fn(() => servers as any),
|
||||
});
|
||||
const erroneousToCsv = vi.fn(() => {
|
||||
throw new Error('');
|
||||
});
|
||||
const createCsvjsonMock = (throwError = false) => (throwError ? erroneousToCsv : vi.fn(() => ''));
|
||||
const createJsonToCsvMock = (throwError = false) => (throwError ? erroneousToCsv : vi.fn(() => ''));
|
||||
|
||||
describe('exportServers', () => {
|
||||
const error = vi.fn();
|
||||
@@ -34,8 +42,8 @@ describe('ServersExporter', () => {
|
||||
});
|
||||
|
||||
it('logs an error if something fails', () => {
|
||||
const csvjsonMock = createCsvjsonMock(true);
|
||||
const exporter = new ServersExporter(storageMock, windowMock, csvjsonMock);
|
||||
const jsonToCsvMock = createJsonToCsvMock(true);
|
||||
const exporter = new ServersExporter(storageMock, windowMock, jsonToCsvMock);
|
||||
|
||||
exporter.exportServers();
|
||||
|
||||
@@ -44,7 +52,8 @@ describe('ServersExporter', () => {
|
||||
});
|
||||
|
||||
it('makes use of download link API', () => {
|
||||
const exporter = new ServersExporter(storageMock, windowMock, createCsvjsonMock());
|
||||
const jsonToCsvMock = createJsonToCsvMock();
|
||||
const exporter = new ServersExporter(storageMock, windowMock, jsonToCsvMock);
|
||||
const { document: { createElement } } = windowMock;
|
||||
|
||||
exporter.exportServers();
|
||||
@@ -53,6 +62,7 @@ describe('ServersExporter', () => {
|
||||
expect(createElement).toHaveBeenCalledTimes(1);
|
||||
expect(appendChild).toHaveBeenCalledTimes(1);
|
||||
expect(removeChild).toHaveBeenCalledTimes(1);
|
||||
expect(jsonToCsvMock).toHaveBeenCalledWith(Object.values(servers).map(serializeServer));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user