diff --git a/backend/src/graphql/resolver/UserResolver.test.ts b/backend/src/graphql/resolver/UserResolver.test.ts index 61625a8ae..1e1e266fb 100644 --- a/backend/src/graphql/resolver/UserResolver.test.ts +++ b/backend/src/graphql/resolver/UserResolver.test.ts @@ -2,7 +2,7 @@ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ import { testEnvironment, headerPushMock, resetToken, cleanDB } from '@test/helpers' -import { createUserFactory } from '@/seeds/factory/user' +import { userFactory } from '@/seeds/factory/user' import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg' import { createUser, setPassword } from '@/seeds/graphql/mutations' import { login, logout } from '@/seeds/graphql/queries' @@ -11,6 +11,7 @@ import { LoginEmailOptIn } from '@entity/LoginEmailOptIn' import { User } from '@entity/User' import CONFIG from '@/config' import { sendAccountActivationEmail } from '@/mailer/sendAccountActivationEmail' + // import { klicktippSignIn } from '@/apis/KlicktippController' jest.mock('@/mailer/sendAccountActivationEmail', () => { @@ -30,9 +31,10 @@ jest.mock('@/apis/KlicktippController', () => { */ let mutate: any, query: any, con: any +let testEnv: any beforeAll(async () => { - const testEnv = await testEnvironment() + testEnv = await testEnvironment() mutate = testEnv.mutate query = testEnv.query con = testEnv.con @@ -312,7 +314,7 @@ describe('UserResolver', () => { describe('user is in database and correct login data', () => { beforeAll(async () => { - await createUserFactory(mutate, bibiBloxberg) + await userFactory(testEnv, bibiBloxberg) result = await query({ query: login, variables }) }) @@ -349,7 +351,7 @@ describe('UserResolver', () => { describe('user is in database and wrong password', () => { beforeAll(async () => { - await createUserFactory(mutate, bibiBloxberg) + await userFactory(testEnv, bibiBloxberg) }) afterAll(async () => { @@ -387,7 +389,7 @@ describe('UserResolver', () => { } beforeAll(async () => { - await createUserFactory(mutate, bibiBloxberg) + await userFactory(testEnv, bibiBloxberg) await query({ query: login, variables }) }) diff --git a/backend/src/seeds/creation/CreationInterface.ts b/backend/src/seeds/creation/CreationInterface.ts new file mode 100644 index 000000000..8723f441d --- /dev/null +++ b/backend/src/seeds/creation/CreationInterface.ts @@ -0,0 +1,7 @@ +export interface CreationInterface { + email: string + amount: number + memo: string + creationDate: string + confirmed?: boolean +} diff --git a/backend/src/seeds/creation/index.ts b/backend/src/seeds/creation/index.ts new file mode 100644 index 000000000..7396a7ec8 --- /dev/null +++ b/backend/src/seeds/creation/index.ts @@ -0,0 +1,29 @@ +import { CreationInterface } from './CreationInterface' + +const lastMonth = (date: Date): string => { + return new Date(date.getFullYear(), date.getMonth() - 1, 1).toISOString() +} + +export const creations: CreationInterface[] = [ + { + email: 'bibi@bloxberg.de', + amount: 1000, + memo: 'Herzlich Willkommen bei Gradido!', + creationDate: lastMonth(new Date()), + confirmed: true, + }, + { + email: 'bob@baumeister.de', + amount: 1000, + memo: 'Herzlich Willkommen bei Gradido!', + creationDate: lastMonth(new Date()), + confirmed: true, + }, + { + email: 'raeuber@hotzenplotz.de', + amount: 1000, + memo: 'Herzlich Willkommen bei Gradido!', + creationDate: lastMonth(new Date()), + confirmed: true, + }, +] diff --git a/backend/src/seeds/factory/creation.ts b/backend/src/seeds/factory/creation.ts new file mode 100644 index 000000000..980e0b3af --- /dev/null +++ b/backend/src/seeds/factory/creation.ts @@ -0,0 +1,38 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ + +import { createPendingCreation, confirmPendingCreation } from '@/seeds/graphql/mutations' +import { login } from '@/seeds/graphql/queries' +import { CreationInterface } from '@/seeds/creation/CreationInterface' +import { ApolloServerTestClient } from 'apollo-server-testing' +import { User } from '@entity/User' +import { AdminPendingCreation } from '@entity/AdminPendingCreation' +// import CONFIG from '@/config/index' + +export const creationFactory = async ( + client: ApolloServerTestClient, + creation: CreationInterface, +): Promise => { + const { mutate, query } = client + + // login as Peter Lustig (admin) + await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } }) + + // get Peter Lustig's user id + const peterLustig = await User.findOneOrFail({ where: { email: 'peter@lustig.de' } }) + const variables = { ...creation, moderator: peterLustig.id } + + await mutate({ mutation: createPendingCreation, variables }) + + // get User + const user = await User.findOneOrFail({ where: { email: creation.email } }) + + if (creation.confirmed) { + const pendingCreation = await AdminPendingCreation.findOneOrFail({ + where: { userId: user.id }, + order: { created: 'DESC' }, + }) + + await mutate({ mutation: confirmPendingCreation, variables: { id: pendingCreation.id } }) + } +} diff --git a/backend/src/seeds/factory/user.ts b/backend/src/seeds/factory/user.ts index 89bff6852..6d81f26a6 100644 --- a/backend/src/seeds/factory/user.ts +++ b/backend/src/seeds/factory/user.ts @@ -1,13 +1,16 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ - import { createUser, setPassword } from '@/seeds/graphql/mutations' import { User } from '@entity/User' import { LoginEmailOptIn } from '@entity/LoginEmailOptIn' import { ServerUser } from '@entity/ServerUser' import { UserInterface } from '@/seeds/users/UserInterface' +import { ApolloServerTestClient } from 'apollo-server-testing' + +export const userFactory = async ( + client: ApolloServerTestClient, + user: UserInterface, +): Promise => { + const { mutate } = client -export const createUserFactory = async (mutate: any, user: UserInterface): Promise => { await mutate({ mutation: createUser, variables: user }) let dbUser = await User.findOneOrFail({ where: { email: user.email } }) diff --git a/backend/src/seeds/graphql/mutations.ts b/backend/src/seeds/graphql/mutations.ts index 8f425cdec..32232e410 100644 --- a/backend/src/seeds/graphql/mutations.ts +++ b/backend/src/seeds/graphql/mutations.ts @@ -69,3 +69,29 @@ export const createTransactionLink = gql` } } ` + +// from admin interface + +export const createPendingCreation = gql` + mutation ( + $email: String! + $amount: Float! + $memo: String! + $creationDate: String! + $moderator: Int! + ) { + createPendingCreation( + email: $email + amount: $amount + memo: $memo + creationDate: $creationDate + moderator: $moderator + ) + } +` + +export const confirmPendingCreation = gql` + mutation ($id: Float!) { + confirmPendingCreation(id: $id) + } +` diff --git a/backend/src/seeds/index.ts b/backend/src/seeds/index.ts index b68bcbdd9..3943a63e0 100644 --- a/backend/src/seeds/index.ts +++ b/backend/src/seeds/index.ts @@ -7,14 +7,16 @@ import { createTestClient } from 'apollo-server-testing' import { name, internet, random } from 'faker' import { users } from './users/index' -import { createUserFactory } from './factory/user' +import { creations } from './creation/index' +import { userFactory } from './factory/user' +import { creationFactory } from './factory/creation' import { entities } from '@entity/index' const context = { token: '', setHeaders: { - push: (value: string): void => { - context.token = value + push: (value: { key: string; value: string }): void => { + context.token = value.value }, // eslint-disable-next-line @typescript-eslint/no-empty-function forEach: (): void => {}, @@ -38,19 +40,18 @@ const resetEntity = async (entity: any) => { const run = async () => { const server = await createServer(context) - const testClient = createTestClient(server.apollo) - const { mutate } = testClient + const seedClient = createTestClient(server.apollo) const { con } = server await cleanDB() // seed the standard users for (let i = 0; i < users.length; i++) { - await createUserFactory(mutate, users[i]) + await userFactory(seedClient, users[i]) } // seed 100 random users for (let i = 0; i < 100; i++) { - await createUserFactory(mutate, { + await userFactory(seedClient, { firstName: name.firstName(), lastName: name.lastName(), email: internet.email(), @@ -58,6 +59,11 @@ const run = async () => { }) } + // create GDD + for (let i = 0; i < creations.length; i++) { + await creationFactory(seedClient, creations[i]) + } + await con.close() }