From abcad503b000c97315104321c7350aa06c1e0428 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Mon, 6 Mar 2023 22:40:41 +0100 Subject: [PATCH 01/17] optimize log-output --- federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts index 53f0d0bd4..8670c3d1d 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts @@ -7,12 +7,12 @@ import { GetPublicKeyResult } from '../model/GetPublicKeyResult' export class PublicKeyResolver { @Query(() => GetPublicKeyResult) async getPublicKey(): Promise { - logger.info(`getPublicKey()...`) + logger.debug(`getPublicKey() via apiVersion=1_0 ...`) const homeCom = await DbCommunity.findOneOrFail({ foreign: false, apiVersion: '1_0', }) - logger.info(`getPublicKey()... with publicKey=${homeCom.publicKey}`) + logger.info(`getPublicKey()-1_0... return publicKey=${homeCom.publicKey}`) return new GetPublicKeyResult(homeCom.publicKey.toString()) } } From 46831167bc905345283bfd0807a81c2d2744a893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 01:14:18 +0100 Subject: [PATCH 02/17] new testclass --- .../1_0/resolver/PublicKeyResolver.test.ts | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts new file mode 100644 index 000000000..1622c7be4 --- /dev/null +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -0,0 +1,54 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { createTestClient } from 'apollo-server-testing' +import createServer from '@/server/createServer' +import { Community as DbCommunity } from '@entity/Community' + +let query: any +let testEnv: any + +// to do: We need a setup for the tests that closes the connection +let con: any + +beforeAll(async () => { + const server = await createServer() + con = server.con + query = createTestClient(server.apollo).query + DbCommunity.clear() +}) + +afterAll(async () => { + await con.close() +}) + +describe('PublicKeyResolver', () => { + const getPublicKeyQuery = ` + query { + getPublicKey + { + publicKey + } + } + ` + + describe('getPublicKey', () => { + beforeEach(async () => { + const homeCom = new DbCommunity() + homeCom.foreign = false + homeCom.apiVersion = '1_0' + homeCom.endPoint = 'endpoint-url' + homeCom.publicKey = Buffer.from('homeCommunity-publicKey') + await DbCommunity.insert(homeCom) + }) + + it('returns homeCommunity-publicKey', async () => { + await expect(query({ query: getPublicKeyQuery })).resolves.toMatchObject({ + data: { + getPublicKey: { + publicKey: 'homeCommunity-publicKey', + }, + }, + }) + }) + }) +}) From c71e293e6732ae68ca7673c6698e445f6d311d10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 03:48:43 +0100 Subject: [PATCH 03/17] next try for test --- .../src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts index 1622c7be4..25fde9f3c 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -42,13 +42,14 @@ describe('PublicKeyResolver', () => { }) it('returns homeCommunity-publicKey', async () => { - await expect(query({ query: getPublicKeyQuery })).resolves.toMatchObject({ + await expect(query({ query: getPublicKeyQuery })).resolves.toEqual(expect.objectContaining({ data: { getPublicKey: { publicKey: 'homeCommunity-publicKey', }, }, }) + ) }) }) }) From f442c289c2e67b0a3bc011d37259956d87a39b54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Tue, 7 Mar 2023 22:55:23 +0100 Subject: [PATCH 04/17] next try, but doesn't work --- .../api/1_0/resolver/PublicKeyResolver.test.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts index 25fde9f3c..fffb83e7d 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -42,13 +42,14 @@ describe('PublicKeyResolver', () => { }) it('returns homeCommunity-publicKey', async () => { - await expect(query({ query: getPublicKeyQuery })).resolves.toEqual(expect.objectContaining({ - data: { - getPublicKey: { - publicKey: 'homeCommunity-publicKey', + await expect(query({ query: getPublicKeyQuery })).resolves.toContainEqual( + expect.objectContaining({ + data: { + getPublicKey: { + publicKey: 'homeCommunity-publicKey', + }, }, - }, - }) + }) ) }) }) From a1e8a4aab2bbfca70e4bf1bf2dc91d4cd05a395a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 9 Mar 2023 14:40:28 +0100 Subject: [PATCH 05/17] linting --- federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts | 2 ++ federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts b/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts index 1582ad892..696c96cfe 100644 --- a/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts +++ b/federation/src/graphql/api/1_0/model/GetPublicKeyResult.ts @@ -1,6 +1,8 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars import { Field, ObjectType } from 'type-graphql' @ObjectType() +// eslint-disable-next-line @typescript-eslint/no-unused-vars export class GetPublicKeyResult { constructor(pubKey: string) { this.publicKey = pubKey diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts index 8670c3d1d..df7bd3dc9 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.ts @@ -1,9 +1,11 @@ +// eslint-disable-next-line @typescript-eslint/no-unused-vars import { Field, ObjectType, Query, Resolver } from 'type-graphql' import { federationLogger as logger } from '@/server/logger' import { Community as DbCommunity } from '@entity/Community' import { GetPublicKeyResult } from '../model/GetPublicKeyResult' @Resolver() +// eslint-disable-next-line @typescript-eslint/no-unused-vars export class PublicKeyResolver { @Query(() => GetPublicKeyResult) async getPublicKey(): Promise { From 4d19ce06b5221cb132b080d44f84fd821cf44c64 Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Thu, 9 Mar 2023 15:18:31 +0100 Subject: [PATCH 06/17] fix test --- .../api/1_0/resolver/PublicKeyResolver.test.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts index fffb83e7d..b355f075e 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -42,15 +42,13 @@ describe('PublicKeyResolver', () => { }) it('returns homeCommunity-publicKey', async () => { - await expect(query({ query: getPublicKeyQuery })).resolves.toContainEqual( - expect.objectContaining({ - data: { - getPublicKey: { - publicKey: 'homeCommunity-publicKey', - }, + await expect(query({ query: getPublicKeyQuery })).resolves.toMatchObject({ + data: { + getPublicKey: { + publicKey: expect.stringMatching('homeCommunity-publicKey'), }, - }) - ) + }, + }) }) }) }) From 297abea1ec0aa634c7a60e0465ba12fec3d16654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 9 Mar 2023 15:48:24 +0100 Subject: [PATCH 07/17] linting --- .../src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts index b355f075e..20e6c8228 100644 --- a/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts +++ b/federation/src/graphql/api/1_0/resolver/PublicKeyResolver.test.ts @@ -5,7 +5,6 @@ import createServer from '@/server/createServer' import { Community as DbCommunity } from '@entity/Community' let query: any -let testEnv: any // to do: We need a setup for the tests that closes the connection let con: any From 9a834fa720e55cdf0f563263695a0cbd52e4e72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 9 Mar 2023 18:56:25 +0100 Subject: [PATCH 08/17] implement getCommunities in CommunityResolver --- backend/src/graphql/model/Community.ts | 46 ++++-- .../resolver/CommunityResolver.test.ts | 136 +++++++++--------- .../src/graphql/resolver/CommunityResolver.ts | 55 ++----- .../Community.ts | 6 +- 4 files changed, 111 insertions(+), 132 deletions(-) diff --git a/backend/src/graphql/model/Community.ts b/backend/src/graphql/model/Community.ts index 466028d00..9840dda9e 100644 --- a/backend/src/graphql/model/Community.ts +++ b/backend/src/graphql/model/Community.ts @@ -1,31 +1,47 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { ObjectType, Field } from 'type-graphql' +import { Community as DbCommunity } from '@entity/Community' @ObjectType() export class Community { - constructor(json?: any) { - if (json) { - this.id = Number(json.id) - this.name = json.name - this.url = json.url - this.description = json.description - this.registerUrl = json.registerUrl - } + constructor(dbCom: DbCommunity) { + this.id = dbCom.id + this.foreign = dbCom.foreign + this.publicKey = dbCom.publicKey.toString() + this.url = + (dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/') + + 'api/' + + dbCom.apiVersion + this.lastAnnouncedAt = dbCom.lastAnnouncedAt + this.verifiedAt = dbCom.verifiedAt + this.lastErrorAt = dbCom.lastErrorAt + this.createdAt = dbCom.createdAt + this.updatedAt = dbCom.updatedAt } @Field(() => Number) id: number + @Field(() => Boolean) + foreign: boolean + @Field(() => String) - name: string + publicKey: string @Field(() => String) url: string - @Field(() => String) - description: string + @Field(() => Date, { nullable: true }) + lastAnnouncedAt: Date | null - @Field(() => String) - registerUrl: string + @Field(() => Date, { nullable: true }) + verifiedAt: Date | null + + @Field(() => Date, { nullable: true }) + lastErrorAt: Date | null + + @Field(() => Date, { nullable: true }) + createdAt: Date | null + + @Field(() => Date, { nullable: true }) + updatedAt: Date | null } diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index cb916e47c..c48ab0f25 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -3,7 +3,9 @@ import { createTestClient } from 'apollo-server-testing' import createServer from '@/server/createServer' -import CONFIG from '@/config' +import { resetEntity } from '@test/helpers' +import { Community as DbCommunity } from '@entity/Community' +import { Community } from '../model/Community' jest.mock('@/config') @@ -16,6 +18,7 @@ beforeAll(async () => { const server = await createServer({}) con = server.con query = createTestClient(server.apollo).query + resetEntity(DbCommunity) }) afterAll(async () => { @@ -23,96 +26,93 @@ afterAll(async () => { }) describe('CommunityResolver', () => { - const getCommunityInfoQuery = ` + const getCommunities = ` query { - getCommunityInfo { - name - description - url - registerUrl - } - } - ` - - const communities = ` - query { - communities { + getCommunities { id - name + foreign + publicKey url - description - registerUrl + lastAnnouncedAt + verifiedAt + lastErrorAt + createdAt + updatedAt } } ` - describe('getCommunityInfo', () => { - it('returns the default values', async () => { - await expect(query({ query: getCommunityInfoQuery })).resolves.toMatchObject({ - data: { - getCommunityInfo: { - name: 'Gradido Entwicklung', - description: 'Die lokale Entwicklungsumgebung von Gradido.', - url: 'http://localhost/', - registerUrl: 'http://localhost/register', - }, - }, + describe('getCommunities', () => { + describe('with empty list', () => { + it('returns no community entry', async () => { + const result: Community[] = await query({ query: getCommunities }) + expect(result.length).decimalEqual(0) }) }) - }) - describe('communities', () => { - describe('PRODUCTION = false', () => { + describe('only home-communities entries', () => { beforeEach(() => { - CONFIG.PRODUCTION = false + const homeCom1 = DbCommunity.create() + homeCom1.foreign = false + homeCom1.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom1.apiVersion = '1_0' + homeCom1.endPoint = 'https://localhost' + homeCom1.createdAt = new Date() + DbCommunity.save(homeCom1) + + const homeCom2 = DbCommunity.create() + homeCom2.foreign = false + homeCom2.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom2.apiVersion = '1_1' + homeCom2.endPoint = 'https://localhost' + homeCom2.createdAt = new Date() + DbCommunity.save(homeCom2) + + const homeCom3 = DbCommunity.create() + homeCom3.foreign = false + homeCom3.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom3.apiVersion = '2_0' + homeCom3.endPoint = 'https://localhost' + homeCom3.createdAt = new Date() + DbCommunity.save(homeCom3) }) - it('returns three communities', async () => { - await expect(query({ query: communities })).resolves.toMatchObject({ + it('returns three home-community entries', async () => { + await expect(query({ query: getCommunities })).resolves.toMatchObject({ data: { communities: [ { id: 1, - name: 'Gradido Entwicklung', - description: 'Die lokale Entwicklungsumgebung von Gradido.', - url: 'http://localhost/', - registerUrl: 'http://localhost/register-community', + foreign: false, + publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()), + url: 'http://localhost/api/1_0', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: expect.any(Date), + updatedAt: null, }, { id: 2, - name: 'Gradido Staging', - description: 'Der Testserver der Gradido-Akademie.', - url: 'https://stage1.gradido.net/', - registerUrl: 'https://stage1.gradido.net/register-community', + foreign: false, + publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()), + url: 'http://localhost/api/1_1', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: expect.any(Date), + updatedAt: null, }, { id: 3, - name: 'Gradido-Akademie', - description: 'Freies Institut für Wirtschaftsbionik.', - url: 'https://gradido.net', - registerUrl: 'https://gdd1.gradido.com/register-community', - }, - ], - }, - }) - }) - }) - - describe('PRODUCTION = true', () => { - beforeEach(() => { - CONFIG.PRODUCTION = true - }) - - it('returns one community', async () => { - await expect(query({ query: communities })).resolves.toMatchObject({ - data: { - communities: [ - { - id: 3, - name: 'Gradido-Akademie', - description: 'Freies Institut für Wirtschaftsbionik.', - url: 'https://gradido.net', - registerUrl: 'https://gdd1.gradido.com/register-community', + foreign: false, + publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()), + url: 'http://localhost/api/2_0', + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: expect.any(Date), + updatedAt: null, }, ], }, diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index f56254e1f..8250170c6 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -1,58 +1,21 @@ import { Resolver, Query, Authorized } from 'type-graphql' import { Community } from '@model/Community' +import { Community as DbCommunity } from '@entity/Community' import { RIGHTS } from '@/auth/RIGHTS' -import CONFIG from '@/config' @Resolver() export class CommunityResolver { - @Authorized([RIGHTS.GET_COMMUNITY_INFO]) - @Query(() => Community) - async getCommunityInfo(): Promise { - return new Community({ - name: CONFIG.COMMUNITY_NAME, - description: CONFIG.COMMUNITY_DESCRIPTION, - url: CONFIG.COMMUNITY_URL, - registerUrl: CONFIG.COMMUNITY_REGISTER_URL, - }) - } - @Authorized([RIGHTS.COMMUNITIES]) @Query(() => [Community]) - async communities(): Promise { - if (CONFIG.PRODUCTION) - return [ - new Community({ - id: 3, - name: 'Gradido-Akademie', - description: 'Freies Institut für Wirtschaftsbionik.', - url: 'https://gradido.net', - registerUrl: 'https://gdd1.gradido.com/register-community', - }), - ] - return [ - new Community({ - id: 1, - name: 'Gradido Entwicklung', - description: 'Die lokale Entwicklungsumgebung von Gradido.', - url: 'http://localhost/', - registerUrl: 'http://localhost/register-community', - }), - new Community({ - id: 2, - name: 'Gradido Staging', - description: 'Der Testserver der Gradido-Akademie.', - url: 'https://stage1.gradido.net/', - registerUrl: 'https://stage1.gradido.net/register-community', - }), - new Community({ - id: 3, - name: 'Gradido-Akademie', - description: 'Freies Institut für Wirtschaftsbionik.', - url: 'https://gradido.net', - registerUrl: 'https://gdd1.gradido.com/register-community', - }), - ] + async getCommunities(): Promise { + const comList: Community[] = [] + const dbCommunities: DbCommunity[] = await DbCommunity.find() + dbCommunities.forEach(async function (dbCom) { + const com = new Community(dbCom) + comList.push(com) + }) + return comList } } diff --git a/database/entity/0060-update_communities_table/Community.ts b/database/entity/0060-update_communities_table/Community.ts index 5ded76cf9..ab7cfb58a 100644 --- a/database/entity/0060-update_communities_table/Community.ts +++ b/database/entity/0060-update_communities_table/Community.ts @@ -25,13 +25,13 @@ export class Community extends BaseEntity { endPoint: string @Column({ name: 'last_announced_at', type: 'datetime', nullable: true }) - lastAnnouncedAt: Date + lastAnnouncedAt: Date | null @Column({ name: 'verified_at', type: 'datetime', nullable: true }) - verifiedAt: Date + verifiedAt: Date | null @Column({ name: 'last_error_at', type: 'datetime', nullable: true }) - lastErrorAt: Date + lastErrorAt: Date | null @CreateDateColumn({ name: 'created_at', From e7062f2a55fdce61be0870ad92d5be78f2d306bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 9 Mar 2023 20:41:40 +0100 Subject: [PATCH 09/17] tests --- .../resolver/CommunityResolver.test.ts | 77 +++++++++++-------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index c48ab0f25..aae64a75a 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -1,24 +1,23 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ -import { createTestClient } from 'apollo-server-testing' -import createServer from '@/server/createServer' -import { resetEntity } from '@test/helpers' import { Community as DbCommunity } from '@entity/Community' import { Community } from '../model/Community' +import { testEnvironment } from '@test/helpers' -jest.mock('@/config') +// jest.mock('@/config') let query: any // to do: We need a setup for the tests that closes the connection let con: any +let testEnv: any beforeAll(async () => { - const server = await createServer({}) - con = server.con - query = createTestClient(server.apollo).query - resetEntity(DbCommunity) + testEnv = await testEnvironment() + query = testEnv.query + con = testEnv.con + await DbCommunity.clear() }) afterAll(async () => { @@ -45,73 +44,85 @@ describe('CommunityResolver', () => { describe('getCommunities', () => { describe('with empty list', () => { it('returns no community entry', async () => { - const result: Community[] = await query({ query: getCommunities }) - expect(result.length).decimalEqual(0) + // const result: Community[] = await query({ query: getCommunities }) + // expect(result.length).toEqual(0) + await expect(query({ query: getCommunities })).resolves.toMatchObject({ + data: { + getCommunities: [], + }, + }) }) }) describe('only home-communities entries', () => { - beforeEach(() => { - const homeCom1 = DbCommunity.create() + let homeCom1: DbCommunity + let homeCom2: DbCommunity + let homeCom3: DbCommunity + + beforeEach(async () => { + jest.clearAllMocks() + await DbCommunity.clear() + + homeCom1 = DbCommunity.create() homeCom1.foreign = false homeCom1.publicKey = Buffer.from('publicKey-HomeCommunity') homeCom1.apiVersion = '1_0' - homeCom1.endPoint = 'https://localhost' + homeCom1.endPoint = 'http://localhost' homeCom1.createdAt = new Date() - DbCommunity.save(homeCom1) + await DbCommunity.insert(homeCom1) - const homeCom2 = DbCommunity.create() + homeCom2 = DbCommunity.create() homeCom2.foreign = false homeCom2.publicKey = Buffer.from('publicKey-HomeCommunity') homeCom2.apiVersion = '1_1' - homeCom2.endPoint = 'https://localhost' + homeCom2.endPoint = 'http://localhost' homeCom2.createdAt = new Date() - DbCommunity.save(homeCom2) + await DbCommunity.insert(homeCom2) - const homeCom3 = DbCommunity.create() + homeCom3 = DbCommunity.create() homeCom3.foreign = false homeCom3.publicKey = Buffer.from('publicKey-HomeCommunity') homeCom3.apiVersion = '2_0' - homeCom3.endPoint = 'https://localhost' + homeCom3.endPoint = 'http://localhost' homeCom3.createdAt = new Date() - DbCommunity.save(homeCom3) + await DbCommunity.insert(homeCom3) }) it('returns three home-community entries', async () => { await expect(query({ query: getCommunities })).resolves.toMatchObject({ data: { - communities: [ + getCommunities: [ { id: 1, - foreign: false, - publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()), - url: 'http://localhost/api/1_0', + foreign: homeCom1.foreign, + publicKey: expect.stringMatching('publicKey-HomeCommunity'), + url: expect.stringMatching('http://localhost/api/1_0'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, - createdAt: expect.any(Date), + createdAt: homeCom1.createdAt.toISOString(), updatedAt: null, }, { id: 2, - foreign: false, - publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()), - url: 'http://localhost/api/1_1', + foreign: homeCom2.foreign, + publicKey: expect.stringMatching('publicKey-HomeCommunity'), + url: expect.stringMatching('http://localhost/api/1_1'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, - createdAt: expect.any(Date), + createdAt: homeCom2.createdAt.toISOString(), updatedAt: null, }, { id: 3, - foreign: false, - publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()), - url: 'http://localhost/api/2_0', + foreign: homeCom3.foreign, + publicKey: expect.stringMatching('publicKey-HomeCommunity'), + url: expect.stringMatching('http://localhost/api/2_0'), lastAnnouncedAt: null, verifiedAt: null, lastErrorAt: null, - createdAt: expect.any(Date), + createdAt: homeCom3.createdAt.toISOString(), updatedAt: null, }, ], From d4099b1aeae26c0724b95e8d2e414e2a0124af11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 9 Mar 2023 21:06:52 +0100 Subject: [PATCH 10/17] add test for home- and foreign communities with order by id asc --- .../resolver/CommunityResolver.test.ts | 116 +++++++++++++++++- .../src/graphql/resolver/CommunityResolver.ts | 2 +- 2 files changed, 112 insertions(+), 6 deletions(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index aae64a75a..dc59e1a13 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -42,6 +42,12 @@ describe('CommunityResolver', () => { ` describe('getCommunities', () => { + let homeCom1: DbCommunity + let homeCom2: DbCommunity + let homeCom3: DbCommunity + let foreignCom1: DbCommunity + let foreignCom2: DbCommunity + let foreignCom3: DbCommunity describe('with empty list', () => { it('returns no community entry', async () => { // const result: Community[] = await query({ query: getCommunities }) @@ -55,13 +61,8 @@ describe('CommunityResolver', () => { }) describe('only home-communities entries', () => { - let homeCom1: DbCommunity - let homeCom2: DbCommunity - let homeCom3: DbCommunity - beforeEach(async () => { jest.clearAllMocks() - await DbCommunity.clear() homeCom1 = DbCommunity.create() homeCom1.foreign = false @@ -130,5 +131,110 @@ describe('CommunityResolver', () => { }) }) }) + + describe('plus foreign-communities entries', () => { + beforeEach(async () => { + jest.clearAllMocks() + + foreignCom1 = DbCommunity.create() + foreignCom1.foreign = true + foreignCom1.publicKey = Buffer.from('publicKey-ForeignCommunity') + foreignCom1.apiVersion = '1_0' + foreignCom1.endPoint = 'http://remotehost' + foreignCom1.createdAt = new Date() + await DbCommunity.insert(foreignCom1) + + foreignCom2 = DbCommunity.create() + foreignCom2.foreign = true + foreignCom2.publicKey = Buffer.from('publicKey-ForeignCommunity') + foreignCom2.apiVersion = '1_1' + foreignCom2.endPoint = 'http://remotehost' + foreignCom2.createdAt = new Date() + await DbCommunity.insert(foreignCom2) + + foreignCom3 = DbCommunity.create() + foreignCom3.foreign = true + foreignCom3.publicKey = Buffer.from('publicKey-ForeignCommunity') + foreignCom3.apiVersion = '1_2' + foreignCom3.endPoint = 'http://remotehost' + foreignCom3.createdAt = new Date() + await DbCommunity.insert(foreignCom3) + }) + + it('returns 3x home and 3x foreign-community entries', async () => { + await expect(query({ query: getCommunities })).resolves.toMatchObject({ + data: { + getCommunities: [ + { + id: 1, + foreign: homeCom1.foreign, + publicKey: expect.stringMatching('publicKey-HomeCommunity'), + url: expect.stringMatching('http://localhost/api/1_0'), + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: homeCom1.createdAt.toISOString(), + updatedAt: null, + }, + { + id: 2, + foreign: homeCom2.foreign, + publicKey: expect.stringMatching('publicKey-HomeCommunity'), + url: expect.stringMatching('http://localhost/api/1_1'), + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: homeCom2.createdAt.toISOString(), + updatedAt: null, + }, + { + id: 3, + foreign: homeCom3.foreign, + publicKey: expect.stringMatching('publicKey-HomeCommunity'), + url: expect.stringMatching('http://localhost/api/2_0'), + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: homeCom3.createdAt.toISOString(), + updatedAt: null, + }, + { + id: 4, + foreign: foreignCom1.foreign, + publicKey: expect.stringMatching('publicKey-ForeignCommunity'), + url: expect.stringMatching('http://remotehost/api/1_0'), + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: foreignCom1.createdAt.toISOString(), + updatedAt: null, + }, + { + id: 5, + foreign: foreignCom2.foreign, + publicKey: expect.stringMatching('publicKey-ForeignCommunity'), + url: expect.stringMatching('http://remotehost/api/1_1'), + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: foreignCom2.createdAt.toISOString(), + updatedAt: null, + }, + { + id: 6, + foreign: foreignCom3.foreign, + publicKey: expect.stringMatching('publicKey-ForeignCommunity'), + url: expect.stringMatching('http://remotehost/api/1_2'), + lastAnnouncedAt: null, + verifiedAt: null, + lastErrorAt: null, + createdAt: foreignCom3.createdAt.toISOString(), + updatedAt: null, + }, + ], + }, + }) + }) + }) }) }) diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 8250170c6..1bb0d3c64 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -11,7 +11,7 @@ export class CommunityResolver { @Query(() => [Community]) async getCommunities(): Promise { const comList: Community[] = [] - const dbCommunities: DbCommunity[] = await DbCommunity.find() + const dbCommunities: DbCommunity[] = await DbCommunity.find({ order: { id: 'ASC' } }) dbCommunities.forEach(async function (dbCom) { const com = new Community(dbCom) comList.push(com) From 534e77858f9af75a6cb41c3bb27b3bad4af31867 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Thu, 9 Mar 2023 21:10:53 +0100 Subject: [PATCH 11/17] linting --- backend/src/graphql/resolver/CommunityResolver.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index dc59e1a13..fb0089250 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -2,7 +2,6 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { Community as DbCommunity } from '@entity/Community' -import { Community } from '../model/Community' import { testEnvironment } from '@test/helpers' // jest.mock('@/config') From e1c239cd08f8c65bfcfd0eec9cdb8d8f8b645f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 15 Mar 2023 01:25:34 +0100 Subject: [PATCH 12/17] rework PR-comments --- backend/src/auth/RIGHTS.ts | 1 - .../resolver/CommunityResolver.test.ts | 20 ++----------------- .../src/graphql/resolver/CommunityResolver.ts | 9 +++------ backend/src/seeds/graphql/queries.ts | 16 +++++++++++++++ 4 files changed, 21 insertions(+), 25 deletions(-) diff --git a/backend/src/auth/RIGHTS.ts b/backend/src/auth/RIGHTS.ts index 22be48e40..7ee60dbe5 100644 --- a/backend/src/auth/RIGHTS.ts +++ b/backend/src/auth/RIGHTS.ts @@ -2,7 +2,6 @@ export enum RIGHTS { LOGIN = 'LOGIN', VERIFY_LOGIN = 'VERIFY_LOGIN', BALANCE = 'BALANCE', - GET_COMMUNITY_INFO = 'GET_COMMUNITY_INFO', COMMUNITIES = 'COMMUNITIES', LIST_GDT_ENTRIES = 'LIST_GDT_ENTRIES', EXIST_PID = 'EXIST_PID', diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index 13a9bb4dc..1e8f6a00f 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -1,14 +1,14 @@ +/* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-call */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +import { getCommunities } from '@/seeds/graphql/queries' import { Community as DbCommunity } from '@entity/Community' import { testEnvironment } from '@test/helpers' -// jest.mock('@/config') - let query: any // to do: We need a setup for the tests that closes the connection @@ -27,22 +27,6 @@ afterAll(async () => { }) describe('CommunityResolver', () => { - const getCommunities = ` - query { - getCommunities { - id - foreign - publicKey - url - lastAnnouncedAt - verifiedAt - lastErrorAt - createdAt - updatedAt - } - } - ` - describe('getCommunities', () => { let homeCom1: DbCommunity let homeCom2: DbCommunity diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 1bb0d3c64..1292fa55f 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -10,12 +10,9 @@ export class CommunityResolver { @Authorized([RIGHTS.COMMUNITIES]) @Query(() => [Community]) async getCommunities(): Promise { - const comList: Community[] = [] - const dbCommunities: DbCommunity[] = await DbCommunity.find({ order: { id: 'ASC' } }) - dbCommunities.forEach(async function (dbCom) { - const com = new Community(dbCom) - comList.push(com) + const dbCommunities: DbCommunity[] = await DbCommunity.find({ + order: { foreign: 'ASC', publicKey: 'ASC', apiVersion: 'ASC' }, }) - return comList + return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom)) } } diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 299a0103d..1d1cea823 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -133,6 +133,22 @@ export const communities = gql` } ` +export const getCommunities = gql` + query { + getCommunities { + id + foreign + publicKey + url + lastAnnouncedAt + verifiedAt + lastErrorAt + createdAt + updatedAt + } + } +` + export const queryTransactionLink = gql` query ($code: String!) { queryTransactionLink(code: $code) { From 0e1e2464301a93d2287980e88074ddfcca20a88f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claus-Peter=20H=C3=BCbner?= Date: Wed, 15 Mar 2023 21:57:53 +0100 Subject: [PATCH 13/17] remove unused Right --- backend/src/auth/INALIENABLE_RIGHTS.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/auth/INALIENABLE_RIGHTS.ts b/backend/src/auth/INALIENABLE_RIGHTS.ts index 348cd5b20..adca3640f 100644 --- a/backend/src/auth/INALIENABLE_RIGHTS.ts +++ b/backend/src/auth/INALIENABLE_RIGHTS.ts @@ -2,7 +2,6 @@ import { RIGHTS } from './RIGHTS' export const INALIENABLE_RIGHTS = [ RIGHTS.LOGIN, - RIGHTS.GET_COMMUNITY_INFO, RIGHTS.COMMUNITIES, RIGHTS.CREATE_USER, RIGHTS.SEND_RESET_PASSWORD_EMAIL, From 8ffe58fc5e88ef888ff5c7d4581ee2de1c534611 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 21 Mar 2023 09:16:02 +0100 Subject: [PATCH 14/17] move nginx test workflow toseparate file --- .github/workflows/test-nginx.yml | 13 +++++++++++++ .github/workflows/test.yml | 25 ------------------------- 2 files changed, 13 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/test-nginx.yml diff --git a/.github/workflows/test-nginx.yml b/.github/workflows/test-nginx.yml new file mode 100644 index 000000000..1b6c91bdf --- /dev/null +++ b/.github/workflows/test-nginx.yml @@ -0,0 +1,13 @@ +name: + +on: push + +jobs: + build_test_nginx: + name: Docker Build Test - Nginx + runs-on: ubuntu-latest + steps: + uses: actions/checkout@v3 + + - name: nginx | Build 'test' image + run: docker build -t "gradido/nginx:test" nginx/ \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1e5f0db02..0fcedb4ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,31 +81,6 @@ jobs: name: docker-mariadb-test path: /tmp/mariadb.tar - ############################################################################## - # JOB: DOCKER BUILD TEST NGINX ############################################### - ############################################################################## - build_test_nginx: - name: Docker Build Test - Nginx - runs-on: ubuntu-latest - steps: - ########################################################################## - # CHECKOUT CODE ########################################################## - ########################################################################## - - name: Checkout code - uses: actions/checkout@v3 - ########################################################################## - # BUILD NGINX DOCKER IMAGE ############################################### - ########################################################################## - - name: nginx | Build `test` image - run: | - docker build -t "gradido/nginx:test" nginx/ - docker save "gradido/nginx:test" > /tmp/nginx.tar - - name: Upload Artifact - uses: actions/upload-artifact@v3 - with: - name: docker-nginx-test - path: /tmp/nginx.tar - ############################################################################## # JOB: LINT BACKEND ########################################################## ############################################################################## From 20c1261c2c67b8e2bbc7e3ae0ffe44f4522ead5b Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 21 Mar 2023 09:29:39 +0100 Subject: [PATCH 15/17] add file filter check to nginx workflow --- .github/file-filters.yml | 5 ++++- .github/workflows/test-nginx.yml | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/file-filters.yml b/.github/file-filters.yml index 2ae1bf9b4..80b7482d9 100644 --- a/.github/file-filters.yml +++ b/.github/file-filters.yml @@ -40,4 +40,7 @@ federation: &federation - 'federation/**/*' frontend: &frontend - - 'frontend/**/*' \ No newline at end of file + - 'frontend/**/*' + +nginx: &nginx + - 'nginx/**/*' \ No newline at end of file diff --git a/.github/workflows/test-nginx.yml b/.github/workflows/test-nginx.yml index 1b6c91bdf..3409a3042 100644 --- a/.github/workflows/test-nginx.yml +++ b/.github/workflows/test-nginx.yml @@ -3,8 +3,26 @@ name: on: push jobs: + files-changed: + name: Detect File Changes - Frontend + runs-on: ubuntu-latest + outputs: + nginx: ${{ steps.changes.outputs.nginx }} + steps: + - uses: actions/checkout@v3.3.0 + + - name: Check for nginx file changes + uses: dorny/paths-filter@v2.11.1 + id: changes + with: + token: ${{ github.token }} + filters: .github/file-filters.yml + list-files: shell + build_test_nginx: name: Docker Build Test - Nginx + if: needs.files-changed.outputs.nginx == 'true' + needs: files-changed runs-on: ubuntu-latest steps: uses: actions/checkout@v3 From a15953468f677cc825509bcd157edc35ad29e274 Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 21 Mar 2023 10:58:37 +0100 Subject: [PATCH 16/17] add name to nginx workflow file --- .github/workflows/test-nginx.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-nginx.yml b/.github/workflows/test-nginx.yml index 3409a3042..5d39c493e 100644 --- a/.github/workflows/test-nginx.yml +++ b/.github/workflows/test-nginx.yml @@ -1,4 +1,4 @@ -name: +name: Gradido Nginx Test CI on: push From 521bb3b2009ac8ebc6bc11e821d4cac2849bcf5f Mon Sep 17 00:00:00 2001 From: mahula Date: Tue, 21 Mar 2023 12:21:52 +0100 Subject: [PATCH 17/17] fix nginx workflow file --- .github/workflows/test-nginx.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-nginx.yml b/.github/workflows/test-nginx.yml index 5d39c493e..146e7a117 100644 --- a/.github/workflows/test-nginx.yml +++ b/.github/workflows/test-nginx.yml @@ -4,7 +4,7 @@ on: push jobs: files-changed: - name: Detect File Changes - Frontend + name: Detect File Changes - Nginx runs-on: ubuntu-latest outputs: nginx: ${{ steps.changes.outputs.nginx }} @@ -25,7 +25,8 @@ jobs: needs: files-changed runs-on: ubuntu-latest steps: + - name: Checkout code uses: actions/checkout@v3 - name: nginx | Build 'test' image - run: docker build -t "gradido/nginx:test" nginx/ \ No newline at end of file + run: docker build -t "gradido/nginx:test" nginx/