mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
Merge pull request #1622 from gradido/seed-transaction-links
feat: Seed Transaction Links
This commit is contained in:
commit
153b39c65d
@ -29,7 +29,7 @@ export const transactionLinkCode = (date: Date): string => {
|
|||||||
|
|
||||||
const CODE_VALID_DAYS_DURATION = 14
|
const CODE_VALID_DAYS_DURATION = 14
|
||||||
|
|
||||||
const transactionLinkExpireDate = (date: Date): Date => {
|
export const transactionLinkExpireDate = (date: Date): Date => {
|
||||||
const validUntil = new Date(date)
|
const validUntil = new Date(date)
|
||||||
return new Date(validUntil.setDate(date.getDate() + CODE_VALID_DAYS_DURATION))
|
return new Date(validUntil.setDate(date.getDate() + CODE_VALID_DAYS_DURATION))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,9 @@ describe('UserResolver', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('returns success', () => {
|
it('returns success', () => {
|
||||||
expect(result).toEqual(expect.objectContaining({ data: { createUser: 'success' } }))
|
expect(result).toEqual(
|
||||||
|
expect.objectContaining({ data: { createUser: { id: expect.any(Number) } } }),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('valid input data', () => {
|
describe('valid input data', () => {
|
||||||
@ -331,6 +333,7 @@ describe('UserResolver', () => {
|
|||||||
email: 'bibi@bloxberg.de',
|
email: 'bibi@bloxberg.de',
|
||||||
firstName: 'Bibi',
|
firstName: 'Bibi',
|
||||||
hasElopage: false,
|
hasElopage: false,
|
||||||
|
id: expect.any(Number),
|
||||||
isAdmin: false,
|
isAdmin: false,
|
||||||
klickTipp: {
|
klickTipp: {
|
||||||
newsletterState: false,
|
newsletterState: false,
|
||||||
|
|||||||
@ -313,10 +313,10 @@ export class UserResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Authorized([RIGHTS.CREATE_USER])
|
@Authorized([RIGHTS.CREATE_USER])
|
||||||
@Mutation(() => String)
|
@Mutation(() => User)
|
||||||
async createUser(
|
async createUser(
|
||||||
@Args() { email, firstName, lastName, language, publisherId }: CreateUserArgs,
|
@Args() { email, firstName, lastName, language, publisherId }: CreateUserArgs,
|
||||||
): Promise<string> {
|
): Promise<User> {
|
||||||
// TODO: wrong default value (should be null), how does graphql work here? Is it an required field?
|
// TODO: wrong default value (should be null), how does graphql work here? Is it an required field?
|
||||||
// default int publisher_id = 0;
|
// default int publisher_id = 0;
|
||||||
|
|
||||||
@ -396,7 +396,7 @@ export class UserResolver {
|
|||||||
} finally {
|
} finally {
|
||||||
await queryRunner.release()
|
await queryRunner.release()
|
||||||
}
|
}
|
||||||
return 'success'
|
return new User(dbUser)
|
||||||
}
|
}
|
||||||
|
|
||||||
// THis is used by the admin only - should we move it to the admin resolver?
|
// THis is used by the admin only - should we move it to the admin resolver?
|
||||||
|
|||||||
@ -15,14 +15,14 @@ export const creationFactory = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const { mutate, query } = client
|
const { mutate, query } = client
|
||||||
|
|
||||||
// login as Peter Lustig (admin)
|
// login as Peter Lustig (admin) and get his user ID
|
||||||
await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
const {
|
||||||
|
data: {
|
||||||
|
login: { id },
|
||||||
|
},
|
||||||
|
} = await query({ query: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
||||||
|
|
||||||
// get Peter Lustig's user id
|
await mutate({ mutation: createPendingCreation, variables: { ...creation, moderator: id } })
|
||||||
const peterLustig = await User.findOneOrFail({ where: { email: 'peter@lustig.de' } })
|
|
||||||
const variables = { ...creation, moderator: peterLustig.id }
|
|
||||||
|
|
||||||
await mutate({ mutation: createPendingCreation, variables })
|
|
||||||
|
|
||||||
// get User
|
// get User
|
||||||
const user = await User.findOneOrFail({ where: { email: creation.email } })
|
const user = await User.findOneOrFail({ where: { email: creation.email } })
|
||||||
|
|||||||
43
backend/src/seeds/factory/transactionLink.ts
Normal file
43
backend/src/seeds/factory/transactionLink.ts
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||||
|
import { createTransactionLink } from '@/seeds/graphql/mutations'
|
||||||
|
import { login } from '@/seeds/graphql/queries'
|
||||||
|
import { TransactionLinkInterface } from '@/seeds/transactionLink/TransactionLinkInterface'
|
||||||
|
import { transactionLinkExpireDate } from '@/graphql/resolver/TransactionLinkResolver'
|
||||||
|
import { TransactionLink } from '@entity/TransactionLink'
|
||||||
|
|
||||||
|
export const transactionLinkFactory = async (
|
||||||
|
client: ApolloServerTestClient,
|
||||||
|
transactionLink: TransactionLinkInterface,
|
||||||
|
): Promise<void> => {
|
||||||
|
const { mutate, query } = client
|
||||||
|
|
||||||
|
// login
|
||||||
|
await query({ query: login, variables: { email: transactionLink.email, password: 'Aa12345_' } })
|
||||||
|
|
||||||
|
const variables = {
|
||||||
|
amount: transactionLink.amount,
|
||||||
|
memo: transactionLink.memo,
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the transaction links's id
|
||||||
|
const {
|
||||||
|
data: {
|
||||||
|
createTransactionLink: { id },
|
||||||
|
},
|
||||||
|
} = await mutate({ mutation: createTransactionLink, variables })
|
||||||
|
|
||||||
|
if (transactionLink.createdAt || transactionLink.deletedAt) {
|
||||||
|
const dbTransactionLink = await TransactionLink.findOneOrFail({ id })
|
||||||
|
|
||||||
|
if (transactionLink.createdAt) {
|
||||||
|
dbTransactionLink.createdAt = transactionLink.createdAt
|
||||||
|
dbTransactionLink.validUntil = transactionLinkExpireDate(transactionLink.createdAt)
|
||||||
|
await dbTransactionLink.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (transactionLink.deletedAt) {
|
||||||
|
dbTransactionLink.deletedAt = new Date()
|
||||||
|
await dbTransactionLink.save()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -11,19 +11,23 @@ export const userFactory = async (
|
|||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const { mutate } = client
|
const { mutate } = client
|
||||||
|
|
||||||
await mutate({ mutation: createUser, variables: user })
|
const {
|
||||||
let dbUser = await User.findOneOrFail({ where: { email: user.email } })
|
data: {
|
||||||
|
createUser: { id },
|
||||||
|
},
|
||||||
|
} = await mutate({ mutation: createUser, variables: user })
|
||||||
|
|
||||||
if (user.emailChecked) {
|
if (user.emailChecked) {
|
||||||
const optin = await LoginEmailOptIn.findOneOrFail({ where: { userId: dbUser.id } })
|
const optin = await LoginEmailOptIn.findOneOrFail({ userId: id })
|
||||||
await mutate({
|
await mutate({
|
||||||
mutation: setPassword,
|
mutation: setPassword,
|
||||||
variables: { password: 'Aa12345_', code: optin.verificationCode },
|
variables: { password: 'Aa12345_', code: optin.verificationCode },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// refetch data
|
if (user.createdAt || user.deletedAt || user.isAdmin) {
|
||||||
dbUser = await User.findOneOrFail({ where: { email: user.email } })
|
// get user from database
|
||||||
|
const dbUser = await User.findOneOrFail({ id })
|
||||||
|
|
||||||
if (user.createdAt || user.deletedAt) {
|
if (user.createdAt || user.deletedAt) {
|
||||||
if (user.createdAt) dbUser.createdAt = user.createdAt
|
if (user.createdAt) dbUser.createdAt = user.createdAt
|
||||||
@ -43,4 +47,5 @@ export const userFactory = async (
|
|||||||
admin.modified = dbUser.createdAt
|
admin.modified = dbUser.createdAt
|
||||||
await admin.save()
|
await admin.save()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,9 @@ export const createUser = gql`
|
|||||||
lastName: $lastName
|
lastName: $lastName
|
||||||
language: $language
|
language: $language
|
||||||
publisherId: $publisherId
|
publisherId: $publisherId
|
||||||
)
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
@ -65,6 +67,7 @@ export const sendCoins = gql`
|
|||||||
export const createTransactionLink = gql`
|
export const createTransactionLink = gql`
|
||||||
mutation ($amount: Decimal!, $memo: String!) {
|
mutation ($amount: Decimal!, $memo: String!) {
|
||||||
createTransactionLink(amount: $amount, memo: $memo) {
|
createTransactionLink(amount: $amount, memo: $memo) {
|
||||||
|
id
|
||||||
code
|
code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import gql from 'graphql-tag'
|
|||||||
export const login = gql`
|
export const login = gql`
|
||||||
query ($email: String!, $password: String!, $publisherId: Int) {
|
query ($email: String!, $password: String!, $publisherId: Int) {
|
||||||
login(email: $email, password: $password, publisherId: $publisherId) {
|
login(email: $email, password: $password, publisherId: $publisherId) {
|
||||||
|
id
|
||||||
email
|
email
|
||||||
firstName
|
firstName
|
||||||
lastName
|
lastName
|
||||||
|
|||||||
@ -8,8 +8,10 @@ import { name, internet, random } from 'faker'
|
|||||||
|
|
||||||
import { users } from './users/index'
|
import { users } from './users/index'
|
||||||
import { creations } from './creation/index'
|
import { creations } from './creation/index'
|
||||||
|
import { transactionLinks } from './transactionLink/index'
|
||||||
import { userFactory } from './factory/user'
|
import { userFactory } from './factory/user'
|
||||||
import { creationFactory } from './factory/creation'
|
import { creationFactory } from './factory/creation'
|
||||||
|
import { transactionLinkFactory } from './factory/transactionLink'
|
||||||
import { entities } from '@entity/index'
|
import { entities } from '@entity/index'
|
||||||
|
|
||||||
const context = {
|
const context = {
|
||||||
@ -64,6 +66,11 @@ const run = async () => {
|
|||||||
await creationFactory(seedClient, creations[i])
|
await creationFactory(seedClient, creations[i])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create Transaction Links
|
||||||
|
for (let i = 0; i < transactionLinks.length; i++) {
|
||||||
|
await transactionLinkFactory(seedClient, transactionLinks[i])
|
||||||
|
}
|
||||||
|
|
||||||
await con.close()
|
await con.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
export interface TransactionLinkInterface {
|
||||||
|
email: string
|
||||||
|
amount: number
|
||||||
|
memo: string
|
||||||
|
createdAt?: Date
|
||||||
|
deletedAt?: boolean
|
||||||
|
}
|
||||||
52
backend/src/seeds/transactionLink/index.ts
Normal file
52
backend/src/seeds/transactionLink/index.ts
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
import { TransactionLinkInterface } from './TransactionLinkInterface'
|
||||||
|
|
||||||
|
export const transactionLinks: TransactionLinkInterface[] = [
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: 'Leider wollte niemand meine Gradidos zum Neujahr haben :(',
|
||||||
|
createdAt: new Date(2022, 0, 1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: `Kein Trick, keine Zauberrei,
|
||||||
|
bei Gradidio sei dabei!`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: `Kein Trick, keine Zauberrei,
|
||||||
|
bei Gradidio sei dabei!`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: `Kein Trick, keine Zauberrei,
|
||||||
|
bei Gradidio sei dabei!`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: `Kein Trick, keine Zauberrei,
|
||||||
|
bei Gradidio sei dabei!`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: `Kein Trick, keine Zauberrei,
|
||||||
|
bei Gradidio sei dabei!`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: `Kein Trick, keine Zauberrei,
|
||||||
|
bei Gradidio sei dabei!`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
email: 'bibi@bloxberg.de',
|
||||||
|
amount: 19.99,
|
||||||
|
memo: 'Da habe ich mich wohl etwas übernommen.',
|
||||||
|
deletedAt: true,
|
||||||
|
},
|
||||||
|
]
|
||||||
@ -52,7 +52,9 @@ export const createUser = gql`
|
|||||||
lastName: $lastName
|
lastName: $lastName
|
||||||
language: $language
|
language: $language
|
||||||
publisherId: $publisherId
|
publisherId: $publisherId
|
||||||
)
|
) {
|
||||||
|
id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user