diff --git a/package-lock.json b/package-lock.json index 7f7da90..33e68fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -976,12 +976,6 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, - "node_modules/@one-ini/wasm": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@one-ini/wasm/-/wasm-0.1.1.tgz", - "integrity": "sha512-XuySG1E38YScSJoMlqovLru4KTUNSjgVTIjyh7qMX6aNN5HY5Ct5LhRJdxO79JtTzKfzV/bnWpz+zquYrISsvw==", - "dev": true - }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", @@ -1237,36 +1231,11 @@ "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.3.4.tgz", "integrity": "sha512-7OjdcV8vQ74eiz1TZLzZP4JwqM5fA94K6yntPS5Z25r9HDuGNzaGdgvwKYq6S+MxwF0TFRwe50fIR/MYnakdkQ==" }, - "node_modules/@vue/test-utils": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/@vue/test-utils/-/test-utils-2.4.1.tgz", - "integrity": "sha512-VO8nragneNzUZUah6kOjiFmD/gwRjUauG9DROh6oaOeFwX1cZRUNHhdeogE8635cISigXFTtGLUQWx5KCb0xeg==", - "dev": true, - "dependencies": { - "js-beautify": "1.14.9", - "vue-component-type-helpers": "1.8.4" - }, - "peerDependencies": { - "@vue/server-renderer": "^3.0.1", - "vue": "^3.0.1" - }, - "peerDependenciesMeta": { - "@vue/server-renderer": { - "optional": true - } - } - }, "node_modules/abab": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz", "integrity": "sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==" }, - "node_modules/abbrev": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", - "dev": true - }, "node_modules/acorn": { "version": "8.10.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", @@ -1399,6 +1368,18 @@ "follow-redirects": "^1.14.0" } }, + "node_modules/axios-mock-adapter": { + "version": "1.22.0", + "resolved": "https://registry.npmjs.org/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz", + "integrity": "sha512-dmI0KbkyAhntUR05YY96qg2H6gg0XMl2+qTW0xmYg6Up+BFBAJYRLROMXRdDEL06/Wqwa0TJThAYvFtSFdRCZw==", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "is-buffer": "^2.0.5" + }, + "peerDependencies": { + "axios": ">= 0.17.0" + } + }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -1512,6 +1493,10 @@ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", "dev": true }, + "node_modules/bones-ui-tests": { + "resolved": "tests/Bones.UI.Tests", + "link": true + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -1731,31 +1716,12 @@ "node": ">= 0.8" } }, - "node_modules/commander": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", - "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", - "dev": true, - "engines": { - "node": ">=14" - } - }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, - "node_modules/config-chain": { - "version": "1.1.13", - "resolved": "https://registry.npmjs.org/config-chain/-/config-chain-1.1.13.tgz", - "integrity": "sha512-qj+f8APARXHrM0hraqXYb2/bOVSV4PvJQlNZ/DVj0QrmNM2q2euizkeuVckQ57J+W0mRH6Hvi+k50M4Jul2VRQ==", - "dev": true, - "dependencies": { - "ini": "^1.3.4", - "proto-list": "~1.2.1" - } - }, "node_modules/convert-source-map": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", @@ -1917,81 +1883,6 @@ "node": ">=12" } }, - "node_modules/editorconfig": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/editorconfig/-/editorconfig-1.0.4.tgz", - "integrity": "sha512-L9Qe08KWTlqYMVvMcTIvMAdl1cDUubzRNYL+WfA4bLDMHe4nemKkpmYzkznE1FwLKu0EEmy6obgQKzMJrg4x9Q==", - "dev": true, - "dependencies": { - "@one-ini/wasm": "0.1.1", - "commander": "^10.0.0", - "minimatch": "9.0.1", - "semver": "^7.5.3" - }, - "bin": { - "editorconfig": "bin/editorconfig" - }, - "engines": { - "node": ">=14" - } - }, - "node_modules/editorconfig/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/editorconfig/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/editorconfig/node_modules/minimatch": { - "version": "9.0.1", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.1.tgz", - "integrity": "sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/editorconfig/node_modules/semver": { - "version": "7.5.4", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.4.tgz", - "integrity": "sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/editorconfig/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true - }, "node_modules/electron-to-chromium": { "version": "1.4.542", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.542.tgz", @@ -2446,18 +2337,34 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, - "node_modules/ini": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", - "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", - "dev": true - }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", "dev": true }, + "node_modules/is-buffer": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz", + "integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "engines": { + "node": ">=4" + } + }, "node_modules/is-core-module": { "version": "2.13.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.0.tgz", @@ -3229,66 +3136,6 @@ "url": "https://github.com/chalk/supports-color?sponsor=1" } }, - "node_modules/js-beautify": { - "version": "1.14.9", - "resolved": "https://registry.npmjs.org/js-beautify/-/js-beautify-1.14.9.tgz", - "integrity": "sha512-coM7xq1syLcMyuVGyToxcj2AlzhkDjmfklL8r0JgJ7A76wyGMpJ1oA35mr4APdYNO/o/4YY8H54NQIJzhMbhBg==", - "dev": true, - "dependencies": { - "config-chain": "^1.1.13", - "editorconfig": "^1.0.3", - "glob": "^8.1.0", - "nopt": "^6.0.0" - }, - "bin": { - "css-beautify": "js/bin/css-beautify.js", - "html-beautify": "js/bin/html-beautify.js", - "js-beautify": "js/bin/js-beautify.js" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/js-beautify/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/js-beautify/node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/js-beautify/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -3614,21 +3461,6 @@ "integrity": "sha512-uYr7J37ae/ORWdZeQ1xxMJe3NtdmqMC/JZK+geofDrkLUApKRHPd18/TxtBOJ4A0/+uUIliorNrfYV6s1b02eQ==", "dev": true }, - "node_modules/nopt": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz", - "integrity": "sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==", - "dev": true, - "dependencies": { - "abbrev": "^1.0.0" - }, - "bin": { - "nopt": "bin/nopt.js" - }, - "engines": { - "node": "^12.13.0 || ^14.15.0 || >=16.0.0" - } - }, "node_modules/normalize-path": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", @@ -3893,12 +3725,6 @@ "node": ">= 6" } }, - "node_modules/proto-list": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz", - "integrity": "sha512-vtK/94akxsTMhe0/cbfpR+syPuszcuwhqVjJq26CuNDgFGj682oRBXOP5MJpv2r7JtE8MsiepGIqvvOTBwn2vA==", - "dev": true - }, "node_modules/psl": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", @@ -4228,10 +4054,6 @@ "node": ">=8" } }, - "node_modules/tests": { - "resolved": "tests/Bones.UI.Tests", - "link": true - }, "node_modules/tmpl": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", @@ -4473,12 +4295,6 @@ "@vue/shared": "3.3.4" } }, - "node_modules/vue-component-type-helpers": { - "version": "1.8.4", - "resolved": "https://registry.npmjs.org/vue-component-type-helpers/-/vue-component-type-helpers-1.8.4.tgz", - "integrity": "sha512-6bnLkn8O0JJyiFSIF0EfCogzeqNXpnjJ0vW/SZzNHfe6sPx30lTtTXlE5TFs2qhJlAtDFybStVNpL73cPe3OMQ==", - "dev": true - }, "node_modules/w3c-xmlserializer": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-4.0.0.tgz", @@ -4690,13 +4506,13 @@ } }, "tests/Bones.UI.Tests": { - "name": "tests", + "name": "bones-ui-tests", "dependencies": { + "axios-mock-adapter": "^1.22.0", "jest-environment-jsdom": "^29.7.0" }, "devDependencies": { "@types/jest": "^29.5.5", - "@vue/test-utils": "^2.0.0-0", "jest": "^29.7.0", "ts-jest": "^29.1.1", "typescript": "^5.2.2" diff --git a/package.json b/package.json index 99d6f09..1fc72c3 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "private": true, "workspaces": [ "./src/Bones.UI", "./tests/Bones.UI.Tests" diff --git a/src/Bones.UI/core/serviceFactory.ts b/src/Bones.UI/core/serviceFactory.ts index 97c3984..adda6d8 100644 --- a/src/Bones.UI/core/serviceFactory.ts +++ b/src/Bones.UI/core/serviceFactory.ts @@ -41,6 +41,8 @@ export class ServiceFactory { const getMany = async (filter?: TFilter) => { const realUrl = typeof url === "string" ? url : url(); + console.log("TESST"); + console.log(buildURL(realUrl, filter)); const response = await ServiceFactory.http.get(buildURL(realUrl, filter)); const dtos: TInfosDTO[] = response.data; @@ -121,7 +123,7 @@ export class ServiceFactory { const otherMethods: U = others ? others(notifyService) : {} as U; - return { subscribe, unsubscribe, ...otherMethods }; + return { subscribe: subscribe.bind(notifyService), unsubscribe: unsubscribe.bind(notifyService), ...otherMethods }; } diff --git a/tests/Bones.UI.Tests/models/index.ts b/tests/Bones.UI.Tests/models/index.ts new file mode 100644 index 0000000..f53b3f2 --- /dev/null +++ b/tests/Bones.UI.Tests/models/index.ts @@ -0,0 +1,2 @@ +export * from './testUserDetails' +export * from './testUserInfos' \ No newline at end of file diff --git a/tests/Bones.UI.Tests/models/testUserDetails.ts b/tests/Bones.UI.Tests/models/testUserDetails.ts new file mode 100644 index 0000000..8444aa5 --- /dev/null +++ b/tests/Bones.UI.Tests/models/testUserDetails.ts @@ -0,0 +1,22 @@ +export class TestUserDetails { + id: string; + label: string; + + constructor(dto: TestUserDetailsDTO) { + this.id = dto.id; + this.label = dto.label; + } +} + +export interface TestUserDetailsDTO { + id: string; + label: string; +} + +export interface CreateTestUserDTO { + label: string; +} + +export interface UpdateTestUserDTO { + label: string; +} \ No newline at end of file diff --git a/tests/Bones.UI.Tests/models/testUserInfos.ts b/tests/Bones.UI.Tests/models/testUserInfos.ts new file mode 100644 index 0000000..24fd1ec --- /dev/null +++ b/tests/Bones.UI.Tests/models/testUserInfos.ts @@ -0,0 +1,18 @@ +export class TestUserInfos { + id: string; + label: string; + + constructor(dto: TestUserInfosDTO) { + this.id = dto.id; + this.label = dto.label; + } +} + +export interface TestUserInfosDTO { + id: string; + label: string; +} + +export interface TestUserFilter { + label?: string; +} \ No newline at end of file diff --git a/tests/Bones.UI.Tests/package.json b/tests/Bones.UI.Tests/package.json index 1fb87c6..f617deb 100644 --- a/tests/Bones.UI.Tests/package.json +++ b/tests/Bones.UI.Tests/package.json @@ -10,6 +10,7 @@ "test": "jest" }, "dependencies": { + "axios-mock-adapter": "^1.22.0", "jest-environment-jsdom": "^29.7.0" } } diff --git a/tests/Bones.UI.Tests/services/testUserService.ts b/tests/Bones.UI.Tests/services/testUserService.ts new file mode 100644 index 0000000..94a156a --- /dev/null +++ b/tests/Bones.UI.Tests/services/testUserService.ts @@ -0,0 +1,14 @@ +import { ServiceFactory, ComposableFactory } from '@dative-gpi/bones-ui'; +import { CreateTestUserDTO, TestUserDetails, UpdateTestUserDTO } from '../models/testUserDetails'; +import { TestUserFilter, TestUserInfos } from '../models/testUserInfos'; + +export const TEST_USERS_URL = "/api/testUsers"; +export const TEST_USER_URL = (id: string) => `/api/testUsers/${id}`; + +const testUserServiceFactory = ServiceFactory.createComplete("testUser", TEST_USERS_URL, TEST_USER_URL, TestUserDetails, TestUserInfos); + +export const useTestUser = ComposableFactory.get(testUserServiceFactory); +export const useTestUsers = ComposableFactory.getMany(testUserServiceFactory); +export const useCreateTestUser = ComposableFactory.create(testUserServiceFactory); +export const useUpdateTestUser = ComposableFactory.update(testUserServiceFactory); +export const useRemoveTestUser = ComposableFactory.remove(testUserServiceFactory); \ No newline at end of file diff --git a/tests/Bones.UI.Tests/tests/composable.test.ts b/tests/Bones.UI.Tests/tests/composable.test.ts new file mode 100644 index 0000000..b80038b --- /dev/null +++ b/tests/Bones.UI.Tests/tests/composable.test.ts @@ -0,0 +1,100 @@ +/** + * @jest-environment jsdom + */ +import * as all from '@dative-gpi/bones-ui'; +import { ServiceFactory } from '@dative-gpi/bones-ui'; +import { useTestUser, useTestUsers, TEST_USERS_URL, TEST_USER_URL, useCreateTestUser, useUpdateTestUser, useRemoveTestUser } from '../services/testUserService'; +import MockAdapter from 'axios-mock-adapter'; +import buildURL from 'axios/lib/helpers/buildURL'; + +const mock = new MockAdapter(ServiceFactory.http); + +test('testComposableGet', async () => { + mock.onGet(TEST_USER_URL("1")).reply(200, { id: "1", label: "test" }); + const { get, entity: user } = useTestUser(); + await get("1"); + expect(user.value?.label).toBe("test"); +}); + +test('testComposableGetMany', async () => { + mock.onGet(TEST_USERS_URL).reply(200, [{ id: "1", label: "test1" },{ id: "2", label: "test2" }]); + const { getMany, entities: users } = useTestUsers(); + await getMany(); + expect(users.value?.length).toBe(2); +}); + +test('testComposableCreate', async () => { + mock.onPost(TEST_USERS_URL).reply(200, { id: "1", label: "test" }); + const { create, created } = useCreateTestUser(); + await create({ label: "test" }); + expect(created).toBeTruthy(); +}); + +test('testComposableUpdate', async () => { + mock.onPost(TEST_USER_URL("1")).reply(200, { id: "1", label: "updated" }); + const { update, updated } = useUpdateTestUser(); + await update("1", { label: "updated" }); + expect(updated.value?.label).toBe("updated"); +}); + +test('testComposableRemove', async () => { + mock.onDelete(TEST_USER_URL("1")).reply(200); + const { remove, removing } = useRemoveTestUser(); + await remove("1"); + expect(removing.value).toBeFalsy(); +}); + + +//create and look at the list +test('testComposableComplexeCreate', async () => { + mock.onGet(TEST_USERS_URL).reply(200, [{ id: "1", label: "test1" },{ id: "2", label: "test2" }]); + mock.onPost(TEST_USERS_URL).reply(200, { id: 3, label: "test3" }); + const { getMany, entities: users } = useTestUsers(); + await getMany(); + expect(users.value?.length).toBe(2); + const { create, created } = useCreateTestUser(); + await create({ label: "test3" }); + expect(created).toBeTruthy(); + expect(users.value?.length).toBe(3); +}); + +//update and look at the list +test('testComposableComplexeUpdate', async () => { + mock.onGet(TEST_USERS_URL).reply(200, [{ id: "1", label: "test1" },{ id: "2", label: "test2" }]); + mock.onPost(TEST_USER_URL("1")).reply(200, { id: "1", label: "updated" }); + const { getMany, entities: users } = useTestUsers(); + await getMany(); + expect(users.value?.at(0)?.label).toBe("test1"); + const { update, updated } = useUpdateTestUser(); + await update("1", { label: "updated" }); + expect(users.value?.at(0)?.label).toBe("updated"); +}); + +//remove and look at the list +test('testComposableComplexeRemove', async () => { + mock.onGet(TEST_USERS_URL).reply(200, [{ id: "1", label: "test1" },{ id: "2", label: "test2" }]); + mock.onDelete(TEST_USER_URL("1")).reply(200); + const { getMany, entities: users } = useTestUsers(); + await getMany(); + expect(users.value.length).toBe(2); + const { remove, removing } = useRemoveTestUser(); + await remove("1"); + expect(users.value.length).toBe(1); +}); + +//try to getmany with filter then create and see if only filtered are added +test('testComposableComplexeFilter', async () => { + mock.onGet(buildURL(TEST_USERS_URL, {label: "test3"})).reply(200, [{ id: "1", label: "test1" },{ id: "2", label: "test2" }]); + const { getMany, entities: users } = useTestUsers(); + await getMany({ label: "test3"}); + expect(users.value?.length).toBe(2); + const { create, created } = useCreateTestUser(); + mock.onPost(TEST_USERS_URL).reply(200, { id: "3", label: "filtered" }); + await create({ label: "filtered" }); + expect(created).toBeTruthy(); + expect(users.value?.length).toBe(2); + mock.onPost(TEST_USERS_URL).reply(200, { id: "4", label: "test3" }); + await create({ label: "test3" }); + expect(created).toBeTruthy(); + expect(users.value?.length).toBe(3); +}); \ No newline at end of file