diff --git a/package-lock.json b/package-lock.json
index 8b74c082..199aae14 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -85,7 +85,6 @@
"resize-observer-polyfill": "^1.5.1",
"sass": "^1.57.1",
"stylelint": "^14.16.0",
- "ts-mockery": "^1.2.0",
"typescript": "^5.0.2",
"vite": "^4.2.0",
"vite-plugin-pwa": "^0.14.4"
@@ -11902,14 +11901,6 @@
"node": ">=8"
}
},
- "node_modules/ts-mockery": {
- "version": "1.2.0",
- "dev": true,
- "license": "MIT",
- "peerDependencies": {
- "typescript": ">= 2.8"
- }
- },
"node_modules/ts-toolbelt": {
"version": "6.15.5",
"dev": true,
@@ -15897,6 +15888,9 @@
}
}
},
+ "caniuse-lite": {
+ "version": "1.0.30001415"
+ },
"chalk": {
"version": "5.2.0",
"dev": true
@@ -20285,11 +20279,6 @@
"version": "3.0.1",
"dev": true
},
- "ts-mockery": {
- "version": "1.2.0",
- "dev": true,
- "requires": {}
- },
"ts-toolbelt": {
"version": "6.15.5",
"dev": true
@@ -20959,4 +20948,4 @@
"dev": true
}
}
-}
\ No newline at end of file
+}
diff --git a/package.json b/package.json
index 62bb4d0d..4f0cdbf6 100644
--- a/package.json
+++ b/package.json
@@ -102,7 +102,6 @@
"resize-observer-polyfill": "^1.5.1",
"sass": "^1.57.1",
"stylelint": "^14.16.0",
- "ts-mockery": "^1.2.0",
"typescript": "^5.0.2",
"vite": "^4.2.0",
"vite-plugin-pwa": "^0.14.4"
diff --git a/test/visits/helpers/OpenMapModalBtn.test.tsx b/test/visits/helpers/OpenMapModalBtn.test.tsx
index e80cee16..91a69f7b 100644
--- a/test/visits/helpers/OpenMapModalBtn.test.tsx
+++ b/test/visits/helpers/OpenMapModalBtn.test.tsx
@@ -1,14 +1,14 @@
import { screen, waitFor } from '@testing-library/react';
-import { Mock } from 'ts-mockery';
+import { fromPartial } from '@total-typescript/shoehorn';
import { OpenMapModalBtn } from '../../../src/visits/helpers/OpenMapModalBtn';
import type { CityStats } from '../../../src/visits/types';
import { renderWithEvents } from '../../__helpers__/setUpTest';
describe('', () => {
const title = 'Foo';
- const locations = [
- Mock.of({ cityName: 'foo', count: 30, latLong: [5, 5] }),
- Mock.of({ cityName: 'bar', count: 45, latLong: [88, 88] }),
+ const locations: CityStats[] = [
+ fromPartial({ cityName: 'foo', count: 30, latLong: [5, 5] }),
+ fromPartial({ cityName: 'bar', count: 45, latLong: [88, 88] }),
];
const setUp = (activeCities?: string[]) => renderWithEvents(
,
diff --git a/test/visits/reducers/domainVisits.test.ts b/test/visits/reducers/domainVisits.test.ts
index 0135eb65..c8a5bec4 100644
--- a/test/visits/reducers/domainVisits.test.ts
+++ b/test/visits/reducers/domainVisits.test.ts
@@ -1,5 +1,5 @@
+import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
-import { Mock } from 'ts-mockery';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkState } from '../../../src/container/types';
@@ -16,25 +16,25 @@ import {
getDomainVisits as getDomainVisitsCreator,
} from '../../../src/visits/reducers/domainVisits';
import { createNewVisits } from '../../../src/visits/reducers/visitCreation';
-import type { CreateVisit, Visit } from '../../../src/visits/types';
+import type { Visit } from '../../../src/visits/types';
describe('domainVisitsReducer', () => {
const now = new Date();
- const visitsMocks = rangeOf(2, () => Mock.all());
+ const visitsMocks = rangeOf(2, () => fromPartial({}));
const getDomainVisitsCall = jest.fn();
- const buildApiClientMock = () => Mock.of({ getDomainVisits: getDomainVisitsCall });
+ const buildApiClientMock = () => fromPartial({ getDomainVisits: getDomainVisitsCall });
const getDomainVisits = getDomainVisitsCreator(buildApiClientMock);
const { reducer, cancelGetVisits: cancelGetDomainVisits } = domainVisitsReducerCreator(getDomainVisits);
beforeEach(jest.clearAllMocks);
describe('reducer', () => {
- const buildState = (data: Partial) => Mock.of(data);
+ const buildState = (data: Partial) => fromPartial(data);
it('returns loading on GET_DOMAIN_VISITS_START', () => {
const { loading } = reducer(
buildState({ loading: false }),
- getDomainVisits.pending('', Mock.all()),
+ getDomainVisits.pending('', fromPartial({})),
);
expect(loading).toEqual(true);
});
@@ -52,7 +52,7 @@ describe('domainVisitsReducer', () => {
it('stops loading and returns error on GET_DOMAIN_VISITS_ERROR', () => {
const state = reducer(
buildState({ loading: true, error: false }),
- getDomainVisits.rejected(null, '', Mock.all()),
+ getDomainVisits.rejected(null, '', fromPartial({})),
);
const { loading, error } = state;
@@ -61,10 +61,10 @@ describe('domainVisitsReducer', () => {
});
it('return visits on GET_DOMAIN_VISITS', () => {
- const actionVisits = [Mock.all(), Mock.all()];
+ const actionVisits: Visit[] = [fromPartial({}), fromPartial({})];
const { loading, error, visits } = reducer(
buildState({ loading: true, error: false }),
- getDomainVisits.fulfilled({ visits: actionVisits }, '', Mock.all()),
+ getDomainVisits.fulfilled({ visits: actionVisits }, '', fromPartial({})),
);
expect(loading).toEqual(false);
@@ -75,10 +75,10 @@ describe('domainVisitsReducer', () => {
it.each([
[{ domain: 'foo.com' }, 'foo.com', visitsMocks.length + 1],
[{ domain: 'bar.com' }, 'foo.com', visitsMocks.length],
- [Mock.of({ domain: 'foo.com' }), 'foo.com', visitsMocks.length + 1],
- [Mock.of({ domain: DEFAULT_DOMAIN }), null, visitsMocks.length + 1],
+ [fromPartial({ domain: 'foo.com' }), 'foo.com', visitsMocks.length + 1],
+ [fromPartial({ domain: DEFAULT_DOMAIN }), null, visitsMocks.length + 1],
[
- Mock.of({
+ fromPartial({
domain: 'foo.com',
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
}),
@@ -86,7 +86,7 @@ describe('domainVisitsReducer', () => {
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
domain: 'foo.com',
query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined },
}),
@@ -94,7 +94,7 @@ describe('domainVisitsReducer', () => {
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
domain: 'foo.com',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -105,7 +105,7 @@ describe('domainVisitsReducer', () => {
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
domain: 'foo.com',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -116,7 +116,7 @@ describe('domainVisitsReducer', () => {
visitsMocks.length + 1,
],
[
- Mock.of({
+ fromPartial({
domain: 'bar.com',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -127,9 +127,9 @@ describe('domainVisitsReducer', () => {
visitsMocks.length,
],
])('prepends new visits on CREATE_VISIT', (state, shortUrlDomain, expectedVisits) => {
- const shortUrl = Mock.of({ domain: shortUrlDomain });
+ const shortUrl = fromPartial({ domain: shortUrlDomain });
const { visits } = reducer(buildState({ ...state, visits: visitsMocks }), createNewVisits([
- Mock.of({ shortUrl, visit: { date: formatIsoDate(now) ?? undefined } }),
+ fromPartial({ shortUrl, visit: { date: formatIsoDate(now) ?? undefined } }),
]));
expect(visits).toHaveLength(expectedVisits);
@@ -153,7 +153,7 @@ describe('domainVisitsReducer', () => {
describe('getDomainVisits', () => {
const dispatchMock = jest.fn();
- const getState = () => Mock.of({
+ const getState = () => fromPartial({
domainVisits: { cancelLoad: false },
});
const domain = 'foo.com';
@@ -183,12 +183,12 @@ describe('domainVisitsReducer', () => {
it.each([
[
- [Mock.of({ date: formatISO(subDays(now, 20)) })],
+ [fromPartial({ date: formatISO(subDays(now, 20)) })],
getDomainVisits.fallbackToInterval('last30Days'),
3,
],
[
- [Mock.of({ date: formatISO(subDays(now, 100)) })],
+ [fromPartial({ date: formatISO(subDays(now, 100)) })],
getDomainVisits.fallbackToInterval('last180Days'),
3,
],
diff --git a/test/visits/reducers/nonOrphanVisits.test.ts b/test/visits/reducers/nonOrphanVisits.test.ts
index 98b1037e..da3da921 100644
--- a/test/visits/reducers/nonOrphanVisits.test.ts
+++ b/test/visits/reducers/nonOrphanVisits.test.ts
@@ -1,5 +1,5 @@
+import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
-import { Mock } from 'ts-mockery';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkState } from '../../../src/container/types';
@@ -16,16 +16,16 @@ import type { Visit } from '../../../src/visits/types';
describe('nonOrphanVisitsReducer', () => {
const now = new Date();
- const visitsMocks = rangeOf(2, () => Mock.all());
+ const visitsMocks = rangeOf(2, () => fromPartial({}));
const getNonOrphanVisitsCall = jest.fn();
- const buildShlinkApiClient = () => Mock.of({ getNonOrphanVisits: getNonOrphanVisitsCall });
+ const buildShlinkApiClient = () => fromPartial({ getNonOrphanVisits: getNonOrphanVisitsCall });
const getNonOrphanVisits = getNonOrphanVisitsCreator(buildShlinkApiClient);
const { reducer, cancelGetVisits: cancelGetNonOrphanVisits } = nonOrphanVisitsReducerCreator(getNonOrphanVisits);
beforeEach(jest.clearAllMocks);
describe('reducer', () => {
- const buildState = (data: Partial) => Mock.of(data);
+ const buildState = (data: Partial) => fromPartial(data);
it('returns loading on GET_NON_ORPHAN_VISITS_START', () => {
const { loading } = reducer(buildState({ loading: false }), getNonOrphanVisits.pending('', {}));
@@ -53,7 +53,7 @@ describe('nonOrphanVisitsReducer', () => {
});
it('return visits on GET_NON_ORPHAN_VISITS', () => {
- const actionVisits = [Mock.all(), Mock.all()];
+ const actionVisits: Visit[] = [fromPartial({}), fromPartial({})];
const { loading, error, visits } = reducer(
buildState({ loading: true, error: false }),
getNonOrphanVisits.fulfilled({ visits: actionVisits }, '', {}),
@@ -67,19 +67,19 @@ describe('nonOrphanVisitsReducer', () => {
it.each([
[{}, visitsMocks.length + 2],
[
- Mock.of({
+ fromPartial({
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
endDate: formatIsoDate(subDays(now, 2)) ?? undefined,
@@ -88,7 +88,7 @@ describe('nonOrphanVisitsReducer', () => {
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
endDate: formatIsoDate(addDays(now, 3)) ?? undefined,
@@ -98,7 +98,7 @@ describe('nonOrphanVisitsReducer', () => {
],
])('prepends new visits on CREATE_VISIT', (state, expectedVisits) => {
const prevState = buildState({ ...state, visits: visitsMocks });
- const visit = Mock.of({ date: formatIsoDate(now) ?? undefined });
+ const visit = fromPartial({ date: formatIsoDate(now) ?? undefined });
const { visits } = reducer(prevState, createNewVisits([{ visit }, { visit }]));
@@ -120,7 +120,7 @@ describe('nonOrphanVisitsReducer', () => {
describe('getNonOrphanVisits', () => {
const dispatchMock = jest.fn();
- const getState = () => Mock.of({
+ const getState = () => fromPartial({
orphanVisits: { cancelLoad: false },
});
@@ -151,12 +151,12 @@ describe('nonOrphanVisitsReducer', () => {
it.each([
[
- [Mock.of({ date: formatISO(subDays(now, 5)) })],
+ [fromPartial({ date: formatISO(subDays(now, 5)) })],
getNonOrphanVisits.fallbackToInterval('last7Days'),
3,
],
[
- [Mock.of({ date: formatISO(subDays(now, 200)) })],
+ [fromPartial({ date: formatISO(subDays(now, 200)) })],
getNonOrphanVisits.fallbackToInterval('last365Days'),
3,
],
diff --git a/test/visits/reducers/orphanVisits.test.ts b/test/visits/reducers/orphanVisits.test.ts
index 1071321f..62851f8d 100644
--- a/test/visits/reducers/orphanVisits.test.ts
+++ b/test/visits/reducers/orphanVisits.test.ts
@@ -1,5 +1,5 @@
+import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
-import { Mock } from 'ts-mockery';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkState } from '../../../src/container/types';
@@ -16,16 +16,16 @@ import type { Visit } from '../../../src/visits/types';
describe('orphanVisitsReducer', () => {
const now = new Date();
- const visitsMocks = rangeOf(2, () => Mock.all());
+ const visitsMocks = rangeOf(2, () => fromPartial({}));
const getOrphanVisitsCall = jest.fn();
- const buildShlinkApiClientMock = () => Mock.of({ getOrphanVisits: getOrphanVisitsCall });
+ const buildShlinkApiClientMock = () => fromPartial({ getOrphanVisits: getOrphanVisitsCall });
const getOrphanVisits = getOrphanVisitsCreator(buildShlinkApiClientMock);
const { reducer, cancelGetVisits: cancelGetOrphanVisits } = orphanVisitsReducerCreator(getOrphanVisits);
beforeEach(jest.clearAllMocks);
describe('reducer', () => {
- const buildState = (data: Partial) => Mock.of(data);
+ const buildState = (data: Partial) => fromPartial(data);
it('returns loading on GET_ORPHAN_VISITS_START', () => {
const { loading } = reducer(buildState({ loading: false }), getOrphanVisits.pending('', {}));
@@ -53,7 +53,7 @@ describe('orphanVisitsReducer', () => {
});
it('return visits on GET_ORPHAN_VISITS', () => {
- const actionVisits = [Mock.all(), Mock.all()];
+ const actionVisits: Visit[] = [fromPartial({}), fromPartial({})];
const { loading, error, visits } = reducer(
buildState({ loading: true, error: false }),
getOrphanVisits.fulfilled({ visits: actionVisits }, '', {}),
@@ -67,19 +67,19 @@ describe('orphanVisitsReducer', () => {
it.each([
[{}, visitsMocks.length + 2],
[
- Mock.of({
+ fromPartial({
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
endDate: formatIsoDate(subDays(now, 2)) ?? undefined,
@@ -88,7 +88,7 @@ describe('orphanVisitsReducer', () => {
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
endDate: formatIsoDate(addDays(now, 3)) ?? undefined,
@@ -98,7 +98,7 @@ describe('orphanVisitsReducer', () => {
],
])('prepends new visits on CREATE_VISIT', (state, expectedVisits) => {
const prevState = buildState({ ...state, visits: visitsMocks });
- const visit = Mock.of({ date: formatIsoDate(now) ?? undefined });
+ const visit = fromPartial({ date: formatIsoDate(now) ?? undefined });
const { visits } = reducer(prevState, createNewVisits([{ visit }, { visit }]));
@@ -120,7 +120,7 @@ describe('orphanVisitsReducer', () => {
describe('getOrphanVisits', () => {
const dispatchMock = jest.fn();
- const getState = () => Mock.of({
+ const getState = () => fromPartial({
orphanVisits: { cancelLoad: false },
});
@@ -149,12 +149,12 @@ describe('orphanVisitsReducer', () => {
it.each([
[
- [Mock.of({ date: formatISO(subDays(now, 5)) })],
+ [fromPartial({ date: formatISO(subDays(now, 5)) })],
getOrphanVisits.fallbackToInterval('last7Days'),
3,
],
[
- [Mock.of({ date: formatISO(subDays(now, 200)) })],
+ [fromPartial({ date: formatISO(subDays(now, 200)) })],
getOrphanVisits.fallbackToInterval('last365Days'),
3,
],
diff --git a/test/visits/reducers/shortUrlVisits.test.ts b/test/visits/reducers/shortUrlVisits.test.ts
index e5523e0d..a7ce8cb3 100644
--- a/test/visits/reducers/shortUrlVisits.test.ts
+++ b/test/visits/reducers/shortUrlVisits.test.ts
@@ -1,5 +1,5 @@
+import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
-import { Mock } from 'ts-mockery';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkState } from '../../../src/container/types';
@@ -13,20 +13,20 @@ import {
shortUrlVisitsReducerCreator,
} from '../../../src/visits/reducers/shortUrlVisits';
import { createNewVisits } from '../../../src/visits/reducers/visitCreation';
-import type { CreateVisit, Visit } from '../../../src/visits/types';
+import type { Visit } from '../../../src/visits/types';
describe('shortUrlVisitsReducer', () => {
const now = new Date();
- const visitsMocks = rangeOf(2, () => Mock.all());
+ const visitsMocks = rangeOf(2, () => fromPartial({}));
const getShortUrlVisitsCall = jest.fn();
- const buildApiClientMock = () => Mock.of({ getShortUrlVisits: getShortUrlVisitsCall });
+ const buildApiClientMock = () => fromPartial({ getShortUrlVisits: getShortUrlVisitsCall });
const getShortUrlVisits = getShortUrlVisitsCreator(buildApiClientMock);
const { reducer, cancelGetVisits: cancelGetShortUrlVisits } = shortUrlVisitsReducerCreator(getShortUrlVisits);
beforeEach(jest.clearAllMocks);
describe('reducer', () => {
- const buildState = (data: Partial) => Mock.of(data);
+ const buildState = (data: Partial) => fromPartial(data);
it('returns loading on GET_SHORT_URL_VISITS_START', () => {
const { loading } = reducer(buildState({ loading: false }), getShortUrlVisits.pending('', { shortCode: '' }));
@@ -54,7 +54,7 @@ describe('shortUrlVisitsReducer', () => {
});
it('return visits on GET_SHORT_URL_VISITS', () => {
- const actionVisits = [Mock.all(), Mock.all()];
+ const actionVisits: Visit[] = [fromPartial({}), fromPartial({})];
const { loading, error, visits } = reducer(
buildState({ loading: true, error: false }),
getShortUrlVisits.fulfilled({ visits: actionVisits }, '', { shortCode: '' }),
@@ -69,21 +69,21 @@ describe('shortUrlVisitsReducer', () => {
[{ shortCode: 'abc123' }, visitsMocks.length + 1],
[{ shortCode: 'def456' }, visitsMocks.length],
[
- Mock.of({
+ fromPartial({
shortCode: 'abc123',
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
shortCode: 'abc123',
query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
shortCode: 'abc123',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -93,7 +93,7 @@ describe('shortUrlVisitsReducer', () => {
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
shortCode: 'abc123',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -103,7 +103,7 @@ describe('shortUrlVisitsReducer', () => {
visitsMocks.length + 1,
],
[
- Mock.of({
+ fromPartial({
shortCode: 'def456',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -123,7 +123,7 @@ describe('shortUrlVisitsReducer', () => {
const { visits } = reducer(
prevState,
- createNewVisits([Mock.of({ shortUrl, visit: { date: formatIsoDate(now) ?? undefined } })]),
+ createNewVisits([fromPartial({ shortUrl, visit: { date: formatIsoDate(now) ?? undefined } })]),
);
expect(visits).toHaveLength(expectedVisits);
@@ -144,8 +144,8 @@ describe('shortUrlVisitsReducer', () => {
describe('getShortUrlVisits', () => {
const dispatchMock = jest.fn();
- const getState = () => Mock.of({
- shortUrlVisits: Mock.of({ cancelLoad: false }),
+ const getState = () => fromPartial({
+ shortUrlVisits: { cancelLoad: false },
});
it.each([
@@ -197,12 +197,12 @@ describe('shortUrlVisitsReducer', () => {
it.each([
[
- [Mock.of({ date: formatISO(subDays(now, 5)) })],
+ [fromPartial({ date: formatISO(subDays(now, 5)) })],
getShortUrlVisits.fallbackToInterval('last7Days'),
3,
],
[
- [Mock.of({ date: formatISO(subDays(now, 200)) })],
+ [fromPartial({ date: formatISO(subDays(now, 200)) })],
getShortUrlVisits.fallbackToInterval('last365Days'),
3,
],
diff --git a/test/visits/reducers/tagVisits.test.ts b/test/visits/reducers/tagVisits.test.ts
index f62d068b..8fd1df0b 100644
--- a/test/visits/reducers/tagVisits.test.ts
+++ b/test/visits/reducers/tagVisits.test.ts
@@ -1,5 +1,5 @@
+import { fromPartial } from '@total-typescript/shoehorn';
import { addDays, formatISO, subDays } from 'date-fns';
-import { Mock } from 'ts-mockery';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkVisits } from '../../../src/api/types';
import type { ShlinkState } from '../../../src/container/types';
@@ -13,20 +13,20 @@ import {
tagVisitsReducerCreator,
} from '../../../src/visits/reducers/tagVisits';
import { createNewVisits } from '../../../src/visits/reducers/visitCreation';
-import type { CreateVisit, Visit } from '../../../src/visits/types';
+import type { Visit } from '../../../src/visits/types';
describe('tagVisitsReducer', () => {
const now = new Date();
- const visitsMocks = rangeOf(2, () => Mock.all());
+ const visitsMocks = rangeOf(2, () => fromPartial({}));
const getTagVisitsCall = jest.fn();
- const buildShlinkApiClientMock = () => Mock.of({ getTagVisits: getTagVisitsCall });
+ const buildShlinkApiClientMock = () => fromPartial({ getTagVisits: getTagVisitsCall });
const getTagVisits = getTagVisitsCreator(buildShlinkApiClientMock);
const { reducer, cancelGetVisits: cancelGetTagVisits } = tagVisitsReducerCreator(getTagVisits);
beforeEach(jest.clearAllMocks);
describe('reducer', () => {
- const buildState = (data: Partial) => Mock.of(data);
+ const buildState = (data: Partial) => fromPartial(data);
it('returns loading on GET_TAG_VISITS_START', () => {
const { loading } = reducer(buildState({ loading: false }), getTagVisits.pending('', { tag: '' }));
@@ -54,7 +54,7 @@ describe('tagVisitsReducer', () => {
});
it('return visits on GET_TAG_VISITS', () => {
- const actionVisits = [Mock.all(), Mock.all()];
+ const actionVisits: Visit[] = [fromPartial({}), fromPartial({})];
const { loading, error, visits } = reducer(
buildState({ loading: true, error: false }),
getTagVisits.fulfilled({ visits: actionVisits }, '', { tag: '' }),
@@ -69,21 +69,21 @@ describe('tagVisitsReducer', () => {
[{ tag: 'foo' }, visitsMocks.length + 1],
[{ tag: 'bar' }, visitsMocks.length],
[
- Mock.of({
+ fromPartial({
tag: 'foo',
query: { endDate: formatIsoDate(subDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
tag: 'foo',
query: { startDate: formatIsoDate(addDays(now, 1)) ?? undefined },
}),
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
tag: 'foo',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -93,7 +93,7 @@ describe('tagVisitsReducer', () => {
visitsMocks.length,
],
[
- Mock.of({
+ fromPartial({
tag: 'foo',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -103,7 +103,7 @@ describe('tagVisitsReducer', () => {
visitsMocks.length + 1,
],
[
- Mock.of({
+ fromPartial({
tag: 'bar',
query: {
startDate: formatIsoDate(subDays(now, 5)) ?? undefined,
@@ -123,7 +123,7 @@ describe('tagVisitsReducer', () => {
const { visits } = reducer(
prevState,
- createNewVisits([Mock.of({ shortUrl, visit: { date: formatIsoDate(now) ?? undefined } })]),
+ createNewVisits([fromPartial({ shortUrl, visit: { date: formatIsoDate(now) ?? undefined } })]),
);
expect(visits).toHaveLength(expectedVisits);
@@ -144,7 +144,7 @@ describe('tagVisitsReducer', () => {
describe('getTagVisits', () => {
const dispatchMock = jest.fn();
- const getState = () => Mock.of({
+ const getState = () => fromPartial({
tagVisits: { cancelLoad: false },
});
const tag = 'foo';
@@ -174,12 +174,12 @@ describe('tagVisitsReducer', () => {
it.each([
[
- [Mock.of({ date: formatISO(subDays(now, 20)) })],
+ [fromPartial({ date: formatISO(subDays(now, 20)) })],
getTagVisits.fallbackToInterval('last30Days'),
3,
],
[
- [Mock.of({ date: formatISO(subDays(now, 100)) })],
+ [fromPartial({ date: formatISO(subDays(now, 100)) })],
getTagVisits.fallbackToInterval('last180Days'),
3,
],
diff --git a/test/visits/reducers/visitCreation.test.ts b/test/visits/reducers/visitCreation.test.ts
index 7c9a35ed..30dbf7e7 100644
--- a/test/visits/reducers/visitCreation.test.ts
+++ b/test/visits/reducers/visitCreation.test.ts
@@ -1,12 +1,12 @@
-import { Mock } from 'ts-mockery';
+import { fromPartial } from '@total-typescript/shoehorn';
import type { ShortUrl } from '../../../src/short-urls/data';
import { createNewVisits } from '../../../src/visits/reducers/visitCreation';
import type { Visit } from '../../../src/visits/types';
describe('visitCreationReducer', () => {
describe('createNewVisits', () => {
- const shortUrl = Mock.all();
- const visit = Mock.all();
+ const shortUrl = fromPartial({});
+ const visit = fromPartial({});
it('just returns the action with proper type', () => {
const { payload } = createNewVisits([{ shortUrl, visit }]);
diff --git a/test/visits/reducers/visitsOverview.test.ts b/test/visits/reducers/visitsOverview.test.ts
index a46f9561..5b9af30d 100644
--- a/test/visits/reducers/visitsOverview.test.ts
+++ b/test/visits/reducers/visitsOverview.test.ts
@@ -1,10 +1,9 @@
-import { Mock } from 'ts-mockery';
+import { fromPartial } from '@total-typescript/shoehorn';
import type { ShlinkApiClient } from '../../../src/api/services/ShlinkApiClient';
import type { ShlinkVisitsOverview } from '../../../src/api/types';
import type { ShlinkState } from '../../../src/container/types';
import { createNewVisits } from '../../../src/visits/reducers/visitCreation';
import type {
- ParsedVisitsOverview,
PartialVisitsSummary,
VisitsOverview,
} from '../../../src/visits/reducers/visitsOverview';
@@ -12,18 +11,18 @@ import {
loadVisitsOverview as loadVisitsOverviewCreator,
visitsOverviewReducerCreator,
} from '../../../src/visits/reducers/visitsOverview';
-import type { CreateVisit, OrphanVisit, Visit } from '../../../src/visits/types';
+import type { OrphanVisit } from '../../../src/visits/types';
describe('visitsOverviewReducer', () => {
const getVisitsOverview = jest.fn();
- const buildApiClientMock = () => Mock.of({ getVisitsOverview });
+ const buildApiClientMock = () => fromPartial({ getVisitsOverview });
const loadVisitsOverview = loadVisitsOverviewCreator(buildApiClientMock);
const { reducer } = visitsOverviewReducerCreator(loadVisitsOverview);
beforeEach(jest.clearAllMocks);
describe('reducer', () => {
- const state = (payload: Partial = {}) => Mock.of(payload);
+ const state = (payload: Partial = {}) => fromPartial(payload);
it('returns loading on GET_OVERVIEW_START', () => {
const { loading } = reducer(
@@ -45,7 +44,7 @@ describe('visitsOverviewReducer', () => {
});
it('return visits overview on GET_OVERVIEW', () => {
- const action = loadVisitsOverview.fulfilled(Mock.of({
+ const action = loadVisitsOverview.fulfilled(fromPartial({
nonOrphanVisits: { total: 100 },
}), 'requestId');
const { loading, error, nonOrphanVisits } = reducer(state({ loading: true, error: false }), action);
@@ -65,17 +64,11 @@ describe('visitsOverviewReducer', () => {
orphanVisits: { total: providedOrphanVisitsCount },
}),
createNewVisits([
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.all() }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
]),
);
@@ -120,18 +113,12 @@ describe('visitsOverviewReducer', () => {
orphanVisits: { total: 200, ...initialOrphanVisits },
}),
createNewVisits([
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.of({ potentialBot: true }) }),
- Mock.of({ visit: Mock.of({ potentialBot: true }) }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '', potentialBot: true }),
- }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: { potentialBot: true } }),
+ fromPartial({ visit: { potentialBot: true } }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '', potentialBot: true }) }),
]),
);
@@ -142,7 +129,7 @@ describe('visitsOverviewReducer', () => {
describe('loadVisitsOverview', () => {
const dispatchMock = jest.fn();
- const getState = () => Mock.of();
+ const getState = () => fromPartial({});
it.each([
[
@@ -167,7 +154,7 @@ describe('visitsOverviewReducer', () => {
},
],
])('dispatches start and success when promise is resolved', async (serverResult, dispatchedPayload) => {
- const resolvedOverview = Mock.of(serverResult);
+ const resolvedOverview = fromPartial(serverResult);
getVisitsOverview.mockResolvedValue(resolvedOverview);
await loadVisitsOverview()(dispatchMock, getState, {});
diff --git a/test/visits/services/VisitsParser.test.ts b/test/visits/services/VisitsParser.test.ts
index 25cd5d39..6797601f 100644
--- a/test/visits/services/VisitsParser.test.ts
+++ b/test/visits/services/VisitsParser.test.ts
@@ -1,10 +1,10 @@
-import { Mock } from 'ts-mockery';
+import { fromPartial } from '@total-typescript/shoehorn';
import { normalizeVisits, processStatsFromVisits } from '../../../src/visits/services/VisitsParser';
import type { OrphanVisit, Visit, VisitsStats } from '../../../src/visits/types';
describe('VisitsParser', () => {
const visits: Visit[] = [
- Mock.of({
+ fromPartial({
userAgent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',
referer: 'https://google.com',
potentialBot: false,
@@ -15,7 +15,7 @@ describe('VisitsParser', () => {
longitude: -543.21,
},
}),
- Mock.of({
+ fromPartial({
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0',
referer: 'https://google.com',
potentialBot: false,
@@ -26,7 +26,7 @@ describe('VisitsParser', () => {
longitude: 6758,
},
}),
- Mock.of({
+ fromPartial({
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
potentialBot: false,
visitLocation: {
@@ -34,7 +34,7 @@ describe('VisitsParser', () => {
cityName: '',
},
}),
- Mock.of({
+ fromPartial({
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
referer: 'https://m.facebook.com',
potentialBot: false,
@@ -45,13 +45,13 @@ describe('VisitsParser', () => {
longitude: -543.21,
},
}),
- Mock.of({
+ fromPartial({
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36 OPR/38.0.2220.41',
potentialBot: true,
}),
];
const orphanVisits: OrphanVisit[] = [
- Mock.of({
+ fromPartial({
type: 'base_url',
visitedUrl: 'foo',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X x.y; rv:42.0) Gecko/20100101 Firefox/42.0',
@@ -64,12 +64,12 @@ describe('VisitsParser', () => {
longitude: 6758,
},
}),
- Mock.of({
+ fromPartial({
type: 'regular_404',
visitedUrl: 'bar',
potentialBot: true,
}),
- Mock.of({
+ fromPartial({
type: 'invalid_short_url',
visitedUrl: 'bar',
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
diff --git a/test/visits/types/helpers.test.ts b/test/visits/types/helpers.test.ts
index 75f915c3..9d9aaf94 100644
--- a/test/visits/types/helpers.test.ts
+++ b/test/visits/types/helpers.test.ts
@@ -1,7 +1,7 @@
-import { Mock } from 'ts-mockery';
+import { fromPartial } from '@total-typescript/shoehorn';
import type { ShlinkVisitsParams } from '../../../src/api/types';
import { formatIsoDate, parseDate } from '../../../src/utils/helpers/date';
-import type { CreateVisit, OrphanVisit, Visit, VisitsParams } from '../../../src/visits/types';
+import type { CreateVisit, OrphanVisit, VisitsParams } from '../../../src/visits/types';
import type { GroupedNewVisits } from '../../../src/visits/types/helpers';
import { groupNewVisitsByType, toApiParams } from '../../../src/visits/types/helpers';
@@ -11,19 +11,15 @@ describe('visitsTypeHelpers', () => {
[[], { orphanVisits: [], nonOrphanVisits: [] }],
((): [CreateVisit[], GroupedNewVisits] => {
const orphanVisits: CreateVisit[] = [
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
];
const nonOrphanVisits: CreateVisit[] = [
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.all() }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: {} }),
];
return [
@@ -33,24 +29,18 @@ describe('visitsTypeHelpers', () => {
})(),
((): [CreateVisit[], GroupedNewVisits] => {
const orphanVisits: CreateVisit[] = [
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
- Mock.of({
- visit: Mock.of({ visitedUrl: '' }),
- }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
+ fromPartial({ visit: fromPartial({ visitedUrl: '' }) }),
];
return [orphanVisits, { orphanVisits, nonOrphanVisits: [] }];
})(),
((): [CreateVisit[], GroupedNewVisits] => {
const nonOrphanVisits: CreateVisit[] = [
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.all() }),
- Mock.of({ visit: Mock.all() }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: {} }),
+ fromPartial({ visit: {} }),
];
return [nonOrphanVisits, { orphanVisits: [], nonOrphanVisits }];