From f3a2535e2fbf81d7caeb35d38fb6a2b726a7a787 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 27 Aug 2020 17:56:48 +0200 Subject: [PATCH] Defined visits TS types --- src/short-urls/reducers/shortUrlsList.js | 1 + src/visits/reducers/visitCreation.js | 3 -- src/visits/reducers/visitCreation.ts | 12 +++++ src/visits/types/index.js | 25 --------- src/visits/types/index.ts | 59 ++++++++++++++++++++++ test/visits/reducers/visitCreation.test.js | 10 ---- test/visits/reducers/visitCreation.test.ts | 16 ++++++ 7 files changed, 88 insertions(+), 38 deletions(-) delete mode 100644 src/visits/reducers/visitCreation.js create mode 100644 src/visits/reducers/visitCreation.ts delete mode 100644 src/visits/types/index.js create mode 100644 src/visits/types/index.ts delete mode 100644 test/visits/reducers/visitCreation.test.js create mode 100644 test/visits/reducers/visitCreation.test.ts diff --git a/src/short-urls/reducers/shortUrlsList.js b/src/short-urls/reducers/shortUrlsList.js index 90d2b1c8..f9a23e7f 100644 --- a/src/short-urls/reducers/shortUrlsList.js +++ b/src/short-urls/reducers/shortUrlsList.js @@ -14,6 +14,7 @@ export const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR export const LIST_SHORT_URLS = 'shlink/shortUrlsList/LIST_SHORT_URLS'; /* eslint-enable padding-line-between-statements */ +/** @deprecated Use ShortUrl interface instead */ export const shortUrlType = PropTypes.shape({ shortCode: PropTypes.string, shortUrl: PropTypes.string, diff --git a/src/visits/reducers/visitCreation.js b/src/visits/reducers/visitCreation.js deleted file mode 100644 index e37890a1..00000000 --- a/src/visits/reducers/visitCreation.js +++ /dev/null @@ -1,3 +0,0 @@ -export const CREATE_VISIT = 'shlink/visitCreation/CREATE_VISIT'; - -export const createNewVisit = ({ shortUrl, visit }) => ({ shortUrl, visit, type: CREATE_VISIT }); diff --git a/src/visits/reducers/visitCreation.ts b/src/visits/reducers/visitCreation.ts new file mode 100644 index 00000000..735acf6d --- /dev/null +++ b/src/visits/reducers/visitCreation.ts @@ -0,0 +1,12 @@ +import { Action } from 'redux'; +import { CreateVisit } from '../types'; + +export const CREATE_VISIT = 'shlink/visitCreation/CREATE_VISIT'; + +type CreateVisitAction = Action & CreateVisit; + +export const createNewVisit = ({ shortUrl, visit }: CreateVisit): CreateVisitAction => ({ + type: CREATE_VISIT, + shortUrl, + visit, +}); diff --git a/src/visits/types/index.js b/src/visits/types/index.js deleted file mode 100644 index bd6d1383..00000000 --- a/src/visits/types/index.js +++ /dev/null @@ -1,25 +0,0 @@ -import PropTypes from 'prop-types'; - -export const VisitType = PropTypes.shape({ - referer: PropTypes.string, - date: PropTypes.string, - userAgent: PropTypes.string, - visitLocations: PropTypes.shape({ - countryCode: PropTypes.string, - countryName: PropTypes.string, - regionName: PropTypes.string, - cityName: PropTypes.string, - latitude: PropTypes.number, - longitude: PropTypes.number, - timezone: PropTypes.string, - isEmpty: PropTypes.bool, - }), -}); - -export const VisitsInfoType = PropTypes.shape({ - visits: PropTypes.arrayOf(VisitType), - loading: PropTypes.bool, - loadingLarge: PropTypes.bool, - error: PropTypes.bool, - progress: PropTypes.number, -}); diff --git a/src/visits/types/index.ts b/src/visits/types/index.ts new file mode 100644 index 00000000..7ade9fd9 --- /dev/null +++ b/src/visits/types/index.ts @@ -0,0 +1,59 @@ +import PropTypes from 'prop-types'; +import { ShortUrl } from '../../short-urls/data'; + +/** @deprecated Use Visit interface instead */ +export const VisitType = PropTypes.shape({ + referer: PropTypes.string, + date: PropTypes.string, + userAgent: PropTypes.string, + visitLocation: PropTypes.shape({ + countryCode: PropTypes.string, + countryName: PropTypes.string, + regionName: PropTypes.string, + cityName: PropTypes.string, + latitude: PropTypes.number, + longitude: PropTypes.number, + timezone: PropTypes.string, + isEmpty: PropTypes.bool, + }), +}); + +/** @deprecated Use VisitsInfo interface instead */ +export const VisitsInfoType = PropTypes.shape({ + visits: PropTypes.arrayOf(VisitType), + loading: PropTypes.bool, + loadingLarge: PropTypes.bool, + error: PropTypes.bool, + progress: PropTypes.number, +}); + +export interface VisitsInfo { + visits: Visit[]; + loading: boolean; + loadingLarge: boolean; + error: boolean; + progress: number; +} + +interface VisitLocation { + countryCode: string | null; + countryName: string | null; + regionName: string | null; + cityName: string | null; + latitude: number | null; + longitude: number | null; + timezone: string | null; + isEmpty: boolean; +} + +export interface Visit { + referer: string; + date: string; + userAgent: string; + visitLocation: VisitLocation | null; +} + +export interface CreateVisit { + shortUrl: ShortUrl; + visit: Visit; +} diff --git a/test/visits/reducers/visitCreation.test.js b/test/visits/reducers/visitCreation.test.js deleted file mode 100644 index 7f8dbe3b..00000000 --- a/test/visits/reducers/visitCreation.test.js +++ /dev/null @@ -1,10 +0,0 @@ -import { CREATE_VISIT, createNewVisit } from '../../../src/visits/reducers/visitCreation'; - -describe('visitCreationReducer', () => { - describe('createNewVisit', () => { - it('just returns the action with proper type', () => - expect(createNewVisit({ shortUrl: {}, visit: {} })).toEqual( - { type: CREATE_VISIT, shortUrl: {}, visit: {} }, - )); - }); -}); diff --git a/test/visits/reducers/visitCreation.test.ts b/test/visits/reducers/visitCreation.test.ts new file mode 100644 index 00000000..4149f99c --- /dev/null +++ b/test/visits/reducers/visitCreation.test.ts @@ -0,0 +1,16 @@ +import { Mock } from 'ts-mockery'; +import { CREATE_VISIT, createNewVisit } from '../../../src/visits/reducers/visitCreation'; +import { ShortUrl } from '../../../src/short-urls/data'; +import { Visit } from '../../../src/visits/types'; + +describe('visitCreationReducer', () => { + describe('createNewVisit', () => { + const shortUrl = Mock.all(); + const visit = Mock.all(); + + it('just returns the action with proper type', () => + expect(createNewVisit({ shortUrl, visit })).toEqual( + { type: CREATE_VISIT, shortUrl, visit }, + )); + }); +});