From e5e22c394d443857b9a9ae922870222e380599a2 Mon Sep 17 00:00:00 2001 From: einhornimmond Date: Tue, 20 Feb 2024 13:22:32 +0100 Subject: [PATCH] update test --- .../resolver/CommunityResolver.test.ts | 28 +++++++++++++++++-- .../src/graphql/resolver/CommunityResolver.ts | 2 +- backend/src/seeds/graphql/queries.ts | 6 ++-- dlt-connector/src/client/BackendClient.ts | 2 +- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/backend/src/graphql/resolver/CommunityResolver.test.ts b/backend/src/graphql/resolver/CommunityResolver.test.ts index c9c76e306..5c35a8570 100644 --- a/backend/src/graphql/resolver/CommunityResolver.test.ts +++ b/backend/src/graphql/resolver/CommunityResolver.test.ts @@ -17,7 +17,7 @@ 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, getCommunityQuery } from '@/seeds/graphql/queries' import { peterLustig } from '@/seeds/users/peter-lustig' import { getCommunity } from './util/communities' @@ -487,10 +487,10 @@ describe('CommunityResolver', () => { await DbCommunity.insert(foreignCom2) }) - it('finds the home-community', async () => { + it('finds the home-community by uuid', async () => { await expect( query({ - query: getCommunityByUuidQuery, + query: getCommunityQuery, variables: { communityIdentifier: homeCom?.communityUuid }, }), ).resolves.toMatchObject({ @@ -509,6 +509,28 @@ describe('CommunityResolver', () => { }) }) + it('finds the home-community by foreign', async () => { + await expect( + query({ + query: getCommunityQuery, + variables: { foreign: false }, + }), + ).resolves.toMatchObject({ + data: { + community: { + id: homeCom?.id, + foreign: homeCom?.foreign, + name: homeCom?.name, + description: homeCom?.description, + url: homeCom?.url, + creationDate: homeCom?.creationDate?.toISOString(), + uuid: homeCom?.communityUuid, + authenticatedAt: homeCom?.authenticatedAt, + }, + }, + }) + }) + it('updates the home-community gmsApiKey', async () => { await expect( mutate({ diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 3162a625e..75ac4e8bc 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -42,7 +42,7 @@ export class CommunityResolver { return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom)) } - @Authorized([RIGHTS.COMMUNITIES]) + @Authorized([RIGHTS.COMMUNITY_BY_IDENTIFIER]) @Query(() => Community) async community(@Args() communityArgs: CommunityArgs): Promise { const community = await getCommunity(communityArgs) diff --git a/backend/src/seeds/graphql/queries.ts b/backend/src/seeds/graphql/queries.ts index 9e908d202..49dec61b5 100644 --- a/backend/src/seeds/graphql/queries.ts +++ b/backend/src/seeds/graphql/queries.ts @@ -134,9 +134,9 @@ export const communitiesQuery = gql` } ` -export const getCommunityByUuidQuery = gql` - query ($communityIdentifier: String!) { - community(communityIdentifier: $communityIdentifier) { +export const getCommunityQuery = gql` + query ($communityIdentifier: String, $foreign: Boolean) { + community(communityIdentifier: $communityIdentifier, foreign: $foreign) { id foreign name diff --git a/dlt-connector/src/client/BackendClient.ts b/dlt-connector/src/client/BackendClient.ts index 0a460d116..80bcaa132 100644 --- a/dlt-connector/src/client/BackendClient.ts +++ b/dlt-connector/src/client/BackendClient.ts @@ -1,12 +1,12 @@ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ import { gql, GraphQLClient } from 'graphql-request' +import { SignJWT } from 'jose' import { CONFIG } from '@/config' import { CommunityDraft } from '@/graphql/input/CommunityDraft' import { logger } from '@/logging/logger' import { LogError } from '@/server/LogError' -import { SignJWT } from 'jose' const communityByForeign = gql` query ($foreign: Boolean) {