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 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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,