Skip to content

Commit

Permalink
Merge pull request #375 from acelaya-forks/feature/servers-import-error
Browse files Browse the repository at this point in the history
Feature/servers import error
  • Loading branch information
acelaya committed Dec 30, 2020
2 parents 0822ceb + e577eb4 commit e9cef8a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
lint:
continue-on-error: true
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -21,7 +21,7 @@ jobs:
- run: npm run lint

unit-tests:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -38,7 +38,7 @@ jobs:

mutation-tests:
continue-on-error: true
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand All @@ -52,7 +52,7 @@ jobs:
- run: npm run mutate -- --mutate=$(git diff origin/main --name-only | grep -E 'src\/(.*).(ts|tsx)$' | paste -sd ",")

build-docker-image:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image-build.yml
Expand Up @@ -9,7 +9,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]
## [3.0.1] - 2020-12-30
### Added
* *Nothing*

Expand All @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* [#366](https://github.com/shlinkio/shlink-web-client/issues/366) Fixed text in visits menu jumping to next line in some tablet resolutions.
* [#367](https://github.com/shlinkio/shlink-web-client/issues/367) Removed conflicting overflow in visits table for mobile devices.
* [#365](https://github.com/shlinkio/shlink-web-client/issues/365) Fixed weird rendering of short URLs list in tablets.
* [#372](https://github.com/shlinkio/shlink-web-client/issues/372) Fixed importing servers in Android devices.


## [3.0.0] - 2020-12-22
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -6,7 +6,7 @@
"repository": "https://github.com/shlinkio/shlink-web-client",
"license": "MIT",
"scripts": {
"lint": "npm run lint:js && npm run lint:css",
"lint": "npm run lint:css && npm run lint:js",
"lint:js": "eslint --ext .js,.ts,.tsx src test scripts config",
"lint:js:fix": "npm run lint:js -- --fix",
"lint:css": "stylelint src/*.scss src/**/*.scss",
Expand Down
10 changes: 8 additions & 2 deletions src/servers/services/ServersImporter.ts
@@ -1,13 +1,19 @@
import { CsvJson } from 'csvjson';
import { ServerData } from '../data';

const CSV_MIME_TYPE = 'text/csv';

interface CsvFile extends File {
type: 'text/csv' | 'text/comma-separated-values' | 'application/csv';
}

const CSV_MIME_TYPES = [ 'text/csv', 'text/comma-separated-values', 'application/csv' ];
const isCsv = (file?: File | null): file is CsvFile => !!file && CSV_MIME_TYPES.includes(file.type);

export default class ServersImporter {
public constructor(private readonly csvjson: CsvJson, private readonly fileReaderFactory: () => FileReader) {}

public readonly importServersFromFile = async (file?: File | null): Promise<ServerData[]> => {
if (!file || file.type !== CSV_MIME_TYPE) {
if (!isCsv(file)) {
throw new Error('No file provided or file is not a CSV');
}

Expand Down
8 changes: 6 additions & 2 deletions test/servers/services/ServersImporter.test.ts
Expand Up @@ -29,8 +29,12 @@ describe('ServersImporter', () => {
);
});

it('reads file when a CSV is provided', async () => {
await importer.importServersFromFile(Mock.of<File>({ type: 'text/csv' }));
it.each([
[ 'text/csv' ],
[ 'text/comma-separated-values' ],
[ 'application/csv' ],
])('reads file when a CSV is provided', async (type) => {
await importer.importServersFromFile(Mock.of<File>({ type }));

expect(readAsText).toHaveBeenCalledTimes(1);
expect(toObject).toHaveBeenCalledTimes(1);
Expand Down

0 comments on commit e9cef8a

Please sign in to comment.