From c4c0c6680e005b1115454e8bdfe3b029abff8557 Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Fri, 12 Jan 2024 15:55:24 +0100 Subject: [PATCH 01/14] mostly update backend stuff --- .../FederationVisualizeItem.spec.js | 0 .../FederationVisualizeItem.vue | 0 admin/src/graphql/allCommunities.js | 30 ++++++++ admin/src/graphql/getCommunities.js | 17 ----- admin/src/pages/FederationVisualize.vue | 16 ++-- backend/src/config/index.ts | 2 +- backend/src/graphql/model/Community.ts | 31 ++++++++ .../src/graphql/model/FederatedCommunity.ts | 11 ++- .../src/graphql/resolver/CommunityResolver.ts | 11 ++- .../src/graphql/resolver/util/communities.ts | 59 +++++++++++++++ .../Community.ts | 73 +++++++++++++++++++ .../FederatedCommunity.ts | 58 +++++++++++++++ database/entity/Community.ts | 2 +- database/entity/FederatedCommunity.ts | 2 +- ...82-join_community_federated_communities.ts | 3 + dht-node/src/config/index.ts | 2 +- federation/src/config/index.ts | 2 +- 17 files changed, 283 insertions(+), 36 deletions(-) rename admin/src/components/{Fedaration => Federation}/FederationVisualizeItem.spec.js (100%) rename admin/src/components/{Fedaration => Federation}/FederationVisualizeItem.vue (100%) create mode 100644 admin/src/graphql/allCommunities.js delete mode 100644 admin/src/graphql/getCommunities.js create mode 100644 database/entity/0082-join_community_federated_communities/Community.ts create mode 100644 database/entity/0082-join_community_federated_communities/FederatedCommunity.ts create mode 100644 database/migrations/0082-join_community_federated_communities.ts diff --git a/admin/src/components/Fedaration/FederationVisualizeItem.spec.js b/admin/src/components/Federation/FederationVisualizeItem.spec.js similarity index 100% rename from admin/src/components/Fedaration/FederationVisualizeItem.spec.js rename to admin/src/components/Federation/FederationVisualizeItem.spec.js diff --git a/admin/src/components/Fedaration/FederationVisualizeItem.vue b/admin/src/components/Federation/FederationVisualizeItem.vue similarity index 100% rename from admin/src/components/Fedaration/FederationVisualizeItem.vue rename to admin/src/components/Federation/FederationVisualizeItem.vue diff --git a/admin/src/graphql/allCommunities.js b/admin/src/graphql/allCommunities.js new file mode 100644 index 000000000..62010ec90 --- /dev/null +++ b/admin/src/graphql/allCommunities.js @@ -0,0 +1,30 @@ +import gql from 'graphql-tag' + +export const allCommunities = gql` + query { + allCommunities { + id + foreign + url + publicKey + communityUuid + authenticatedAt + name + description + gmsApiKey + creationDate + createdAt + updatedAt + federatedCommunities { + id + apiVersion + endPoint + lastAnnouncedAt + verifiedAt + lastErrorAt + createdAt + updatedAt + } + } + } +` diff --git a/admin/src/graphql/getCommunities.js b/admin/src/graphql/getCommunities.js deleted file mode 100644 index ccf894f6b..000000000 --- a/admin/src/graphql/getCommunities.js +++ /dev/null @@ -1,17 +0,0 @@ -import gql from 'graphql-tag' - -export const getCommunities = gql` - query { - getCommunities { - id - foreign - publicKey - url - lastAnnouncedAt - verifiedAt - lastErrorAt - createdAt - updatedAt - } - } -` diff --git a/admin/src/pages/FederationVisualize.vue b/admin/src/pages/FederationVisualize.vue index 383cf064d..c6edba5aa 100644 --- a/admin/src/pages/FederationVisualize.vue +++ b/admin/src/pages/FederationVisualize.vue @@ -7,7 +7,7 @@ icon="arrow-clockwise" font-scale="2" :animation="animation" - @click="$apollo.queries.GetCommunities.refresh()" + @click="$apollo.queries.allCommunities.refresh()" data-test="federation-communities-refresh-btn" > @@ -30,9 +30,9 @@ diff --git a/admin/src/components/input/EditableLabel.vue b/admin/src/components/input/EditableLabel.vue new file mode 100644 index 000000000..674fcd3e7 --- /dev/null +++ b/admin/src/components/input/EditableLabel.vue @@ -0,0 +1,64 @@ + + + diff --git a/admin/src/graphql/updateHomeCommunity.js b/admin/src/graphql/updateHomeCommunity.js new file mode 100644 index 000000000..bce09f4d0 --- /dev/null +++ b/admin/src/graphql/updateHomeCommunity.js @@ -0,0 +1,7 @@ +import gql from 'graphql-tag' + +export const updateHomeCommunity = gql` + mutation ($uuid: String!, $gmsApiKey: String!) { + updateHomeCommunity(uuid: $uuid, gmsApiKey: $gmsApiKey) + } +` diff --git a/admin/src/locales/de.json b/admin/src/locales/de.json index 7cc0affac..b22006a8f 100644 --- a/admin/src/locales/de.json +++ b/admin/src/locales/de.json @@ -69,13 +69,20 @@ "deleted_user": "Alle gelöschten Nutzer", "deny": "Ablehnen", "e_mail": "E-Mail", + "edit": "Bearbeiten", "enabled": "aktiviert", "error": "Fehler", "expired": "abgelaufen", "federation": { + "authenticatedAt": "Verifiziert am:", + "communityUuid": "Community UUID:", "createdAt": "Erstellt am", + "gmsApiKey": "GMS API Key:", + "toast_gmsApiKeyUpdated": "Der GMS Api Key wurde erfolgreich aktualisiert!", "gradidoInstances": "Gradido Instanzen", "lastAnnouncedAt": "letzte Bekanntgabe", + "name": "Name", + "publicKey": "PublicKey:", "url": "Url", "verified": "Verifiziert" }, diff --git a/admin/src/locales/en.json b/admin/src/locales/en.json index 084e2104f..471bfc50c 100644 --- a/admin/src/locales/en.json +++ b/admin/src/locales/en.json @@ -69,13 +69,20 @@ "deleted_user": "All deleted user", "deny": "Reject", "e_mail": "E-mail", + "edit": "Edit", "enabled": "enabled", "error": "Error", "expired": "expired", "federation": { + "authenticatedAt": "verified at:", + "communityUuid": "Community UUID:", "createdAt": "Created At ", + "gmsApiKey": "GMS API Key:", + "toast_gmsApiKeyUpdated": "The GMS Api Key has been successfully updated!", "gradidoInstances": "Gradido Instances", "lastAnnouncedAt": "Last Announced", + "name": "Name", + "publicKey": "PublicKey:", "url": "Url", "verified": "Verified" }, diff --git a/admin/src/pages/FederationVisualize.vue b/admin/src/pages/FederationVisualize.vue index c6edba5aa..e29e0c02e 100644 --- a/admin/src/pages/FederationVisualize.vue +++ b/admin/src/pages/FederationVisualize.vue @@ -16,12 +16,13 @@ {{ $t('federation.verified') }} {{ $t('federation.url') }} + {{ $t('federation.name') }} {{ $t('federation.lastAnnouncedAt') }} {{ $t('federation.createdAt') }} diff --git a/backend/src/graphql/model/Community.ts b/backend/src/graphql/model/Community.ts index ef7561c3c..1d376b21f 100644 --- a/backend/src/graphql/model/Community.ts +++ b/backend/src/graphql/model/Community.ts @@ -2,29 +2,43 @@ import { Community as DbCommunity } from '@entity/Community' import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' import { ObjectType, Field, Int } from 'type-graphql' +import { backendLogger as logger } from '@/server/logger' + import { FederatedCommunity } from './FederatedCommunity' @ObjectType() export class Community { constructor(dbCom: DbCommunity) { - this.id = dbCom.id - this.foreign = dbCom.foreign + if (dbCom.federatedCommunities && dbCom.federatedCommunities.length > 0) { + const federatedCommunity = dbCom.federatedCommunities[0] + this.foreign = federatedCommunity.foreign + const url = new URL(federatedCommunity.endPoint) + // use only the host part + this.url = url.protocol + '//' + url.host + this.publicKey = federatedCommunity.publicKey.toString('hex') + this.federatedCommunities = dbCom.federatedCommunities.map( + (federatedCom: DbFederatedCommunity) => new FederatedCommunity(federatedCom), + ) + } + this.id = dbCom.id ?? 0 + if (dbCom.foreign !== undefined) { + this.foreign = dbCom.foreign + } this.name = dbCom.name this.description = dbCom.description this.gmsApiKey = dbCom.gmsApiKey - this.url = dbCom.url - this.publicKey = dbCom.publicKey.toString('hex') + if (dbCom.url) { + this.url = dbCom.url + } + if (dbCom.publicKey && dbCom.publicKey.length === 32) { + this.publicKey = dbCom.publicKey.toString('hex') + } this.communityUuid = dbCom.communityUuid this.creationDate = dbCom.creationDate this.createdAt = dbCom.createdAt this.updatedAt = dbCom.updatedAt this.uuid = dbCom.communityUuid this.authenticatedAt = dbCom.authenticatedAt - if (dbCom.federatedCommunities) { - this.federatedCommunities = dbCom.federatedCommunities.map( - (federatedCom: DbFederatedCommunity) => new FederatedCommunity(federatedCom), - ) - } } @Field(() => Int) From 4f99e75d73fb6eb819998582c2017e0fbcaa9a80 Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Mon, 15 Jan 2024 20:06:35 +0100 Subject: [PATCH 03/14] add list of federated communities --- ...spec.js => CommunityVisualizeItem.spec.js} | 0 .../Federation/CommunityVisualizeItem.vue | 151 ++++++++++++++++++ .../Federation/FederationVisualizeItem.vue | 115 +------------ admin/src/locales/de.json | 5 +- admin/src/locales/en.json | 5 +- admin/src/pages/FederationVisualize.vue | 6 +- 6 files changed, 170 insertions(+), 112 deletions(-) rename admin/src/components/Federation/{FederationVisualizeItem.spec.js => CommunityVisualizeItem.spec.js} (100%) create mode 100644 admin/src/components/Federation/CommunityVisualizeItem.vue diff --git a/admin/src/components/Federation/FederationVisualizeItem.spec.js b/admin/src/components/Federation/CommunityVisualizeItem.spec.js similarity index 100% rename from admin/src/components/Federation/FederationVisualizeItem.spec.js rename to admin/src/components/Federation/CommunityVisualizeItem.spec.js diff --git a/admin/src/components/Federation/CommunityVisualizeItem.vue b/admin/src/components/Federation/CommunityVisualizeItem.vue new file mode 100644 index 000000000..0eb55ae59 --- /dev/null +++ b/admin/src/components/Federation/CommunityVisualizeItem.vue @@ -0,0 +1,151 @@ + + diff --git a/admin/src/components/Federation/FederationVisualizeItem.vue b/admin/src/components/Federation/FederationVisualizeItem.vue index 97a248aaa..7b2d6c5d8 100644 --- a/admin/src/components/Federation/FederationVisualizeItem.vue +++ b/admin/src/components/Federation/FederationVisualizeItem.vue @@ -1,73 +1,24 @@ diff --git a/admin/src/locales/de.json b/admin/src/locales/de.json index b22006a8f..0fb43e48f 100644 --- a/admin/src/locales/de.json +++ b/admin/src/locales/de.json @@ -74,6 +74,7 @@ "error": "Fehler", "expired": "abgelaufen", "federation": { + "apiVersion": "API Version", "authenticatedAt": "Verifiziert am:", "communityUuid": "Community UUID:", "createdAt": "Erstellt am", @@ -81,10 +82,12 @@ "toast_gmsApiKeyUpdated": "Der GMS Api Key wurde erfolgreich aktualisiert!", "gradidoInstances": "Gradido Instanzen", "lastAnnouncedAt": "letzte Bekanntgabe", + "lastErrorAt": "Letzer Fehler am", "name": "Name", "publicKey": "PublicKey:", "url": "Url", - "verified": "Verifiziert" + "verified": "Verifiziert", + "verifiedAt": "Verifiziert am" }, "firstname": "Vorname", "footer": { diff --git a/admin/src/locales/en.json b/admin/src/locales/en.json index 471bfc50c..b2073a1e2 100644 --- a/admin/src/locales/en.json +++ b/admin/src/locales/en.json @@ -74,6 +74,7 @@ "error": "Error", "expired": "expired", "federation": { + "apiVersion": "API Version", "authenticatedAt": "verified at:", "communityUuid": "Community UUID:", "createdAt": "Created At ", @@ -81,10 +82,12 @@ "toast_gmsApiKeyUpdated": "The GMS Api Key has been successfully updated!", "gradidoInstances": "Gradido Instances", "lastAnnouncedAt": "Last Announced", + "lastErrorAt": "last error at", "name": "Name", "publicKey": "PublicKey:", "url": "Url", - "verified": "Verified" + "verified": "Verified", + "verifiedAt": "Verified at" }, "firstname": "Firstname", "footer": { diff --git a/admin/src/pages/FederationVisualize.vue b/admin/src/pages/FederationVisualize.vue index e29e0c02e..5736b1a0e 100644 --- a/admin/src/pages/FederationVisualize.vue +++ b/admin/src/pages/FederationVisualize.vue @@ -25,7 +25,7 @@ :key="item.publicKey" :variant="!item.foreign ? 'primary' : 'warning'" > - + @@ -33,12 +33,12 @@ diff --git a/admin/src/graphql/updateHomeCommunity.js b/admin/src/graphql/updateHomeCommunity.js index bce09f4d0..a43d6edd2 100644 --- a/admin/src/graphql/updateHomeCommunity.js +++ b/admin/src/graphql/updateHomeCommunity.js @@ -2,6 +2,8 @@ import gql from 'graphql-tag' export const updateHomeCommunity = gql` mutation ($uuid: String!, $gmsApiKey: String!) { - updateHomeCommunity(uuid: $uuid, gmsApiKey: $gmsApiKey) + updateHomeCommunity(uuid: $uuid, gmsApiKey: $gmsApiKey) { + id + } } ` From cc617eb827ebcbf8a04d77a56d754b22ca2cc1cc Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 16 Jan 2024 12:17:50 +0100 Subject: [PATCH 05/14] fix after save behaviour --- admin/src/components/Federation/CommunityVisualizeItem.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/admin/src/components/Federation/CommunityVisualizeItem.vue b/admin/src/components/Federation/CommunityVisualizeItem.vue index 0eb55ae59..c99f38ec5 100644 --- a/admin/src/components/Federation/CommunityVisualizeItem.vue +++ b/admin/src/components/Federation/CommunityVisualizeItem.vue @@ -27,7 +27,7 @@ {{ $t('federation.gmsApiKey') }}  @@ -79,8 +79,12 @@ export default { formatDistanceToNow, locale: this.$i18n.locale, details: false, + gmsApiKey: '', } }, + created() { + this.gmsApiKey = this.item.gmsApiKey + }, computed: { verified() { return ( @@ -131,6 +135,7 @@ export default { this.details = !this.details }, handleSaveGsmApiKey(gmsApiKey) { + this.gmsApiKey = gmsApiKey this.$apollo .mutate({ mutation: updateHomeCommunity, From 7494429aad901e39d54db58f2372c965455da94c Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 16 Jan 2024 16:45:25 +0100 Subject: [PATCH 06/14] fix lint and admin tests --- .vscode/launch.json | 12 ++ admin/jest.config.js | 7 +- admin/package.json | 1 + .../Federation/CommunityVisualizeItem.spec.js | 148 ++++++++++++------ .../Federation/CommunityVisualizeItem.vue | 6 +- .../Federation/FederationVisualizeItem.vue | 6 +- .../components/input/EditableLabel.spec.js | 83 ++++++++++ admin/src/locales/de.json | 1 - admin/src/locales/en.json | 1 - admin/src/pages/FederationVisualize.spec.js | 98 +++++++----- .../src/graphql/resolver/util/communities.ts | 1 - 11 files changed, 270 insertions(+), 94 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 admin/src/components/input/EditableLabel.spec.js diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..5a60c21e2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node-terminal", + "name": "Admin: test", + "request": "launch", + "command": "yarn run test", + "cwd": "${workspaceFolder}/admin" + } + ] +} \ No newline at end of file diff --git a/admin/jest.config.js b/admin/jest.config.js index 253c905de..a0c8ae412 100644 --- a/admin/jest.config.js +++ b/admin/jest.config.js @@ -9,7 +9,7 @@ module.exports = { ], coverageThreshold: { global: { - lines: 96, + lines: 95, }, }, moduleFileExtensions: [ @@ -31,6 +31,9 @@ module.exports = { setupFiles: ['/test/testSetup.js', 'jest-canvas-mock'], testMatch: ['**/?(*.)+(spec|test).js?(x)'], // snapshotSerializers: ['jest-serializer-vue'], - transformIgnorePatterns: ['/node_modules/(?!vee-validate/dist/rules)'], + transformIgnorePatterns: [ + '/node_modules/(?!vee-validate/dist/rules)', + '/node_modules/(?!@babel)', + ], testEnvironment: 'jest-environment-jsdom-sixteen', // why this is still needed? should not be needed anymore since jest@26, see: https://www.npmjs.com/package/jest-environment-jsdom-sixteen } diff --git a/admin/package.json b/admin/package.json index e34136e4b..3c1e666e8 100644 --- a/admin/package.json +++ b/admin/package.json @@ -15,6 +15,7 @@ "lint": "eslint --max-warnings=0 --ext .js,.vue,.json .", "stylelint": "stylelint --max-warnings=0 '**/*.{scss,vue}'", "test": "cross-env TZ=UTC jest", + "test:debug": "node --inspect-brk node_modules/.bin/vue-cli-service test:unit --no-cache --watch --runInBand", "locales": "scripts/sort.sh" }, "dependencies": { diff --git a/admin/src/components/Federation/CommunityVisualizeItem.spec.js b/admin/src/components/Federation/CommunityVisualizeItem.spec.js index 6058cc6f4..2c5065ba0 100644 --- a/admin/src/components/Federation/CommunityVisualizeItem.spec.js +++ b/admin/src/components/Federation/CommunityVisualizeItem.spec.js @@ -1,36 +1,83 @@ import { mount } from '@vue/test-utils' -import FederationVisualizeItem from './FederationVisualizeItem.vue' +import Vuex from 'vuex' +import CommunityVisualizeItem from './CommunityVisualizeItem.vue' const localVue = global.localVue +localVue.use(Vuex) const today = new Date() const createdDate = new Date() createdDate.setDate(createdDate.getDate() - 3) +// Mock für den Vuex-Store +const store = new Vuex.Store({ + state: { + moderator: { + roles: ['ADMIN'], + }, + }, +}) + let propsData = { item: { - id: 7590, + id: 1, foreign: false, - publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7', - url: 'http://localhost/api/2_0', - lastAnnouncedAt: createdDate, - verifiedAt: today, - lastErrorAt: null, + url: 'http://localhost/api/', + publicKey: '4007170edd8d33fb009cd99ee4e87f214e7cd21b668d45540a064deb42e243c2', + communityUuid: '5ab0befd-b150-4f31-a631-7f3637e47b21', + authenticatedAt: null, + name: 'Gradido Test', + description: 'Gradido Community zum testen', + gmsApiKey: '', + creationDate: createdDate, createdAt: createdDate, - updatedAt: null, + updatedAt: createdDate, + federatedCommunities: [ + { + id: 2046, + apiVersion: '2_0', + endPoint: 'http://localhost/api/', + lastAnnouncedAt: createdDate, + verifiedAt: today, + lastErrorAt: null, + createdAt: createdDate, + updatedAt: null, + }, + { + id: 2045, + apiVersion: '1_1', + endPoint: 'http://localhost/api/', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: '2024-01-16T10:08:21.550Z', + updatedAt: null, + }, + { + id: 2044, + apiVersion: '1_0', + endPoint: 'http://localhost/api/', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: '2024-01-16T10:08:21.544Z', + updatedAt: null, + }, + ], }, } const mocks = { + $t: (key) => key, $i18n: { locale: 'en', }, } -describe('FederationVisualizeItem', () => { +describe('CommunityVisualizeItem', () => { let wrapper const Wrapper = () => { - return mount(FederationVisualizeItem, { localVue, mocks, propsData }) + return mount(CommunityVisualizeItem, { localVue, mocks, propsData, store }) } describe('mount', () => { @@ -39,19 +86,35 @@ describe('FederationVisualizeItem', () => { }) it('renders the component', () => { - expect(wrapper.find('div.federation-visualize-item').exists()).toBe(true) + expect(wrapper.exists()).toBe(true) + expect(wrapper.find('div.community-visualize-item').exists()).toBe(true) + expect(wrapper.find('.details').exists()).toBe(false) + }) + + it('toggles details on click', async () => { + // Click the row to toggle details + await wrapper.find('.row').trigger('click') + + // Assert that details are now open + expect(wrapper.find('.details').exists()).toBe(true) + + // Click the row again to toggle details back + await wrapper.find('.row').trigger('click') + + // Assert that details are now closed + expect(wrapper.find('.details').exists()).toBe(false) }) describe('rendering item properties', () => { it('has the url', () => { - expect(wrapper.find('.row > div:nth-child(2) > div').text()).toBe( - 'http://localhost/api/2_0', + expect(wrapper.find('.row > div:nth-child(2) > div > a').text()).toBe( + 'http://localhost/api/', ) }) it('has the public key', () => { expect(wrapper.find('.row > div:nth-child(2) > small').text()).toContain( - 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7'.substring(0, 26), + '4007170edd8d33fb009cd99ee4e87f214e7cd21b668d45540a064deb42e243c2'.substring(0, 26), ) }) @@ -65,33 +128,6 @@ describe('FederationVisualizeItem', () => { }) }) - describe('not verified item', () => { - beforeEach(() => { - propsData = { - item: { - id: 7590, - foreign: false, - publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7', - url: 'http://localhost/api/2_0', - lastAnnouncedAt: createdDate, - verifiedAt: null, - lastErrorAt: null, - createdAt: createdDate, - updatedAt: null, - }, - } - wrapper = Wrapper() - }) - - it('has the x-circle icon', () => { - expect(wrapper.find('svg.bi-x-circle').exists()).toBe(true) - }) - - it('has the text variant "danger"', () => { - expect(wrapper.find('.text-danger').exists()).toBe(true) - }) - }) - // describe('with different locales (de, en, fr, es, nl)', () => { describe('lastAnnouncedAt', () => { it('computes the time string for different locales (de, en, fr, es, nl)', () => { @@ -155,6 +191,30 @@ describe('FederationVisualizeItem', () => { expect(wrapper.vm.createdAt).toBe('3 dagen geleden') }) + describe('not verified item', () => { + beforeEach(() => { + propsData = { + item: { + id: 7590, + foreign: false, + publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7', + url: 'http://localhost/api/', + createdAt: createdDate, + updatedAt: null, + }, + } + wrapper = Wrapper() + }) + + it('has the x-circle icon', () => { + expect(wrapper.find('svg.bi-x-circle').exists()).toBe(true) + }) + + it('has the text variant "danger"', () => { + expect(wrapper.find('.text-danger').exists()).toBe(true) + }) + }) + describe('createdAt == null', () => { beforeEach(() => { propsData = { @@ -163,9 +223,9 @@ describe('FederationVisualizeItem', () => { foreign: false, publicKey: 'eaf6a426b24fd54f8fbae11c17700fc595080ca25159579c63d38dbc64284ba7', url: 'http://localhost/api/2_0', - lastAnnouncedAt: createdDate, - verifiedAt: null, - lastErrorAt: null, + communityUuid: '5ab0befd-b150-4f31-a631-7f3637e47b21', + authenticatedAt: null, + creationDate: null, createdAt: null, updatedAt: null, }, diff --git a/admin/src/components/Federation/CommunityVisualizeItem.vue b/admin/src/components/Federation/CommunityVisualizeItem.vue index c99f38ec5..4a5d9e67e 100644 --- a/admin/src/components/Federation/CommunityVisualizeItem.vue +++ b/admin/src/components/Federation/CommunityVisualizeItem.vue @@ -12,7 +12,7 @@ {{ lastAnnouncedAt }} {{ createdAt }} - + @@ -87,6 +87,9 @@ export default { }, computed: { verified() { + if (!this.item.federatedCommunities || this.item.federatedCommunities.length === 0) { + return false + } return ( this.item.federatedCommunities.filter( (federatedCommunity) => @@ -101,6 +104,7 @@ export default { return this.verified ? 'success' : 'danger' }, lastAnnouncedAt() { + if (!this.item.federatedCommunities || this.item.federatedCommunities.length === 0) return '' const minDate = new Date(0) const lastAnnouncedAt = this.item.federatedCommunities.reduce( (lastAnnouncedAt, federateCommunity) => { diff --git a/admin/src/components/Federation/FederationVisualizeItem.vue b/admin/src/components/Federation/FederationVisualizeItem.vue index cbfe53ef0..9172f9a94 100644 --- a/admin/src/components/Federation/FederationVisualizeItem.vue +++ b/admin/src/components/Federation/FederationVisualizeItem.vue @@ -35,7 +35,11 @@ export default { methods: { distanceDate(dateString) { return dateString - ? formatDistanceToNow(new Date(dateString), { locale: locales[this.$i18n.locale] }) + ? formatDistanceToNow(new Date(dateString), { + includeSecond: true, + addSuffix: true, + locale: locales[this.$i18n.locale], + }) : '' }, }, diff --git a/admin/src/components/input/EditableLabel.spec.js b/admin/src/components/input/EditableLabel.spec.js new file mode 100644 index 000000000..0b2462b30 --- /dev/null +++ b/admin/src/components/input/EditableLabel.spec.js @@ -0,0 +1,83 @@ +// Test written by ChatGPT 3.5 +import { mount } from '@vue/test-utils' +import EditableLabel from './EditableLabel.vue' + +const localVue = global.localVue +const value = 'test label value' + +describe('EditableLabel', () => { + let wrapper + + const createWrapper = (propsData) => { + return mount(EditableLabel, { + localVue, + propsData, + }) + } + + it('renders the label when not editing', () => { + wrapper = createWrapper({ value, allowEdit: true }) + + expect(wrapper.find('label').text()).toBe(value) + }) + + it('renders the input when editing', async () => { + wrapper = createWrapper({ value, allowEdit: true }) + + await wrapper.find('button').trigger('click') + + expect(wrapper.find('input').exists()).toBe(true) + }) + + it('emits save event when clicking save button', async () => { + wrapper = createWrapper({ value, allowEdit: true }) + + await wrapper.find('button').trigger('click') + await wrapper.setData({ inputValue: 'New Value' }) + await wrapper.find('button').trigger('click') + + expect(wrapper.emitted().save).toBeTruthy() + expect(wrapper.emitted().save[0][0]).toBe('New Value') + }) + + it('disables save button when value is not changed', async () => { + wrapper = createWrapper({ value, allowEdit: true }) + + await wrapper.find('button').trigger('click') + + expect(wrapper.find('button').attributes('disabled')).toBe('disabled') + }) + + it('enables save button when value is changed', async () => { + wrapper = createWrapper({ value, allowEdit: true }) + + await wrapper.find('button').trigger('click') + await wrapper.setData({ inputValue: 'New Value' }) + + expect(wrapper.find('button').attributes('disabled')).toBeFalsy() + }) + + it('updates originalValue when saving changes', async () => { + wrapper = createWrapper({ value, allowEdit: true }) + + await wrapper.find('button').trigger('click') + await wrapper.setData({ inputValue: 'New Value' }) + await wrapper.find('button').trigger('click') + + expect(wrapper.vm.originalValue).toBe('New Value') + }) + + it('changes variant to success when editing', async () => { + wrapper = createWrapper({ value, allowEdit: true }) + + await wrapper.find('button').trigger('click') + + expect(wrapper.vm.variant).toBe('success') + }) + + it('changes variant to prime when not editing', async () => { + wrapper = createWrapper({ value, allowEdit: true }) + + expect(wrapper.vm.variant).toBe('prime') + }) +}) diff --git a/admin/src/locales/de.json b/admin/src/locales/de.json index 0fb43e48f..9f808f70c 100644 --- a/admin/src/locales/de.json +++ b/admin/src/locales/de.json @@ -69,7 +69,6 @@ "deleted_user": "Alle gelöschten Nutzer", "deny": "Ablehnen", "e_mail": "E-Mail", - "edit": "Bearbeiten", "enabled": "aktiviert", "error": "Fehler", "expired": "abgelaufen", diff --git a/admin/src/locales/en.json b/admin/src/locales/en.json index b2073a1e2..b1f020921 100644 --- a/admin/src/locales/en.json +++ b/admin/src/locales/en.json @@ -69,7 +69,6 @@ "deleted_user": "All deleted user", "deny": "Reject", "e_mail": "E-mail", - "edit": "Edit", "enabled": "enabled", "error": "Error", "expired": "expired", diff --git a/admin/src/pages/FederationVisualize.spec.js b/admin/src/pages/FederationVisualize.spec.js index 67d6dffde..a089ef8fe 100644 --- a/admin/src/pages/FederationVisualize.spec.js +++ b/admin/src/pages/FederationVisualize.spec.js @@ -2,7 +2,7 @@ import { mount } from '@vue/test-utils' import FederationVisualize from './FederationVisualize' import VueApollo from 'vue-apollo' import { createMockClient } from 'mock-apollo-client' -import { getCommunities } from '@/graphql/getCommunities' +import { allCommunities } from '@/graphql/allCommunities' import { toastErrorSpy } from '../../test/testSetup' const mockClient = createMockClient() @@ -25,42 +25,54 @@ const mocks = { const defaultData = () => { return { - getCommunities: [ + allCommunities: [ { - id: 1776, - foreign: true, - publicKey: 'c7ca9e742421bb167b8666cb78f90b40c665b8f35db8f001988d44dbb3ce8527', - url: 'http://localhost/api/2_0', - lastAnnouncedAt: '2023-04-07T12:27:24.037Z', - verifiedAt: null, - lastErrorAt: null, - createdAt: '2023-04-07T11:45:06.254Z', - updatedAt: null, - __typename: 'Community', - }, - { - id: 1775, - foreign: true, - publicKey: 'c7ca9e742421bb167b8666cb78f90b40c665b8f35db8f001988d44dbb3ce8527', - url: 'http://localhost/api/1_1', - lastAnnouncedAt: '2023-04-07T12:27:24.023Z', - verifiedAt: null, - lastErrorAt: null, - createdAt: '2023-04-07T11:45:06.234Z', - updatedAt: null, - __typename: 'Community', - }, - { - id: 1774, - foreign: true, - publicKey: 'c7ca9e742421bb167b8666cb78f90b40c665b8f35db8f001988d44dbb3ce8527', - url: 'http://localhost/api/1_0', - lastAnnouncedAt: '2023-04-07T12:27:24.009Z', - verifiedAt: null, - lastErrorAt: null, - createdAt: '2023-04-07T11:45:06.218Z', - updatedAt: null, - __typename: 'Community', + id: 1, + foreign: false, + url: 'http://localhost/api/', + publicKey: '4007170edd8d33fb009cd99ee4e87f214e7cd21b668d45540a064deb42e243c2', + communityUuid: '5ab0befd-b150-4f31-a631-7f3637e47b21', + authenticatedAt: null, + name: 'Gradido Test', + description: 'Gradido Community zum testen', + gmsApiKey: '', + creationDate: '2024-01-09T15:56:40.592Z', + createdAt: '2024-01-09T15:56:40.595Z', + updatedAt: '2024-01-16T11:17:15.000Z', + federatedCommunities: [ + { + id: 2046, + apiVersion: '2_0', + endPoint: 'http://localhost/api/', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: '2024-01-16T10:08:21.544Z', + updatedAt: null, + }, + { + id: 2045, + apiVersion: '1_1', + endPoint: 'http://localhost/api/', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: '2024-01-16T10:08:21.550Z', + updatedAt: null, + __typename: 'FederatedCommunity', + }, + { + id: 2044, + apiVersion: '1_0', + endPoint: 'http://localhost/api/', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: '2024-01-16T10:08:21.544Z', + updatedAt: null, + __typename: 'FederatedCommunity', + }, + ], }, ], } @@ -68,11 +80,11 @@ const defaultData = () => { describe('FederationVisualize', () => { let wrapper - const getCommunitiesMock = jest.fn() + const allCommunitiesMock = jest.fn() mockClient.setRequestHandler( - getCommunities, - getCommunitiesMock + allCommunities, + allCommunitiesMock .mockRejectedValueOnce({ message: 'Ouch!' }) .mockResolvedValue({ data: defaultData() }), ) @@ -95,7 +107,7 @@ describe('FederationVisualize', () => { describe('sever success', () => { it('sends query to Apollo when created', () => { - expect(getCommunitiesMock).toBeCalled() + expect(allCommunitiesMock).toBeCalled() }) it('has a DIV element with the class "federation-visualize"', () => { @@ -106,8 +118,8 @@ describe('FederationVisualize', () => { expect(wrapper.find('[data-test="federation-communities-refresh-btn"]').exists()).toBe(true) }) - it('renders 3 community list items', () => { - expect(wrapper.findAll('.list-group-item').length).toBe(3) + it('renders 1 community list item', () => { + expect(wrapper.findAll('.list-group-item').length).toBe(1) }) describe('cklicking the refresh button', () => { @@ -117,7 +129,7 @@ describe('FederationVisualize', () => { }) it('calls the API', async () => { - expect(getCommunitiesMock).toBeCalled() + expect(allCommunitiesMock).toBeCalled() }) }) }) diff --git a/backend/src/graphql/resolver/util/communities.ts b/backend/src/graphql/resolver/util/communities.ts index b8f23b50e..e85357991 100644 --- a/backend/src/graphql/resolver/util/communities.ts +++ b/backend/src/graphql/resolver/util/communities.ts @@ -3,7 +3,6 @@ import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCom import { Paginated } from '@arg/Paginated' -import { Order } from '@/graphql/enum/Order' import { LogError } from '@/server/LogError' import { Connection } from '@/typeorm/connection' From d5b0a2060b33c4ef0c4b95bb04b3fa160eb443e5 Mon Sep 17 00:00:00 2001 From: einhorn_b Date: Tue, 16 Jan 2024 18:28:55 +0100 Subject: [PATCH 07/14] fix test --- .../resolver/CommunityResolver.test.ts | 134 +++++++++++++----- backend/src/seeds/graphql/queries.ts | 2 +- 2 files changed, 101 insertions(+), 35 deletions(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index 3cdc04568..c3dbd4cda 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -79,7 +79,10 @@ describe('CommunityResolver', () => { homeCom1 = DbFederatedCommunity.create() homeCom1.foreign = false - homeCom1.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom1.publicKey = Buffer.from( + '8a1f9374b99c30d827b85dcd23f7e50328430d64ef65ef35bf375ea8eb9a2e1d', + 'hex', + ) homeCom1.apiVersion = '1_0' homeCom1.endPoint = 'http://localhost/api' homeCom1.createdAt = new Date() @@ -87,7 +90,10 @@ describe('CommunityResolver', () => { homeCom2 = DbFederatedCommunity.create() homeCom2.foreign = false - homeCom2.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom2.publicKey = Buffer.from( + '7d849b4b53232ed8f3c913e1944b4a20b1a33e44f65ee56673209c14df0e3252', + 'hex', + ) homeCom2.apiVersion = '1_1' homeCom2.endPoint = 'http://localhost/api' homeCom2.createdAt = new Date() @@ -95,7 +101,10 @@ describe('CommunityResolver', () => { homeCom3 = DbFederatedCommunity.create() homeCom3.foreign = false - homeCom3.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom3.publicKey = Buffer.from( + 'f9a683abf2d1bf265c8dcb543d3674e080db5a5d6976a2dd6ea6969c798f8a8c', + 'hex', + ) homeCom3.apiVersion = '2_0' homeCom3.endPoint = 'http://localhost/api' homeCom3.createdAt = new Date() @@ -109,8 +118,10 @@ describe('CommunityResolver', () => { { id: 3, foreign: homeCom3.foreign, - publicKey: expect.stringMatching('publicKey-HomeCommunity'), - url: expect.stringMatching('http://localhost/api/2_0'), + publicKey: expect.stringMatching( + 'f9a683abf2d1bf265c8dcb543d3674e080db5a5d6976a2dd6ea6969c798f8a8c', + ), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -120,8 +131,10 @@ describe('CommunityResolver', () => { { id: 2, foreign: homeCom2.foreign, - publicKey: expect.stringMatching('publicKey-HomeCommunity'), - url: expect.stringMatching('http://localhost/api/1_1'), + publicKey: expect.stringMatching( + '7d849b4b53232ed8f3c913e1944b4a20b1a33e44f65ee56673209c14df0e3252', + ), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -131,8 +144,10 @@ describe('CommunityResolver', () => { { id: 1, foreign: homeCom1.foreign, - publicKey: expect.stringMatching('publicKey-HomeCommunity'), - url: expect.stringMatching('http://localhost/api/1_0'), + publicKey: expect.stringMatching( + '8a1f9374b99c30d827b85dcd23f7e50328430d64ef65ef35bf375ea8eb9a2e1d', + ), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -151,7 +166,10 @@ describe('CommunityResolver', () => { foreignCom1 = DbFederatedCommunity.create() foreignCom1.foreign = true - foreignCom1.publicKey = Buffer.from('publicKey-ForeignCommunity') + foreignCom1.publicKey = Buffer.from( + '2e3c58f8fb7d9e4c1f2e3a9ec51cf4b1473d9b6b422853ac4c28e68ec41db4f3', + 'hex', + ) foreignCom1.apiVersion = '1_0' foreignCom1.endPoint = 'http://remotehost/api' foreignCom1.createdAt = new Date() @@ -159,7 +177,10 @@ describe('CommunityResolver', () => { foreignCom2 = DbFederatedCommunity.create() foreignCom2.foreign = true - foreignCom2.publicKey = Buffer.from('publicKey-ForeignCommunity') + foreignCom2.publicKey = Buffer.from( + '9c74d200b9c8b7210db8e65a58b869e4a8c84eb5b2b8b8e8d1ed74e6d9f5b7a1', + 'hex', + ) foreignCom2.apiVersion = '1_1' foreignCom2.endPoint = 'http://remotehost/api' foreignCom2.createdAt = new Date() @@ -167,7 +188,10 @@ describe('CommunityResolver', () => { foreignCom3 = DbFederatedCommunity.create() foreignCom3.foreign = true - foreignCom3.publicKey = Buffer.from('publicKey-ForeignCommunity') + foreignCom3.publicKey = Buffer.from( + '13fd4edf5b708b5815f8d7d0c0ba34e6aa810f3f187f0bd3d25e0e74315ec16a', + 'hex', + ) foreignCom3.apiVersion = '1_2' foreignCom3.endPoint = 'http://remotehost/api' foreignCom3.createdAt = new Date() @@ -181,8 +205,10 @@ describe('CommunityResolver', () => { { id: 3, foreign: homeCom3.foreign, - publicKey: expect.stringMatching('publicKey-HomeCommunity'), - url: expect.stringMatching('http://localhost/api/2_0'), + publicKey: expect.stringMatching( + 'f9a683abf2d1bf265c8dcb543d3674e080db5a5d6976a2dd6ea6969c798f8a8c', + ), + endPoint: expect.stringMatching('http://localhost/api'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -192,8 +218,10 @@ describe('CommunityResolver', () => { { id: 2, foreign: homeCom2.foreign, - publicKey: expect.stringMatching('publicKey-HomeCommunity'), - url: expect.stringMatching('http://localhost/api/1_1'), + publicKey: expect.stringMatching( + '7d849b4b53232ed8f3c913e1944b4a20b1a33e44f65ee56673209c14df0e3252', + ), + endPoint: expect.stringMatching('http://localhost/api'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -203,8 +231,10 @@ describe('CommunityResolver', () => { { id: 1, foreign: homeCom1.foreign, - publicKey: expect.stringMatching('publicKey-HomeCommunity'), - url: expect.stringMatching('http://localhost/api/1_0'), + publicKey: expect.stringMatching( + '8a1f9374b99c30d827b85dcd23f7e50328430d64ef65ef35bf375ea8eb9a2e1d', + ), + endPoint: expect.stringMatching('http://localhost/api'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -214,8 +244,10 @@ describe('CommunityResolver', () => { { id: 6, foreign: foreignCom3.foreign, - publicKey: expect.stringMatching('publicKey-ForeignCommunity'), - url: expect.stringMatching('http://remotehost/api/1_2'), + publicKey: expect.stringMatching( + '13fd4edf5b708b5815f8d7d0c0ba34e6aa810f3f187f0bd3d25e0e74315ec16a', + ), + endPoint: expect.stringMatching('http://remotehost/api'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -225,8 +257,10 @@ describe('CommunityResolver', () => { { id: 5, foreign: foreignCom2.foreign, - publicKey: expect.stringMatching('publicKey-ForeignCommunity'), - url: expect.stringMatching('http://remotehost/api/1_1'), + publicKey: expect.stringMatching( + '9c74d200b9c8b7210db8e65a58b869e4a8c84eb5b2b8b8e8d1ed74e6d9f5b7a1', + ), + endPoint: expect.stringMatching('http://remotehost/api'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -236,8 +270,10 @@ describe('CommunityResolver', () => { { id: 4, foreign: foreignCom1.foreign, - publicKey: expect.stringMatching('publicKey-ForeignCommunity'), - url: expect.stringMatching('http://remotehost/api/1_0'), + publicKey: expect.stringMatching( + '2e3c58f8fb7d9e4c1f2e3a9ec51cf4b1473d9b6b422853ac4c28e68ec41db4f3', + ), + endPoint: expect.stringMatching('http://remotehost/api'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -281,7 +317,10 @@ describe('CommunityResolver', () => { homeCom1 = DbCommunity.create() homeCom1.foreign = false homeCom1.url = 'http://localhost/api' - homeCom1.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom1.publicKey = Buffer.from( + '8a1f9374b99c30d827b85dcd23f7e50328430d64ef65ef35bf375ea8eb9a2e1d', + 'hex', + ) homeCom1.privateKey = Buffer.from('privateKey-HomeCommunity') homeCom1.communityUuid = 'HomeCom-UUID' homeCom1.authenticatedAt = new Date() @@ -319,7 +358,10 @@ describe('CommunityResolver', () => { homeCom1 = DbCommunity.create() homeCom1.foreign = false homeCom1.url = 'http://localhost/api' - homeCom1.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom1.publicKey = Buffer.from( + '8a1f9374b99c30d827b85dcd23f7e50328430d64ef65ef35bf375ea8eb9a2e1d', + 'hex', + ) homeCom1.privateKey = Buffer.from('privateKey-HomeCommunity') homeCom1.communityUuid = 'HomeCom-UUID' homeCom1.authenticatedAt = new Date() @@ -331,8 +373,14 @@ describe('CommunityResolver', () => { foreignCom1 = DbCommunity.create() foreignCom1.foreign = true foreignCom1.url = 'http://stage-2.gradido.net/api' - foreignCom1.publicKey = Buffer.from('publicKey-stage-2_Community') - foreignCom1.privateKey = Buffer.from('privateKey-stage-2_Community') + foreignCom1.publicKey = Buffer.from( + '8a1f9374b99c30d827b85dcd23f7e50328430d64ef65ef35bf375ea8eb9a2e1d', + 'hex', + ) + foreignCom1.privateKey = Buffer.from( + 'f6c2a9d78e20a3c910f35b8ffcf824aa7b37f0d3d81bfc4c0e65e17a194b3a4a', + 'hex', + ) // foreignCom1.communityUuid = 'Stage2-Com-UUID' // foreignCom1.authenticatedAt = new Date() foreignCom1.name = 'Stage-2_Community-name' @@ -343,8 +391,14 @@ describe('CommunityResolver', () => { foreignCom2 = DbCommunity.create() foreignCom2.foreign = true foreignCom2.url = 'http://stage-3.gradido.net/api' - foreignCom2.publicKey = Buffer.from('publicKey-stage-3_Community') - foreignCom2.privateKey = Buffer.from('privateKey-stage-3_Community') + foreignCom2.publicKey = Buffer.from( + 'e047365a54082e8a7e9273da61b55c8134a2a0c836799ba12b78b9b0c52bc85f', + 'hex', + ) + foreignCom2.privateKey = Buffer.from( + 'e047365a54082e8a7e9273da61b55c8134a2a0c836799ba12b78b9b0c52bc85f', + 'hex', + ) foreignCom2.communityUuid = 'Stage3-Com-UUID' foreignCom2.authenticatedAt = new Date() foreignCom2.name = 'Stage-3_Community-name' @@ -410,8 +464,14 @@ describe('CommunityResolver', () => { foreignCom1 = DbCommunity.create() foreignCom1.foreign = true foreignCom1.url = 'http://stage-2.gradido.net/api' - foreignCom1.publicKey = Buffer.from('publicKey-stage-2_Community') - foreignCom1.privateKey = Buffer.from('privateKey-stage-2_Community') + foreignCom1.publicKey = Buffer.from( + '8a1f9374b99c30d827b85dcd23f7e50328430d64ef65ef35bf375ea8eb9a2e1d', + 'hex', + ) + foreignCom1.privateKey = Buffer.from( + 'f6c2a9d78e20a3c910f35b8ffcf824aa7b37f0d3d81bfc4c0e65e17a194b3a4a', + 'hex', + ) // foreignCom1.communityUuid = 'Stage2-Com-UUID' // foreignCom1.authenticatedAt = new Date() foreignCom1.name = 'Stage-2_Community-name' @@ -422,8 +482,14 @@ describe('CommunityResolver', () => { foreignCom2 = DbCommunity.create() foreignCom2.foreign = true foreignCom2.url = 'http://stage-3.gradido.net/api' - foreignCom2.publicKey = Buffer.from('publicKey-stage-3_Community') - foreignCom2.privateKey = Buffer.from('privateKey-stage-3_Community') + foreignCom2.publicKey = Buffer.from( + 'e047365a54082e8a7e9273da61b55c8134a2a0c836799ba12b78b9b0c52bc85f', + 'hex', + ) + foreignCom2.privateKey = Buffer.from( + 'e047365a54082e8a7e9273da61b55c8134a2a0c836799ba12b78b9b0c52bc85f', + 'hex', + ) foreignCom2.communityUuid = 'Stage3-Com-UUID' foreignCom2.authenticatedAt = new Date() foreignCom2.name = 'Stage-3_Community-name' diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 44c3c35e1..05ef0c740 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -156,7 +156,7 @@ export const getCommunities = gql` id foreign publicKey - url + endPoint lastAnnouncedAt verifiedAt lastErrorAt From c7d6049bd965f0e18fe6567a4ba8397d646f81dc Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 13 Feb 2024 17:28:23 +0100 Subject: [PATCH 08/14] fix test --- .../graphql/resolver/CommunityResolver.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index 58dc6a90c..bb58b3e5b 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -164,7 +164,7 @@ describe('CommunityResolver', () => { id: 3, foreign: homeCom3.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[2].public), - url: expect.stringMatching('http://localhost/api/2_0'), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -175,7 +175,7 @@ describe('CommunityResolver', () => { id: 2, foreign: homeCom2.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[1].public), - url: expect.stringMatching('http://localhost/api/1_1'), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -186,7 +186,7 @@ describe('CommunityResolver', () => { id: 1, foreign: homeCom1.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[0].public), - url: expect.stringMatching('http://localhost/api/1_0'), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -236,7 +236,7 @@ describe('CommunityResolver', () => { id: 3, foreign: homeCom3.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[2].public), - url: expect.stringMatching('http://localhost/api/2_0'), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -247,7 +247,7 @@ describe('CommunityResolver', () => { id: 2, foreign: homeCom2.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[1].public), - url: expect.stringMatching('http://localhost/api/1_1'), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -258,7 +258,7 @@ describe('CommunityResolver', () => { id: 1, foreign: homeCom1.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[0].public), - url: expect.stringMatching('http://localhost/api/1_0'), + endPoint: expect.stringMatching('http://localhost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -269,7 +269,7 @@ describe('CommunityResolver', () => { id: 6, foreign: foreignCom3.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[5].public), - url: expect.stringMatching('http://remotehost/api/1_2'), + endPoint: expect.stringMatching('http://remotehost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -280,7 +280,7 @@ describe('CommunityResolver', () => { id: 5, foreign: foreignCom2.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[4].public), - url: expect.stringMatching('http://remotehost/api/1_1'), + endPoint: expect.stringMatching('http://remotehost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -291,7 +291,7 @@ describe('CommunityResolver', () => { id: 4, foreign: foreignCom1.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[3].public), - url: expect.stringMatching('http://remotehost/api/1_0'), + endPoint: expect.stringMatching('http://remotehost/api/'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, From ff3233e5ff10226287da61addc2450716b9430a0 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Wed, 14 Feb 2024 09:04:03 +0100 Subject: [PATCH 09/14] Delete .vscode/launch.json --- .vscode/launch.json | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 5a60c21e2..000000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "0.2.0", - "configurations": [ - { - "type": "node-terminal", - "name": "Admin: test", - "request": "launch", - "command": "yarn run test", - "cwd": "${workspaceFolder}/admin" - } - ] -} \ No newline at end of file From 6c16307949aa52608efc1d0af1dc85bed03a8f72 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 15 Feb 2024 20:12:52 +0100 Subject: [PATCH 10/14] fix problems with multiple entries with null id, vue seems automatic use id as key, despite the manuel choosen key publicKey --- admin/src/components/Federation/CommunityVisualizeItem.vue | 2 +- admin/src/graphql/allCommunities.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/admin/src/components/Federation/CommunityVisualizeItem.vue b/admin/src/components/Federation/CommunityVisualizeItem.vue index 4a5d9e67e..8d993f1d7 100644 --- a/admin/src/components/Federation/CommunityVisualizeItem.vue +++ b/admin/src/components/Federation/CommunityVisualizeItem.vue @@ -44,7 +44,7 @@ diff --git a/admin/src/graphql/allCommunities.js b/admin/src/graphql/allCommunities.js index 62010ec90..e14e533df 100644 --- a/admin/src/graphql/allCommunities.js +++ b/admin/src/graphql/allCommunities.js @@ -3,7 +3,6 @@ import gql from 'graphql-tag' export const allCommunities = gql` query { allCommunities { - id foreign url publicKey From b587a51ee855986174450c22f7f8c74cda598161 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 15 Feb 2024 23:29:22 +0100 Subject: [PATCH 11/14] implement suggested changes --- .../components/Federation/CommunityVisualizeItem.vue | 6 +++--- admin/src/graphql/allCommunities.js | 2 +- backend/src/graphql/model/Community.ts | 4 ---- .../src/graphql/resolver/CommunityResolver.test.ts | 11 ++++++++++- backend/src/seeds/graphql/queries.ts | 1 + .../FederatedCommunity.ts | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) diff --git a/admin/src/components/Federation/CommunityVisualizeItem.vue b/admin/src/components/Federation/CommunityVisualizeItem.vue index 8d993f1d7..24e6b3712 100644 --- a/admin/src/components/Federation/CommunityVisualizeItem.vue +++ b/admin/src/components/Federation/CommunityVisualizeItem.vue @@ -15,8 +15,8 @@ - - {{ $t('federation.communityUuid') }} {{ item.communityUuid }} + + {{ $t('federation.communityUuid') }} {{ item.uuid }} {{ $t('federation.authenticatedAt') }} {{ item.authenticatedAt }} @@ -144,7 +144,7 @@ export default { .mutate({ mutation: updateHomeCommunity, variables: { - uuid: this.item.communityUuid, + uuid: this.item.uuid, gmsApiKey: gmsApiKey, }, }) diff --git a/admin/src/graphql/allCommunities.js b/admin/src/graphql/allCommunities.js index e14e533df..6379086c7 100644 --- a/admin/src/graphql/allCommunities.js +++ b/admin/src/graphql/allCommunities.js @@ -6,7 +6,7 @@ export const allCommunities = gql` foreign url publicKey - communityUuid + uuid authenticatedAt name description diff --git a/backend/src/graphql/model/Community.ts b/backend/src/graphql/model/Community.ts index 0c4424fa3..db860216a 100644 --- a/backend/src/graphql/model/Community.ts +++ b/backend/src/graphql/model/Community.ts @@ -31,7 +31,6 @@ export class Community { if (dbCom.publicKey && dbCom.publicKey.length === 32) { this.publicKey = dbCom.publicKey.toString('hex') } - this.communityUuid = dbCom.communityUuid this.creationDate = dbCom.creationDate this.createdAt = dbCom.createdAt this.updatedAt = dbCom.updatedAt @@ -61,9 +60,6 @@ export class Community { @Field(() => String) publicKey: string - @Field(() => String, { nullable: true }) - communityUuid: string | null - @Field(() => Date, { nullable: true }) creationDate: Date | null diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index bb58b3e5b..af714e746 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -165,6 +165,7 @@ describe('CommunityResolver', () => { foreign: homeCom3.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[2].public), endPoint: expect.stringMatching('http://localhost/api/'), + apiVersion: '2_0', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -176,6 +177,7 @@ describe('CommunityResolver', () => { foreign: homeCom2.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[1].public), endPoint: expect.stringMatching('http://localhost/api/'), + apiVersion: '1_1', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -187,6 +189,7 @@ describe('CommunityResolver', () => { foreign: homeCom1.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[0].public), endPoint: expect.stringMatching('http://localhost/api/'), + apiVersion: '1_0', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -222,7 +225,7 @@ describe('CommunityResolver', () => { foreignCom3 = DbFederatedCommunity.create() foreignCom3.foreign = true foreignCom3.publicKey = Buffer.from(ed25519KeyPairStaticHex[5].public, 'hex') - foreignCom3.apiVersion = '1_2' + foreignCom3.apiVersion = '2_0' foreignCom3.endPoint = 'http://remotehost/api' foreignCom3.createdAt = new Date() await DbFederatedCommunity.insert(foreignCom3) @@ -237,6 +240,7 @@ describe('CommunityResolver', () => { foreign: homeCom3.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[2].public), endPoint: expect.stringMatching('http://localhost/api/'), + apiVersion: '2_0', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -248,6 +252,7 @@ describe('CommunityResolver', () => { foreign: homeCom2.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[1].public), endPoint: expect.stringMatching('http://localhost/api/'), + apiVersion: '1_1', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -259,6 +264,7 @@ describe('CommunityResolver', () => { foreign: homeCom1.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[0].public), endPoint: expect.stringMatching('http://localhost/api/'), + apiVersion: '1_0', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -270,6 +276,7 @@ describe('CommunityResolver', () => { foreign: foreignCom3.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[5].public), endPoint: expect.stringMatching('http://remotehost/api/'), + apiVersion: '2_0', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -281,6 +288,7 @@ describe('CommunityResolver', () => { foreign: foreignCom2.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[4].public), endPoint: expect.stringMatching('http://remotehost/api/'), + apiVersion: '1_1', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, @@ -292,6 +300,7 @@ describe('CommunityResolver', () => { foreign: foreignCom1.foreign, publicKey: expect.stringMatching(ed25519KeyPairStaticHex[3].public), endPoint: expect.stringMatching('http://remotehost/api/'), + apiVersion: '1_0', lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index f988783b8..c3005ff96 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -157,6 +157,7 @@ export const getCommunities = gql` foreign publicKey endPoint + apiVersion lastAnnouncedAt verifiedAt lastErrorAt diff --git a/database/entity/0083-join_community_federated_communities/FederatedCommunity.ts b/database/entity/0083-join_community_federated_communities/FederatedCommunity.ts index 7e13744c8..b5eb64ea1 100644 --- a/database/entity/0083-join_community_federated_communities/FederatedCommunity.ts +++ b/database/entity/0083-join_community_federated_communities/FederatedCommunity.ts @@ -52,7 +52,7 @@ export class FederatedCommunity extends BaseEntity { }) updatedAt: Date | null - @ManyToOne(() => Community, (community) => community.federatedCommunities) // Assuming you have a User entity with 'accounts' relation + @ManyToOne(() => Community, (community) => community.federatedCommunities) @JoinColumn({ name: 'public_key', referencedColumnName: 'publicKey' }) community?: Community } From d187c541da42311e14cd2ec267eb908818fb2258 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Wed, 21 Feb 2024 18:15:54 +0100 Subject: [PATCH 12/14] move adjustet Community Model Code into separat Model Class --- .../src/graphql/model/AdminCommunityView.ts | 76 +++++++++++++++++++ backend/src/graphql/model/Community.ts | 46 ++--------- .../src/graphql/resolver/CommunityResolver.ts | 7 +- 3 files changed, 85 insertions(+), 44 deletions(-) create mode 100644 backend/src/graphql/model/AdminCommunityView.ts diff --git a/backend/src/graphql/model/AdminCommunityView.ts b/backend/src/graphql/model/AdminCommunityView.ts new file mode 100644 index 000000000..95af54bc5 --- /dev/null +++ b/backend/src/graphql/model/AdminCommunityView.ts @@ -0,0 +1,76 @@ +import { Community as DbCommunity } from '@entity/Community' +import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' +import { ObjectType, Field } from 'type-graphql' + +import { FederatedCommunity } from './FederatedCommunity' + +@ObjectType() +export class AdminCommunityView { + constructor(dbCom: DbCommunity) { + if (dbCom.federatedCommunities && dbCom.federatedCommunities.length > 0) { + const federatedCommunity = dbCom.federatedCommunities[0] + this.foreign = federatedCommunity.foreign + const url = new URL(federatedCommunity.endPoint) + // use only the host part + this.url = url.protocol + '//' + url.host + this.publicKey = federatedCommunity.publicKey.toString('hex') + this.federatedCommunities = dbCom.federatedCommunities.map( + (federatedCom: DbFederatedCommunity) => new FederatedCommunity(federatedCom), + ) + } + if (dbCom.foreign !== undefined) { + this.foreign = dbCom.foreign + } + this.name = dbCom.name + this.description = dbCom.description + this.gmsApiKey = dbCom.gmsApiKey + if (dbCom.url) { + this.url = dbCom.url + } + if (dbCom.publicKey && dbCom.publicKey.length === 32) { + this.publicKey = dbCom.publicKey.toString('hex') + } + this.creationDate = dbCom.creationDate + this.createdAt = dbCom.createdAt + this.updatedAt = dbCom.updatedAt + this.uuid = dbCom.communityUuid + this.authenticatedAt = dbCom.authenticatedAt + this.gmsApiKey = dbCom.gmsApiKey + } + + @Field(() => Boolean) + foreign: boolean + + @Field(() => String) + url: string + + @Field(() => String) + publicKey: string + + @Field(() => String, { nullable: true }) + uuid: string | null + + @Field(() => Date, { nullable: true }) + authenticatedAt: Date | null + + @Field(() => String, { nullable: true }) + name: string | null + + @Field(() => String, { nullable: true }) + description: string | null + + @Field(() => String, { nullable: true }) + gmsApiKey: string | null + + @Field(() => Date, { nullable: true }) + creationDate: Date | null + + @Field(() => Date, { nullable: true }) + createdAt: Date | null + + @Field(() => Date, { nullable: true }) + updatedAt: Date | null + + @Field(() => [FederatedCommunity], { nullable: true }) + federatedCommunities: FederatedCommunity[] | null +} diff --git a/backend/src/graphql/model/Community.ts b/backend/src/graphql/model/Community.ts index db860216a..06c07875e 100644 --- a/backend/src/graphql/model/Community.ts +++ b/backend/src/graphql/model/Community.ts @@ -1,39 +1,15 @@ import { Community as DbCommunity } from '@entity/Community' -import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' import { ObjectType, Field, Int } from 'type-graphql' -import { FederatedCommunity } from './FederatedCommunity' - @ObjectType() export class Community { constructor(dbCom: DbCommunity) { - if (dbCom.federatedCommunities && dbCom.federatedCommunities.length > 0) { - const federatedCommunity = dbCom.federatedCommunities[0] - this.foreign = federatedCommunity.foreign - const url = new URL(federatedCommunity.endPoint) - // use only the host part - this.url = url.protocol + '//' + url.host - this.publicKey = federatedCommunity.publicKey.toString('hex') - this.federatedCommunities = dbCom.federatedCommunities.map( - (federatedCom: DbFederatedCommunity) => new FederatedCommunity(federatedCom), - ) - } - this.id = dbCom.id ?? 0 - if (dbCom.foreign !== undefined) { - this.foreign = dbCom.foreign - } + this.id = dbCom.id + this.foreign = dbCom.foreign this.name = dbCom.name this.description = dbCom.description - this.gmsApiKey = dbCom.gmsApiKey - if (dbCom.url) { - this.url = dbCom.url - } - if (dbCom.publicKey && dbCom.publicKey.length === 32) { - this.publicKey = dbCom.publicKey.toString('hex') - } + this.url = dbCom.url this.creationDate = dbCom.creationDate - this.createdAt = dbCom.createdAt - this.updatedAt = dbCom.updatedAt this.uuid = dbCom.communityUuid this.authenticatedAt = dbCom.authenticatedAt this.gmsApiKey = dbCom.gmsApiKey @@ -51,30 +27,18 @@ export class Community { @Field(() => String, { nullable: true }) description: string | null - @Field(() => String, { nullable: true }) - gmsApiKey: string | null - @Field(() => String) url: string - @Field(() => String) - publicKey: string - @Field(() => Date, { nullable: true }) creationDate: Date | null - @Field(() => Date, { nullable: true }) - createdAt: Date | null - - @Field(() => Date, { nullable: true }) - updatedAt: Date | null - @Field(() => String, { nullable: true }) uuid: string | null @Field(() => Date, { nullable: true }) authenticatedAt: Date | null - @Field(() => [FederatedCommunity], { nullable: true }) - federatedCommunities: FederatedCommunity[] | null + @Field(() => String, { nullable: true }) + gmsApiKey: string | null } diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index d6e69694e..9cab50610 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -5,6 +5,7 @@ import { Resolver, Query, Authorized, Arg, Mutation, Args } from 'type-graphql' import { CommunityArgs } from '@arg//CommunityArgs' import { Paginated } from '@arg/Paginated' +import { AdminCommunityView } from '@model/AdminCommunityView' import { Community } from '@model/Community' import { FederatedCommunity } from '@model/FederatedCommunity' @@ -31,9 +32,9 @@ export class CommunityResolver { } @Authorized([RIGHTS.COMMUNITIES]) - @Query(() => [Community]) - async allCommunities(@Args() paginated: Paginated): Promise { - return (await getAllCommunities(paginated)).map((dbCom) => new Community(dbCom)) + @Query(() => [AdminCommunityView]) + async allCommunities(@Args() paginated: Paginated): Promise { + return (await getAllCommunities(paginated)).map((dbCom) => new AdminCommunityView(dbCom)) } @Authorized([RIGHTS.COMMUNITIES]) From 7aa75b0abd3600b5fce01914b4da01b985b20eb3 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Wed, 21 Feb 2024 19:29:12 +0100 Subject: [PATCH 13/14] add test --- .../resolver/CommunityResolver.test.ts | 230 +++++++++++++++++- backend/src/seeds/graphql/queries.ts | 28 +++ 2 files changed, 257 insertions(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index af714e746..0e4bd5e70 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -16,7 +16,12 @@ import { logger, i18n as localization } from '@test/testSetup' import { userFactory } from '@/seeds/factory/user' import { login, updateHomeCommunityQuery } from '@/seeds/graphql/mutations' -import { getCommunities, communitiesQuery, getCommunityByUuidQuery } from '@/seeds/graphql/queries' +import { + getCommunities, + communitiesQuery, + getCommunityByUuidQuery, + allCommunities, +} from '@/seeds/graphql/queries' import { peterLustig } from '@/seeds/users/peter-lustig' import { getCommunityByUuid } from './util/communities' @@ -312,6 +317,229 @@ describe('CommunityResolver', () => { }) }) }) + + describe('with 6 federated community entries', () => { + let comHomeCom1: DbCommunity + let comForeignCom1: DbCommunity + let comForeignCom2: DbCommunity + let foreignCom4: DbFederatedCommunity + + beforeEach(async () => { + jest.clearAllMocks() + comHomeCom1 = DbCommunity.create() + comHomeCom1.foreign = false + comHomeCom1.url = 'http://localhost' + comHomeCom1.publicKey = Buffer.from(ed25519KeyPairStaticHex[0].public, 'hex') + comHomeCom1.privateKey = Buffer.from(ed25519KeyPairStaticHex[0].private, 'hex') + comHomeCom1.communityUuid = 'HomeCom-UUID' + comHomeCom1.authenticatedAt = new Date() + comHomeCom1.name = 'HomeCommunity-name' + comHomeCom1.description = 'HomeCommunity-description' + comHomeCom1.creationDate = new Date() + await DbCommunity.insert(comHomeCom1) + + comForeignCom1 = DbCommunity.create() + comForeignCom1.foreign = true + comForeignCom1.url = 'http://stage-2.gradido.net' + comForeignCom1.publicKey = Buffer.from(ed25519KeyPairStaticHex[3].public, 'hex') + comForeignCom1.privateKey = Buffer.from(ed25519KeyPairStaticHex[3].private, 'hex') + // foreignCom1.communityUuid = 'Stage2-Com-UUID' + // foreignCom1.authenticatedAt = new Date() + comForeignCom1.name = 'Stage-2_Community-name' + comForeignCom1.description = 'Stage-2_Community-description' + comForeignCom1.creationDate = new Date() + await DbCommunity.insert(comForeignCom1) + + comForeignCom2 = DbCommunity.create() + comForeignCom2.foreign = true + comForeignCom2.url = 'http://stage-3.gradido.net' + comForeignCom2.publicKey = Buffer.from(ed25519KeyPairStaticHex[4].public, 'hex') + comForeignCom2.privateKey = Buffer.from(ed25519KeyPairStaticHex[4].private, 'hex') + comForeignCom2.communityUuid = 'Stage3-Com-UUID' + comForeignCom2.authenticatedAt = new Date() + comForeignCom2.name = 'Stage-3_Community-name' + comForeignCom2.description = 'Stage-3_Community-description' + comForeignCom2.creationDate = new Date() + await DbCommunity.insert(comForeignCom2) + + foreignCom4 = DbFederatedCommunity.create() + foreignCom4.foreign = true + foreignCom4.publicKey = Buffer.from(ed25519KeyPairStaticHex[5].public, 'hex') + foreignCom4.apiVersion = '1_0' + foreignCom4.endPoint = 'http://remotehost/api' + foreignCom4.createdAt = new Date() + await DbFederatedCommunity.insert(foreignCom4) + }) + + it('return communities structured for admin ', async () => { + await expect(query({ query: allCommunities })).resolves.toMatchObject({ + data: { + allCommunities: [ + { + foreign: false, + url: 'http://localhost', + publicKey: expect.stringMatching(ed25519KeyPairStaticHex[2].public), + authenticatedAt: null, + createdAt: null, + creationDate: null, + description: null, + gmsApiKey: null, + name: null, + updatedAt: null, + uuid: null, + federatedCommunities: [ + { + id: 3, + apiVersion: '2_0', + endPoint: 'http://localhost/api/', + createdAt: homeCom3.createdAt.toISOString(), + lastAnnouncedAt: null, + lastErrorAt: null, + updatedAt: null, + verifiedAt: null, + }, + ], + }, + { + foreign: false, + url: 'http://localhost', + publicKey: expect.stringMatching(ed25519KeyPairStaticHex[1].public), + authenticatedAt: null, + createdAt: null, + creationDate: null, + description: null, + gmsApiKey: null, + name: null, + updatedAt: null, + uuid: null, + federatedCommunities: [ + { + id: 2, + apiVersion: '1_1', + endPoint: 'http://localhost/api/', + createdAt: homeCom2.createdAt.toISOString(), + lastAnnouncedAt: null, + lastErrorAt: null, + updatedAt: null, + verifiedAt: null, + }, + ], + }, + { + foreign: false, + url: 'http://localhost', + publicKey: expect.stringMatching(ed25519KeyPairStaticHex[0].public), + authenticatedAt: comHomeCom1.authenticatedAt?.toISOString(), + createdAt: comHomeCom1.createdAt.toISOString(), + creationDate: comHomeCom1.creationDate?.toISOString(), + description: comHomeCom1.description, + gmsApiKey: null, + name: comHomeCom1.name, + updatedAt: null, + uuid: comHomeCom1.communityUuid, + federatedCommunities: [ + { + id: 1, + apiVersion: '1_0', + endPoint: 'http://localhost/api/', + createdAt: homeCom1.createdAt.toISOString(), + lastAnnouncedAt: null, + lastErrorAt: null, + updatedAt: null, + verifiedAt: null, + }, + ], + }, + { + foreign: true, + url: 'http://remotehost', + publicKey: expect.stringMatching(ed25519KeyPairStaticHex[5].public), + authenticatedAt: null, + createdAt: null, + creationDate: null, + description: null, + gmsApiKey: null, + name: null, + updatedAt: null, + uuid: null, + federatedCommunities: [ + { + id: 7, + apiVersion: '1_0', + endPoint: 'http://remotehost/api/', + createdAt: foreignCom4.createdAt.toISOString(), + lastAnnouncedAt: null, + lastErrorAt: null, + updatedAt: null, + verifiedAt: null, + }, + { + id: 6, + apiVersion: '2_0', + endPoint: 'http://remotehost/api/', + createdAt: foreignCom3.createdAt.toISOString(), + lastAnnouncedAt: null, + lastErrorAt: null, + updatedAt: null, + verifiedAt: null, + }, + ], + }, + { + foreign: true, + url: 'http://stage-3.gradido.net', + publicKey: expect.stringMatching(ed25519KeyPairStaticHex[4].public), + authenticatedAt: comForeignCom2.authenticatedAt?.toISOString(), + createdAt: comForeignCom2.createdAt.toISOString(), + creationDate: comForeignCom2.creationDate?.toISOString(), + description: comForeignCom2.description, + gmsApiKey: null, + name: comForeignCom2.name, + updatedAt: null, + uuid: comForeignCom2.communityUuid, + federatedCommunities: [ + { + id: 5, + apiVersion: '1_1', + endPoint: 'http://remotehost/api/', + createdAt: foreignCom2.createdAt.toISOString(), + lastAnnouncedAt: null, + lastErrorAt: null, + updatedAt: null, + verifiedAt: null, + }, + ], + }, + { + foreign: true, + url: 'http://stage-2.gradido.net', + publicKey: expect.stringMatching(ed25519KeyPairStaticHex[3].public), + authenticatedAt: null, + createdAt: comForeignCom1.createdAt.toISOString(), + creationDate: comForeignCom1.creationDate?.toISOString(), + description: comForeignCom1.description, + gmsApiKey: null, + name: comForeignCom1.name, + updatedAt: null, + uuid: null, + federatedCommunities: [ + { + id: 4, + apiVersion: '1_0', + endPoint: 'http://remotehost/api/', + createdAt: foreignCom1.createdAt.toISOString(), + lastAnnouncedAt: null, + lastErrorAt: null, + updatedAt: null, + verifiedAt: null, + }, + ], + }, + ], + }, + }) + }) + }) }) describe('communities', () => { diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index c3005ff96..c3e7974a4 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -167,6 +167,34 @@ export const getCommunities = gql` } ` +export const allCommunities = gql` + query { + allCommunities { + foreign + url + publicKey + uuid + authenticatedAt + name + description + gmsApiKey + creationDate + createdAt + updatedAt + federatedCommunities { + id + apiVersion + endPoint + lastAnnouncedAt + verifiedAt + lastErrorAt + createdAt + updatedAt + } + } + } +` + export const queryTransactionLink = gql` query ($code: String!) { queryTransactionLink(code: $code) { From d331a50d7869c1aa5bc1d6a6b554e3ba8733b702 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Thu, 29 Feb 2024 15:00:52 +0100 Subject: [PATCH 14/14] update test --- backend/src/graphql/resolver/CommunityResolver.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index 2d60f3444..8b5c05d5b 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -729,7 +729,7 @@ describe('CommunityResolver', () => { 'e047365a54082e8a7e9273da61b55c8134a2a0c836799ba12b78b9b0c52bc85f', 'hex', ) - foreignCom2.communityUuid = 'Stage3-Com-UUID' + foreignCom2.communityUuid = uuidv4() foreignCom2.authenticatedAt = new Date() foreignCom2.name = 'Stage-3_Community-name' foreignCom2.description = 'Stage-3_Community-description'