From 3cd948fc62f7a1d3d119fa7d77431c733eedadfe Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Tue, 5 Nov 2024 19:29:56 +0100 Subject: [PATCH] test: Add simple test to make `yarn test` pass `yarn test` requires at least one test to pass but we removed all tests that were related to Search --- jest-setup.ts | 1 + jest.config.ts | 2 ++ package.json | 1 + src/helpers/client.spec.ts | 41 ++++++++++++++++++++++++++++++++++++++ src/helpers/client.ts | 2 +- yarn.lock | 9 ++++++++- 6 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/helpers/client.spec.ts diff --git a/jest-setup.ts b/jest-setup.ts index 7b0828b..0eec232 100644 --- a/jest-setup.ts +++ b/jest-setup.ts @@ -1 +1,2 @@ import '@testing-library/jest-dom'; +import 'cross-fetch/polyfill'; \ No newline at end of file diff --git a/jest.config.ts b/jest.config.ts index 4d89a84..297414a 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -26,6 +26,8 @@ export default { '\\.(css|less|scss|sass)$': '/tests/__mocks__/styleMock.js', "^@/(.*)$": "/src/$1", "^manifest.webapp$": ["/manifest.webapp"], + // Force module uuid to resolve with the CJS entry point, because Jest does not support package.json.exports. See https://github.com/uuidjs/uuid/issues/451 + "uuid": require.resolve('uuid'), }, resetMocks: true }; diff --git a/package.json b/package.json index cdc2975..8676a4a 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "@types/sharedworker": "^0.0.126", "@typescript-eslint/eslint-plugin": "^7.1.0", "@typescript-eslint/parser": "^7.1.0", + "cross-fetch": "^4.0.0", "eslint": "8.57.1", "eslint-config-prettier": "9.1.0", "eslint-plugin-import": "2.29.1", diff --git a/src/helpers/client.spec.ts b/src/helpers/client.spec.ts new file mode 100644 index 0000000..5050627 --- /dev/null +++ b/src/helpers/client.spec.ts @@ -0,0 +1,41 @@ +import CozyClient from 'cozy-client' +import PouchLink from 'cozy-pouch-link' +import { LinkPlatform } from 'cozy-pouch-link/types/types' + +import { getPouchLink } from '@/helpers/client' + +test('should retrieve PouchLink from client', () => { + const pouchLinkOptions = { + doctypes: ['io.cozy.files'], + initialSync: true, + periodicSync: false, + platform: {} as LinkPlatform, + doctypesReplicationOptions: { + 'io.cozy.files': { + strategy: 'fromRemote' + } + } + } + const pouchLink = new PouchLink(pouchLinkOptions) + const client = new CozyClient({ + links: [pouchLink] + }) + + const result = getPouchLink(client) + + expect(result).toBe(pouchLink) +}) + +test('should return null if no client', () => { + const result = getPouchLink(undefined) + + expect(result).toBe(null) +}) + +test('should return null if no PouchLink found', () => { + const client = new CozyClient() + + const result = getPouchLink(client) + + expect(result).toBe(null) +}) diff --git a/src/helpers/client.ts b/src/helpers/client.ts index 198b0a6..5bbd356 100644 --- a/src/helpers/client.ts +++ b/src/helpers/client.ts @@ -1,7 +1,7 @@ import CozyClient from 'cozy-client' import PouchLink from 'cozy-pouch-link' -export const getPouchLink = (client: CozyClient): PouchLink | null => { +export const getPouchLink = (client?: CozyClient): PouchLink | null => { if (!client) { return null } diff --git a/yarn.lock b/yarn.lock index 450bcf7..dc447f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2390,6 +2390,13 @@ create-require@^1.1.0: resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== +cross-fetch@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-4.0.0.tgz#f037aef1580bb3a1a35164ea2a848ba81b445983" + integrity sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g== + dependencies: + node-fetch "^2.6.12" + cross-spawn@^6.0.5: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" @@ -4815,7 +4822,7 @@ node-fetch@2.6.7: dependencies: whatwg-url "^5.0.0" -node-fetch@^2.6.1: +node-fetch@^2.6.1, node-fetch@^2.6.12: version "2.7.0" resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.7.0.tgz#d0f0fa6e3e2dc1d27efcd8ad99d550bda94d187d" integrity sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==