diff --git a/backend/src/graphql/resolver/EmailOptinCodes.test.ts b/backend/src/graphql/resolver/EmailOptinCodes.test.ts index 640faad17..731d4a395 100644 --- a/backend/src/graphql/resolver/EmailOptinCodes.test.ts +++ b/backend/src/graphql/resolver/EmailOptinCodes.test.ts @@ -11,6 +11,8 @@ import { CONFIG } from '@/config' import { createUser, setPassword, forgotPassword } from '@/seeds/graphql/mutations' import { queryOptIn } from '@/seeds/graphql/queries' +import { createHomeCommunity } from './util/communities' + let mutate: ApolloServerTestClient['mutate'], query: ApolloServerTestClient['query'], con: Connection @@ -46,6 +48,7 @@ describe('EmailOptinCodes', () => { lastName: 'Lustig', language: 'de', } + await createHomeCommunity() const { data: { createUser: user }, } = await mutate({ mutation: createUser, variables }) diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index a9c50553e..fd9a85790 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -67,6 +67,8 @@ import { stephenHawking } from '@/seeds/users/stephen-hawking' import { printTimeDuration } from '@/util/time' import { objectValuesToArray } from '@/util/utilities' +import { createHomeCommunity } from './util/communities' + jest.mock('@/emails/sendEmailVariants', () => { const originalModule = jest.requireActual('@/emails/sendEmailVariants') return { @@ -125,9 +127,11 @@ describe('UserResolver', () => { let result: any let emailVerificationCode: string let user: User[] + let homeCom: DbCommunity beforeAll(async () => { jest.clearAllMocks() + homeCom = await createHomeCommunity() result = await mutate({ mutation: createUser, variables }) }) @@ -172,7 +176,7 @@ describe('UserResolver', () => { referrerId: null, contributionLinkId: null, passwordEncryptionType: PasswordEncryptionType.NO_PASSWORD, - communityUuid: null, + communityUuid: homeCom.communityUuid, foreign: false, }, ]) @@ -542,6 +546,7 @@ describe('UserResolver', () => { let newUser: User beforeAll(async () => { + await createHomeCommunity() await mutate({ mutation: createUser, variables: createUserVariables }) const emailContact = await UserContact.findOneOrFail({ where: { email: createUserVariables.email }, @@ -586,6 +591,7 @@ describe('UserResolver', () => { describe('no valid password', () => { beforeAll(async () => { + await createHomeCommunity() await mutate({ mutation: createUser, variables: createUserVariables }) const emailContact = await UserContact.findOneOrFail({ where: { email: createUserVariables.email }, diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 45ccd720e..1f21abbb9 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -275,6 +275,10 @@ export class UserResolver { { id: 0 } as DbUser, ) let dbUser = new DbUser() + const homeCom = await getHomeCommunity() + if (homeCom.communityUuid) { + dbUser.communityUuid = homeCom.communityUuid + } dbUser.gradidoID = gradidoID dbUser.firstName = firstName dbUser.lastName = lastName diff --git a/backend/src/graphql/resolver/util/communities.ts b/backend/src/graphql/resolver/util/communities.ts index 0c0023a19..9a271066d 100644 --- a/backend/src/graphql/resolver/util/communities.ts +++ b/backend/src/graphql/resolver/util/communities.ts @@ -63,3 +63,23 @@ export async function getCommunity(communityUuid: string): Promise { + let homeCom: DbCommunity + try { + return await getHomeCommunity() + } catch (err) { + homeCom = DbCommunity.create() + homeCom.foreign = false + homeCom.url = 'http://localhost/api' + homeCom.publicKey = Buffer.from('publicKey-HomeCommunity') + homeCom.privateKey = Buffer.from('privateKey-HomeCommunity') + homeCom.communityUuid = 'HomeCom-UUID' + homeCom.authenticatedAt = new Date() + homeCom.name = 'HomeCommunity-name' + homeCom.description = 'HomeCommunity-description' + homeCom.creationDate = new Date() + await DbCommunity.insert(homeCom) + return homeCom + } +} diff --git a/backend/src/seeds/factory/user.ts b/backend/src/seeds/factory/user.ts index 65b0ff3bb..321e9db17 100644 --- a/backend/src/seeds/factory/user.ts +++ b/backend/src/seeds/factory/user.ts @@ -5,7 +5,7 @@ import { ApolloServerTestClient } from 'apollo-server-testing' import { RoleNames } from '@enum/RoleNames' -import { getHomeCommunity } from '@/graphql/resolver/util/communities' +import { createHomeCommunity, getHomeCommunity } from '@/graphql/resolver/util/communities' import { setUserRole } from '@/graphql/resolver/util/modifyUserRole' import { createUser, setPassword } from '@/seeds/graphql/mutations' import { UserInterface } from '@/seeds/users/UserInterface' @@ -16,6 +16,8 @@ export const userFactory = async ( ): Promise => { const { mutate } = client + await createHomeCommunity() + const { data: { createUser: { id },