mirror of
https://github.com/IT4Change/gradido.git
synced 2026-03-01 12:44:43 +00:00
use new seeding in database from backend
This commit is contained in:
parent
f30cbb80e7
commit
654eec3f85
@ -2139,14 +2139,6 @@ describe('ContributionResolver', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('stores the EMAIL_CONFIRMATION event in the database', async () => {
|
||||
await expect(DbEvent.find()).resolves.toContainEqual(
|
||||
expect.objectContaining({
|
||||
type: EventType.EMAIL_CONFIRMATION,
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
describe('confirm same contribution again', () => {
|
||||
it('throws an error', async () => {
|
||||
jest.clearAllMocks()
|
||||
|
||||
@ -67,7 +67,7 @@ import { printTimeDuration } from '@/util/time'
|
||||
import { objectValuesToArray } from 'core'
|
||||
|
||||
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
|
||||
import { getLogger } from 'config-schema/test/testSetup'
|
||||
import { clearLogs, getLogger, printLogs } from 'config-schema/test/testSetup'
|
||||
import { Location2Point } from './util/Location2Point'
|
||||
|
||||
jest.mock('@/apis/humhub/HumHubClient')
|
||||
@ -738,7 +738,7 @@ describe('UserResolver', () => {
|
||||
hasElopage: false,
|
||||
hideAmountGDD: false,
|
||||
hideAmountGDT: false,
|
||||
humhubAllowed: true,
|
||||
humhubAllowed: false,
|
||||
humhubPublishName: 'PUBLISH_NAME_ALIAS_OR_INITALS',
|
||||
klickTipp: {
|
||||
newsletterState: false,
|
||||
@ -1610,7 +1610,7 @@ describe('UserResolver', () => {
|
||||
hasElopage: false,
|
||||
hideAmountGDD: false,
|
||||
hideAmountGDT: false,
|
||||
humhubAllowed: true,
|
||||
humhubAllowed: false,
|
||||
humhubPublishName: 'PUBLISH_NAME_ALIAS_OR_INITALS',
|
||||
klickTipp: {
|
||||
newsletterState: false,
|
||||
@ -2256,7 +2256,7 @@ describe('UserResolver', () => {
|
||||
relations: ['user'],
|
||||
})
|
||||
const activationLink = `${
|
||||
CONFIG.EMAIL_LINK_VERIFICATION
|
||||
CONFIG.EMAIL_LINK_SETPASSWORD
|
||||
}${userContact.emailVerificationCode.toString()}`
|
||||
expect(sendAccountActivationEmail).toBeCalledWith({
|
||||
firstName: 'Bibi',
|
||||
|
||||
@ -1,27 +1,19 @@
|
||||
import { Community as DbCommunity } from 'database'
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
|
||||
import { CONFIG } from '@/config'
|
||||
|
||||
|
||||
export async function writeHomeCommunityEntry(): Promise<DbCommunity> {
|
||||
try {
|
||||
// check for existing homeCommunity entry
|
||||
let homeCom = await DbCommunity.findOne({ where: { foreign: false } })
|
||||
if (homeCom) {
|
||||
// simply update the existing entry, but it MUST keep the ID and UUID because of possible relations
|
||||
homeCom.publicKey = Buffer.from('public-key-data-seeding') // keyPair.publicKey
|
||||
// homeCom.privateKey = keyPair.secretKey
|
||||
homeCom.url = 'http://localhost/api/'
|
||||
homeCom.name = CONFIG.COMMUNITY_NAME
|
||||
homeCom.description = CONFIG.COMMUNITY_DESCRIPTION
|
||||
await DbCommunity.save(homeCom)
|
||||
} else {
|
||||
if (!homeCom) {
|
||||
// insert a new homecommunity entry including a new ID and a new but ensured unique UUID
|
||||
homeCom = new DbCommunity()
|
||||
homeCom.foreign = false
|
||||
homeCom.publicKey = Buffer.from('public-key-data-seeding') // keyPair.publicKey
|
||||
// homeCom.privateKey = keyPair.secretKey
|
||||
homeCom.communityUuid = uuidv4() // await newCommunityUuid()
|
||||
homeCom.communityUuid = 'beac216d-73ae-427f-9678-0209af4936ce' // await newCommunityUuid()
|
||||
homeCom.url = 'http://localhost/api/'
|
||||
homeCom.name = CONFIG.COMMUNITY_NAME
|
||||
homeCom.description = CONFIG.COMMUNITY_DESCRIPTION
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
export { ContributionLinkInterface } from 'database'
|
||||
|
||||
/*
|
||||
export interface ContributionLinkInterface {
|
||||
amount: number
|
||||
name: string
|
||||
@ -5,3 +8,4 @@ export interface ContributionLinkInterface {
|
||||
validFrom?: Date
|
||||
validTo?: Date
|
||||
}
|
||||
*/
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import { ContributionLinkInterface } from './ContributionLinkInterface'
|
||||
export { contributionLinks } from 'database'
|
||||
|
||||
/*
|
||||
export const contributionLinks: ContributionLinkInterface[] = [
|
||||
{
|
||||
name: 'Dokumenta 2017',
|
||||
@ -16,3 +17,4 @@ export const contributionLinks: ContributionLinkInterface[] = [
|
||||
validTo: new Date(2022, 8, 25),
|
||||
},
|
||||
]
|
||||
*/
|
||||
@ -1,3 +1,5 @@
|
||||
export { CreationInterface } from 'database'
|
||||
/*
|
||||
export interface CreationInterface {
|
||||
email: string
|
||||
amount: number
|
||||
@ -7,3 +9,4 @@ export interface CreationInterface {
|
||||
// number of months to move the confirmed creation to the past
|
||||
moveCreationDate?: number
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,7 @@
|
||||
|
||||
export { creations } from 'database'
|
||||
|
||||
/*
|
||||
import { nMonthsBefore } from '@/seeds/factory/creation'
|
||||
|
||||
import { CreationInterface } from './CreationInterface'
|
||||
@ -153,3 +157,4 @@ export const creations: CreationInterface[] = [
|
||||
confirmed: true,
|
||||
},
|
||||
]
|
||||
*/
|
||||
@ -1,32 +1,15 @@
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
import {
|
||||
contributionLinkFactory as contributionLinkFactoryDb,
|
||||
ContributionLinkInterface
|
||||
} from 'database'
|
||||
|
||||
import { ContributionLink } from '@model/ContributionLink'
|
||||
|
||||
import { ContributionLinkInterface } from '@/seeds/contributionLink/ContributionLinkInterface'
|
||||
import { createContributionLink, login } from '@/seeds/graphql/mutations'
|
||||
export { ContributionLinkInterface }
|
||||
|
||||
export const contributionLinkFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
export async function contributionLinkFactory (
|
||||
_client: any,
|
||||
contributionLink: ContributionLinkInterface,
|
||||
): Promise<ContributionLink> => {
|
||||
const { mutate } = client
|
||||
|
||||
// login as admin
|
||||
await mutate({
|
||||
mutation: login,
|
||||
variables: { email: 'peter@lustig.de', password: 'Aa12345_' },
|
||||
})
|
||||
const variables = {
|
||||
amount: contributionLink.amount,
|
||||
memo: contributionLink.memo,
|
||||
name: contributionLink.name,
|
||||
cycle: 'ONCE',
|
||||
maxPerCycle: 1,
|
||||
maxAmountPerMonth: 200,
|
||||
validFrom: contributionLink.validFrom ? contributionLink.validFrom.toISOString() : undefined,
|
||||
validTo: contributionLink.validTo ? contributionLink.validTo.toISOString() : undefined,
|
||||
}
|
||||
|
||||
const result = await mutate({ mutation: createContributionLink, variables })
|
||||
return result.data.createContributionLink
|
||||
): Promise<ContributionLink> {
|
||||
return new ContributionLink(await contributionLinkFactoryDb(contributionLink))
|
||||
}
|
||||
|
||||
@ -1,58 +1,15 @@
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
import { Contribution, Transaction } from 'database'
|
||||
import {
|
||||
Contribution,
|
||||
creationFactory as creationFactoryDb,
|
||||
CreationInterface,
|
||||
nMonthsBefore
|
||||
} from 'database'
|
||||
|
||||
import { findUserByEmail } from '@/graphql/resolver/UserResolver'
|
||||
import { CreationInterface } from '@/seeds/creation/CreationInterface'
|
||||
import { confirmContribution, createContribution, login } from '@/seeds/graphql/mutations'
|
||||
|
||||
export const nMonthsBefore = (date: Date, months = 1): string => {
|
||||
return new Date(date.getFullYear(), date.getMonth() - months, 1).toISOString()
|
||||
}
|
||||
export { CreationInterface, nMonthsBefore }
|
||||
|
||||
export const creationFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
_client: any,
|
||||
creation: CreationInterface,
|
||||
): Promise<Contribution> => {
|
||||
const { mutate } = client
|
||||
await mutate({
|
||||
mutation: login,
|
||||
variables: { email: creation.email, password: 'Aa12345_' },
|
||||
})
|
||||
const {
|
||||
data: { createContribution: contribution },
|
||||
} = await mutate({ mutation: createContribution, variables: { ...creation } })
|
||||
|
||||
if (creation.confirmed) {
|
||||
const user = await findUserByEmail(creation.email) // userContact.user
|
||||
|
||||
await mutate({ mutation: login, variables: { email: 'peter@lustig.de', password: 'Aa12345_' } })
|
||||
await mutate({ mutation: confirmContribution, variables: { id: contribution.id } })
|
||||
const confirmedContribution = await Contribution.findOneOrFail({
|
||||
where: { id: contribution.id },
|
||||
})
|
||||
|
||||
if (creation.moveCreationDate) {
|
||||
const transaction = await Transaction.findOneOrFail({
|
||||
where: { userId: user.id, creationDate: new Date(creation.contributionDate) },
|
||||
order: { balanceDate: 'DESC' },
|
||||
})
|
||||
|
||||
if (transaction.decay.equals(0) && transaction.creationDate) {
|
||||
confirmedContribution.contributionDate = new Date(
|
||||
nMonthsBefore(transaction.creationDate, creation.moveCreationDate),
|
||||
)
|
||||
transaction.creationDate = new Date(
|
||||
nMonthsBefore(transaction.creationDate, creation.moveCreationDate),
|
||||
)
|
||||
transaction.balanceDate = new Date(
|
||||
nMonthsBefore(transaction.balanceDate, creation.moveCreationDate),
|
||||
)
|
||||
await transaction.save()
|
||||
await confirmedContribution.save()
|
||||
}
|
||||
}
|
||||
return confirmedContribution
|
||||
} else {
|
||||
return contribution
|
||||
}
|
||||
return creationFactoryDb(creation)
|
||||
}
|
||||
|
||||
@ -1,46 +1,13 @@
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
import { TransactionLink } from 'database'
|
||||
import {
|
||||
transactionLinkFactory as transactionLinkFactoryDb,
|
||||
TransactionLinkInterface
|
||||
} from 'database'
|
||||
|
||||
import { transactionLinkExpireDate } from '@/graphql/resolver/TransactionLinkResolver'
|
||||
import { createTransactionLink, login } from '@/seeds/graphql/mutations'
|
||||
import { TransactionLinkInterface } from '@/seeds/transactionLink/TransactionLinkInterface'
|
||||
export { TransactionLinkInterface }
|
||||
|
||||
export const transactionLinkFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
export async function transactionLinkFactory (
|
||||
_client: any,
|
||||
transactionLink: TransactionLinkInterface,
|
||||
): Promise<void> => {
|
||||
const { mutate } = client
|
||||
|
||||
// login
|
||||
await mutate({
|
||||
mutation: 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({ where: { id } })
|
||||
|
||||
if (transactionLink.createdAt) {
|
||||
dbTransactionLink.createdAt = transactionLink.createdAt
|
||||
dbTransactionLink.validUntil = transactionLinkExpireDate(transactionLink.createdAt)
|
||||
await dbTransactionLink.save()
|
||||
}
|
||||
|
||||
if (transactionLink.deletedAt) {
|
||||
dbTransactionLink.deletedAt = new Date(dbTransactionLink.createdAt.getTime() + 1000)
|
||||
await dbTransactionLink.save()
|
||||
}
|
||||
}
|
||||
): Promise<void> {
|
||||
await transactionLinkFactoryDb(transactionLink)
|
||||
}
|
||||
|
||||
@ -1,77 +1,20 @@
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
import { User } from 'database'
|
||||
import { User, userFactory as userFactoryDb } from 'database'
|
||||
|
||||
import { RoleNames } from '@enum/RoleNames'
|
||||
|
||||
import { setUserRole } from '@/graphql/resolver/util/modifyUserRole'
|
||||
import { writeHomeCommunityEntry } from '@/seeds/community'
|
||||
import { createUser, setPassword } from '@/seeds/graphql/mutations'
|
||||
import { UserInterface } from '@/seeds/users/UserInterface'
|
||||
import { encryptPassword } from '@/password/PasswordEncryptor'
|
||||
|
||||
export const userFactory = async (
|
||||
client: ApolloServerTestClient,
|
||||
_client: any,
|
||||
user: UserInterface,
|
||||
): Promise<User> => {
|
||||
const { mutate } = client
|
||||
|
||||
const homeCom = await writeHomeCommunityEntry()
|
||||
// console.log('call createUser with', JSON.stringify(user, null, 2))
|
||||
const response = await mutate({ mutation: createUser, variables: user })
|
||||
if (!response?.data?.createUser) {
|
||||
// console.log(JSON.stringify(response, null, 2))
|
||||
throw new Error('createUser mutation returned unexpected response')
|
||||
}
|
||||
const {
|
||||
data: {
|
||||
createUser: { id },
|
||||
},
|
||||
} = response
|
||||
// get user from database
|
||||
let dbUser = await User.findOneOrFail({ where: { id }, relations: ['emailContact', 'userRoles'] })
|
||||
|
||||
const emailContact = dbUser.emailContact
|
||||
const dbUser = await userFactoryDb(user, homeCom)
|
||||
|
||||
if (user.emailChecked) {
|
||||
await mutate({
|
||||
mutation: setPassword,
|
||||
variables: { password: 'Aa12345_', code: emailContact.emailVerificationCode },
|
||||
})
|
||||
}
|
||||
|
||||
// get last changes of user from database
|
||||
dbUser = await User.findOneOrFail({ where: { id }, relations: { userRoles: true, emailContact: true } })
|
||||
|
||||
if (user.createdAt || user.deletedAt || user.role) {
|
||||
if (user.createdAt) {
|
||||
dbUser.createdAt = user.createdAt
|
||||
// make sure emailContact is also updated for e2e test, prevent failing when time between seeding and test run is < 1 minute
|
||||
dbUser.emailContact.createdAt = user.createdAt
|
||||
dbUser.emailContact.updatedAt = user.createdAt
|
||||
await dbUser.emailContact.save()
|
||||
}
|
||||
if (user.deletedAt) {
|
||||
dbUser.deletedAt = user.deletedAt
|
||||
}
|
||||
const userRole = user.role as RoleNames
|
||||
if (userRole && (userRole === RoleNames.ADMIN || userRole === RoleNames.MODERATOR)) {
|
||||
await setUserRole(dbUser, user.role)
|
||||
}
|
||||
const passwortHash = await encryptPassword(dbUser, 'Aa12345_')
|
||||
dbUser.password = passwortHash
|
||||
await dbUser.save()
|
||||
}
|
||||
try {
|
||||
if (homeCom.communityUuid) {
|
||||
dbUser.communityUuid = homeCom.communityUuid
|
||||
await User.save(dbUser)
|
||||
}
|
||||
} catch (_err) {
|
||||
// no homeCommunity exists
|
||||
}
|
||||
|
||||
// get last changes of user from database
|
||||
dbUser = await User.findOneOrFail({
|
||||
where: { id },
|
||||
withDeleted: true,
|
||||
relations: ['emailContact', 'userRoles'],
|
||||
})
|
||||
return dbUser
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
export { TransactionLinkInterface } from 'database'
|
||||
/*
|
||||
export interface TransactionLinkInterface {
|
||||
email: string
|
||||
amount: number
|
||||
@ -8,3 +10,4 @@ export interface TransactionLinkInterface {
|
||||
// redeemedBy?: number
|
||||
deletedAt?: boolean
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,5 @@
|
||||
export { transactionLinks } from 'database'
|
||||
/*
|
||||
import { TransactionLinkInterface } from './TransactionLinkInterface'
|
||||
|
||||
export const transactionLinks: TransactionLinkInterface[] = [
|
||||
@ -53,3 +55,4 @@ bei Gradidio sei dabei!`,
|
||||
deletedAt: true,
|
||||
},
|
||||
]
|
||||
*/
|
||||
@ -1,3 +1,5 @@
|
||||
export { UserInterface } from 'database'
|
||||
/*
|
||||
export interface UserInterface {
|
||||
alias?: string
|
||||
email?: string
|
||||
@ -11,3 +13,4 @@ export interface UserInterface {
|
||||
publisherId?: number
|
||||
role?: string
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,5 @@
|
||||
export { bibiBloxberg } from 'database'
|
||||
/*
|
||||
import { UserInterface } from './UserInterface'
|
||||
|
||||
export const bibiBloxberg: UserInterface = {
|
||||
@ -12,3 +14,4 @@ export const bibiBloxberg: UserInterface = {
|
||||
// move user createdAt before transaction link
|
||||
createdAt: new Date(2021, 9, 17),
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,5 @@
|
||||
export { bobBaumeister } from 'database'
|
||||
/*
|
||||
import { UserInterface } from './UserInterface'
|
||||
|
||||
export const bobBaumeister: UserInterface = {
|
||||
@ -9,3 +11,4 @@ export const bobBaumeister: UserInterface = {
|
||||
emailChecked: true,
|
||||
language: 'de',
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,6 @@
|
||||
|
||||
export { garrickOllivander } from 'database'
|
||||
/*
|
||||
import { UserInterface } from './UserInterface'
|
||||
|
||||
export const garrickOllivander: UserInterface = {
|
||||
@ -10,3 +13,4 @@ export const garrickOllivander: UserInterface = {
|
||||
emailChecked: false,
|
||||
language: 'en',
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,5 @@
|
||||
export { peterLustig } from 'database'
|
||||
/*
|
||||
import { RoleNames } from '@enum/RoleNames'
|
||||
|
||||
import { UserInterface } from './UserInterface'
|
||||
@ -12,3 +14,4 @@ export const peterLustig: UserInterface = {
|
||||
language: 'de',
|
||||
role: RoleNames.ADMIN,
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,6 @@
|
||||
|
||||
export { raeuberHotzenplotz } from 'database'
|
||||
/*
|
||||
import { UserInterface } from './UserInterface'
|
||||
|
||||
export const raeuberHotzenplotz: UserInterface = {
|
||||
@ -8,3 +11,4 @@ export const raeuberHotzenplotz: UserInterface = {
|
||||
emailChecked: true,
|
||||
language: 'de',
|
||||
}
|
||||
*/
|
||||
@ -1,3 +1,5 @@
|
||||
export { stephenHawking } from 'database'
|
||||
/*
|
||||
import { UserInterface } from './UserInterface'
|
||||
|
||||
export const stephenHawking: UserInterface = {
|
||||
@ -10,3 +12,4 @@ export const stephenHawking: UserInterface = {
|
||||
deletedAt: new Date('2018-03-14T09:17:52'),
|
||||
language: 'en',
|
||||
}
|
||||
*/
|
||||
8
bun.lock
8
bun.lock
@ -245,7 +245,7 @@
|
||||
"@types/mysql": "^2.15.27",
|
||||
"@types/node": "^18.7.14",
|
||||
"await-semaphore": "^0.1.3",
|
||||
"crypto-random-bigint": "^2.1.1",
|
||||
"random-bigint": "^0.0.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^4.9.5",
|
||||
},
|
||||
@ -1768,8 +1768,6 @@
|
||||
|
||||
"cross-spawn": ["cross-spawn@7.0.6", "", { "dependencies": { "path-key": "^3.1.0", "shebang-command": "^2.0.0", "which": "^2.0.1" } }, "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA=="],
|
||||
|
||||
"crypto-random-bigint": ["crypto-random-bigint@2.1.1", "", { "dependencies": { "uint-rng": "^1.2.1" } }, "sha512-96+FDrenXybkpnLML/60S8NcG32KgJ5Y8yvNNCYPW02r+ssoXFR5XKenuIQcHLWumnGj8UPqUUHBzXNrDGkDmQ=="],
|
||||
|
||||
"css-functions-list": ["css-functions-list@3.2.3", "", {}, "sha512-IQOkD3hbR5KrN93MtcYuad6YPuTSUhntLHDuLEbFWE+ff2/XSZNdZG+LcbbIW5AXKg/WFIfYItIzVoHngHXZzA=="],
|
||||
|
||||
"css-select": ["css-select@4.3.0", "", { "dependencies": { "boolbase": "^1.0.0", "css-what": "^6.0.1", "domhandler": "^4.3.1", "domutils": "^2.8.0", "nth-check": "^2.0.1" } }, "sha512-wPpOYtnsVontu2mODhA19JrqWxNsfdatRKd64kmpRbQgh1KtItko5sTnEpPdpSaJszTOhEMlF/RPz28qj4HqhQ=="],
|
||||
@ -3278,8 +3276,6 @@
|
||||
|
||||
"tiny-case": ["tiny-case@1.0.3", "", {}, "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q=="],
|
||||
|
||||
"tiny-webcrypto": ["tiny-webcrypto@1.0.3", "", {}, "sha512-LQQdNMAgz9BXNT2SKbYh3eCb+fLV0p7JB7MwUjzY6IOlQLGIadfnFqRpshERsS5Dl2OM/hs0+4I/XmSrF+RBbw=="],
|
||||
|
||||
"tinybench": ["tinybench@2.9.0", "", {}, "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg=="],
|
||||
|
||||
"tinyexec": ["tinyexec@1.0.1", "", {}, "sha512-5uC6DDlmeqiOwCPmK9jMSdOuZTh8bU39Ys6yidB+UTt5hfZUPGAypSgFRiEp+jbi9qH40BLDvy85jIU88wKSqw=="],
|
||||
@ -3392,8 +3388,6 @@
|
||||
|
||||
"uglify-js": ["uglify-js@3.19.3", "", { "bin": { "uglifyjs": "bin/uglifyjs" } }, "sha512-v3Xu+yuwBXisp6QYTcH4UbH+xYJXqnq2m/LtQVWKWzYc1iehYnLixoQDN9FH6/j9/oybfd6W9Ghwkl8+UMKTKQ=="],
|
||||
|
||||
"uint-rng": ["uint-rng@1.2.1", "", { "dependencies": { "tiny-webcrypto": "^1.0.2" } }, "sha512-swhDg5H+3DX2sIvnYA7VMBMXV/t8mPxvh49CjCDkwFmj/3OZIDOQwJANBgM1MPSUBrUHNIlXmU7/GcL7m4907g=="],
|
||||
|
||||
"uint8array-extras": ["uint8array-extras@1.5.0", "", {}, "sha512-rvKSBiC5zqCCiDZ9kAOszZcDvdAHwwIKJG33Ykj43OKcWsnmcBRL09YTU4nOeHZ8Y2a7l1MgTd08SBe9A8Qj6A=="],
|
||||
|
||||
"unbox-primitive": ["unbox-primitive@1.1.0", "", { "dependencies": { "call-bound": "^1.0.3", "has-bigints": "^1.0.2", "has-symbols": "^1.1.0", "which-boxed-primitive": "^1.1.1" } }, "sha512-nWJ91DjeOkej/TA8pXQ3myruKpKEYgqvpw9lz4OPHj/NWFNluYrjbz9j01CJ8yKQd2g4jFoOkINCTW2I5LEEyw=="],
|
||||
|
||||
5
database/@types/random-bigint/index.d.ts
vendored
Normal file
5
database/@types/random-bigint/index.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
declare module 'random-bigint' {
|
||||
function random(bits: number, cb?: (err: Error, num: BigInt) => void): BigInt
|
||||
export = random
|
||||
}
|
||||
@ -25,7 +25,7 @@
|
||||
"up": "cross-env TZ=UTC tsx migration/index.ts up",
|
||||
"down": "cross-env TZ=UTC tsx migration/index.ts down",
|
||||
"reset": "cross-env TZ=UTC tsx migration/index.ts reset",
|
||||
"seed": "cross-env TZ=UTC NODE_ENV=development bun src/seeds/index.ts",
|
||||
"seed": "cross-env TZ=UTC NODE_ENV=development bun src/seeds/seed.ts",
|
||||
"up:test": "cross-env TZ=UTC DB_DATABASE=gradido_test tsx migration/index.ts up",
|
||||
"up:backend_test": "cross-env TZ=UTC DB_DATABASE=gradido_test_backend tsx migration/index.ts up",
|
||||
"up:federation_test": "cross-env TZ=UTC DB_DATABASE=gradido_test_federation tsx migration/index.ts up",
|
||||
@ -39,7 +39,7 @@
|
||||
"@types/mysql": "^2.15.27",
|
||||
"@types/node": "^18.7.14",
|
||||
"await-semaphore": "^0.1.3",
|
||||
"crypto-random-bigint": "^2.1.1",
|
||||
"random-bigint": "^0.0.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^4.9.5"
|
||||
},
|
||||
|
||||
@ -4,6 +4,7 @@ export { latestDbVersion }
|
||||
export * from './entity'
|
||||
export * from './logging'
|
||||
export * from './queries'
|
||||
export * from './seeds'
|
||||
export * from './util'
|
||||
export * from './enum'
|
||||
export { AppDatabase } from './AppDatabase'
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { ContributionLinkInterface } from './ContributionLinkInterface'
|
||||
export type { ContributionLinkInterface }
|
||||
|
||||
export const contributionLinks: ContributionLinkInterface[] = [
|
||||
{
|
||||
|
||||
@ -2,6 +2,8 @@ import { nMonthsBefore } from '../factory/creation'
|
||||
|
||||
import { CreationInterface } from './CreationInterface'
|
||||
|
||||
export type { CreationInterface }
|
||||
|
||||
const bobsSendings = [
|
||||
{
|
||||
amount: 10,
|
||||
|
||||
@ -5,13 +5,11 @@ import { ContributionLinkInterface } from '../contributionLink/ContributionLinkI
|
||||
import { transactionLinkCode } from './transactionLink'
|
||||
import { ContributionCycleType } from '../../enum'
|
||||
|
||||
export const contributionLinkFactory = async (
|
||||
contributionLink: ContributionLinkInterface,
|
||||
): Promise<ContributionLink> => {
|
||||
export function contributionLinkFactory(contributionLink: ContributionLinkInterface): Promise<ContributionLink> {
|
||||
return createContributionLink(contributionLink)
|
||||
}
|
||||
|
||||
export async function createContributionLink(contributionLinkData: ContributionLinkInterface): Promise<ContributionLink> {
|
||||
export function createContributionLink(contributionLinkData: ContributionLinkInterface): Promise<ContributionLink> {
|
||||
const contributionLink = new ContributionLink()
|
||||
contributionLink.amount = new Decimal(contributionLinkData.amount)
|
||||
contributionLink.name = contributionLinkData.name
|
||||
|
||||
6
database/src/seeds/factory/index.ts
Normal file
6
database/src/seeds/factory/index.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export * from './contributionLink'
|
||||
export * from './creation'
|
||||
export * from './pendingTransaction'
|
||||
export * from './transaction'
|
||||
export * from './transactionLink'
|
||||
export * from './user'
|
||||
@ -3,7 +3,7 @@ import { User, UserContact, UserRole } from '../../entity'
|
||||
import { v4 } from 'uuid'
|
||||
import { UserContactType, OptInType, PasswordEncryptionType } from 'shared'
|
||||
import { getHomeCommunity } from '../../queries/communities'
|
||||
import random from 'crypto-random-bigint'
|
||||
import random from 'random-bigint'
|
||||
import { Community } from '../../entity'
|
||||
import { AppDatabase } from '../..'
|
||||
import { RoleNames } from '../../enum/RoleNames'
|
||||
@ -12,14 +12,13 @@ export async function userFactory(user: UserInterface, homeCommunity?: Community
|
||||
// TODO: improve with cascade
|
||||
let dbUser = await createUser(user, homeCommunity)
|
||||
let dbUserContact = await createUserContact(user, dbUser.id)
|
||||
dbUserContact = await dbUserContact.save()
|
||||
dbUser.emailId = dbUserContact.id
|
||||
dbUser.emailContact = dbUserContact
|
||||
dbUser = await dbUser.save()
|
||||
|
||||
const userRole = user.role as RoleNames
|
||||
if (userRole && (userRole === RoleNames.ADMIN || userRole === RoleNames.MODERATOR)) {
|
||||
await createUserRole(dbUser.id, userRole)
|
||||
dbUser.userRoles = [await createUserRole(dbUser.id, userRole)]
|
||||
}
|
||||
|
||||
return dbUser
|
||||
@ -86,7 +85,7 @@ export async function createUser(user: UserInterface, homeCommunity?: Community
|
||||
dbUser.gradidoID = v4()
|
||||
|
||||
if (user.emailChecked) {
|
||||
dbUser.password = random(64)
|
||||
// dbUser.password =
|
||||
dbUser.passwordEncryptionType = PasswordEncryptionType.GRADIDO_ID
|
||||
}
|
||||
if (!homeCommunity) {
|
||||
|
||||
@ -1,98 +1,5 @@
|
||||
import { AppDatabase } from '../AppDatabase'
|
||||
import { createCommunity } from './community'
|
||||
import { userFactoryBulk } from './factory/user'
|
||||
import { users } from './users'
|
||||
import { internet, name } from 'faker'
|
||||
import { creationFactoryBulk } from './factory/creation'
|
||||
import { creations } from './creation'
|
||||
import { transactionLinkCode, transactionLinkFactoryBulk } from './factory/transactionLink'
|
||||
import { transactionLinks } from './transactionLink'
|
||||
import { contributionLinkFactory } from './factory/contributionLink'
|
||||
import { contributionLinks } from './contributionLink'
|
||||
import { User } from '../entity'
|
||||
import { UserInterface } from './users/UserInterface'
|
||||
|
||||
const RANDOM_USER_COUNT = 100
|
||||
|
||||
async function run() {
|
||||
console.info('##seed## seeding started...')
|
||||
|
||||
const db = AppDatabase.getInstance()
|
||||
await db.init()
|
||||
await clearDatabase()
|
||||
|
||||
// seed home community
|
||||
const homeCommunity = await createCommunity(false)
|
||||
console.info(`##seed## seeding home community successful ...`)
|
||||
|
||||
// seed standard users
|
||||
// put into map for later direct access
|
||||
const userCreationIndexedByEmail = new Map<string, User>()
|
||||
const defaultUsers = await userFactoryBulk(users, homeCommunity)
|
||||
for (const dbUser of defaultUsers) {
|
||||
userCreationIndexedByEmail.set(dbUser.emailContact.email, dbUser)
|
||||
}
|
||||
console.info(`##seed## seeding all standard users successful ...`)
|
||||
|
||||
// seed 100 random users
|
||||
const randomUsers = new Array<UserInterface>(RANDOM_USER_COUNT)
|
||||
for (let i = 0; i < RANDOM_USER_COUNT; i++) {
|
||||
randomUsers[i] = {
|
||||
firstName: name.firstName(),
|
||||
lastName: name.lastName(),
|
||||
email: internet.email(),
|
||||
language: Math.random() < 0.5 ? 'en' : 'de',
|
||||
}
|
||||
}
|
||||
await userFactoryBulk(randomUsers, homeCommunity)
|
||||
console.info(`##seed## seeding ${RANDOM_USER_COUNT} random users successful ...`)
|
||||
|
||||
// create GDD serial, must be called one after another because seeding don't use semaphore
|
||||
const moderatorUser = userCreationIndexedByEmail.get('peter@lustig.de')!
|
||||
await creationFactoryBulk(creations, userCreationIndexedByEmail, moderatorUser)
|
||||
console.info(`##seed## seeding all creations successful ...`)
|
||||
|
||||
// create Contribution Links
|
||||
for (const contributionLink of contributionLinks) {
|
||||
await contributionLinkFactory(contributionLink)
|
||||
}
|
||||
console.info(`##seed## seeding all contributionLinks successful ...`)
|
||||
|
||||
// create Transaction Links
|
||||
const movedTransactionLinks = transactionLinks.map(transactionLink => {
|
||||
let createdAt = new Date(new Date().getTime() + 1000)
|
||||
if (transactionLink.createdAt) {
|
||||
createdAt = transactionLink.createdAt
|
||||
}
|
||||
return {
|
||||
...transactionLink,
|
||||
createdAt: createdAt,
|
||||
}
|
||||
})
|
||||
await transactionLinkFactoryBulk(movedTransactionLinks, userCreationIndexedByEmail)
|
||||
console.info(`##seed## seeding all transactionLinks successful ...`)
|
||||
|
||||
await db.destroy()
|
||||
console.info(`##seed## seeding successful...`)
|
||||
}
|
||||
|
||||
async function clearDatabase() {
|
||||
await AppDatabase.getInstance().getDataSource().transaction(async trx => {
|
||||
await trx.query(`SET FOREIGN_KEY_CHECKS = 0`)
|
||||
await trx.query(`TRUNCATE TABLE contributions`)
|
||||
await trx.query(`TRUNCATE TABLE contribution_links`)
|
||||
await trx.query(`TRUNCATE TABLE users`)
|
||||
await trx.query(`TRUNCATE TABLE user_contacts`)
|
||||
await trx.query(`TRUNCATE TABLE user_roles`)
|
||||
await trx.query(`TRUNCATE TABLE transactions`)
|
||||
await trx.query(`TRUNCATE TABLE transaction_links`)
|
||||
await trx.query(`TRUNCATE TABLE communities`)
|
||||
await trx.query(`SET FOREIGN_KEY_CHECKS = 1`)
|
||||
})
|
||||
}
|
||||
|
||||
run().catch((err) => {
|
||||
// biome-ignore lint/suspicious/noConsole: no logger present
|
||||
console.error('error on seeding', err)
|
||||
})
|
||||
|
||||
export * from './contributionLink'
|
||||
export * from './creation'
|
||||
export * from './factory'
|
||||
export * from './transactionLink'
|
||||
export * from './users'
|
||||
|
||||
98
database/src/seeds/seed.ts
Normal file
98
database/src/seeds/seed.ts
Normal file
@ -0,0 +1,98 @@
|
||||
import { AppDatabase } from '../AppDatabase'
|
||||
import { createCommunity } from './community'
|
||||
import { userFactoryBulk } from './factory/user'
|
||||
import { users } from './users'
|
||||
import { internet, name } from 'faker'
|
||||
import { creationFactoryBulk } from './factory/creation'
|
||||
import { creations } from './creation'
|
||||
import { transactionLinkFactoryBulk } from './factory/transactionLink'
|
||||
import { transactionLinks } from './transactionLink'
|
||||
import { contributionLinkFactory } from './factory/contributionLink'
|
||||
import { contributionLinks } from './contributionLink'
|
||||
import { User } from '../entity'
|
||||
import { UserInterface } from './users/UserInterface'
|
||||
|
||||
const RANDOM_USER_COUNT = 100
|
||||
|
||||
async function run() {
|
||||
console.info('##seed## seeding started...')
|
||||
|
||||
const db = AppDatabase.getInstance()
|
||||
await db.init()
|
||||
await clearDatabase()
|
||||
|
||||
// seed home community
|
||||
const homeCommunity = await createCommunity(false)
|
||||
console.info(`##seed## seeding home community successful ...`)
|
||||
|
||||
// seed standard users
|
||||
// put into map for later direct access
|
||||
const userCreationIndexedByEmail = new Map<string, User>()
|
||||
const defaultUsers = await userFactoryBulk(users, homeCommunity)
|
||||
for (const dbUser of defaultUsers) {
|
||||
userCreationIndexedByEmail.set(dbUser.emailContact.email, dbUser)
|
||||
}
|
||||
console.info(`##seed## seeding all standard users successful ...`)
|
||||
|
||||
// seed 100 random users
|
||||
const randomUsers = new Array<UserInterface>(RANDOM_USER_COUNT)
|
||||
for (let i = 0; i < RANDOM_USER_COUNT; i++) {
|
||||
randomUsers[i] = {
|
||||
firstName: name.firstName(),
|
||||
lastName: name.lastName(),
|
||||
email: internet.email(),
|
||||
language: Math.random() < 0.5 ? 'en' : 'de',
|
||||
}
|
||||
}
|
||||
await userFactoryBulk(randomUsers, homeCommunity)
|
||||
console.info(`##seed## seeding ${RANDOM_USER_COUNT} random users successful ...`)
|
||||
|
||||
// create GDD serial, must be called one after another because seeding don't use semaphore
|
||||
const moderatorUser = userCreationIndexedByEmail.get('peter@lustig.de')!
|
||||
await creationFactoryBulk(creations, userCreationIndexedByEmail, moderatorUser)
|
||||
console.info(`##seed## seeding all creations successful ...`)
|
||||
|
||||
// create Contribution Links
|
||||
for (const contributionLink of contributionLinks) {
|
||||
await contributionLinkFactory(contributionLink)
|
||||
}
|
||||
console.info(`##seed## seeding all contributionLinks successful ...`)
|
||||
|
||||
// create Transaction Links
|
||||
const movedTransactionLinks = transactionLinks.map(transactionLink => {
|
||||
let createdAt = new Date(new Date().getTime() + 1000)
|
||||
if (transactionLink.createdAt) {
|
||||
createdAt = transactionLink.createdAt
|
||||
}
|
||||
return {
|
||||
...transactionLink,
|
||||
createdAt: createdAt,
|
||||
}
|
||||
})
|
||||
await transactionLinkFactoryBulk(movedTransactionLinks, userCreationIndexedByEmail)
|
||||
console.info(`##seed## seeding all transactionLinks successful ...`)
|
||||
|
||||
await db.destroy()
|
||||
console.info(`##seed## seeding successful...`)
|
||||
}
|
||||
|
||||
async function clearDatabase() {
|
||||
await AppDatabase.getInstance().getDataSource().transaction(async trx => {
|
||||
await trx.query(`SET FOREIGN_KEY_CHECKS = 0`)
|
||||
await trx.query(`TRUNCATE TABLE contributions`)
|
||||
await trx.query(`TRUNCATE TABLE contribution_links`)
|
||||
await trx.query(`TRUNCATE TABLE users`)
|
||||
await trx.query(`TRUNCATE TABLE user_contacts`)
|
||||
await trx.query(`TRUNCATE TABLE user_roles`)
|
||||
await trx.query(`TRUNCATE TABLE transactions`)
|
||||
await trx.query(`TRUNCATE TABLE transaction_links`)
|
||||
await trx.query(`TRUNCATE TABLE communities`)
|
||||
await trx.query(`SET FOREIGN_KEY_CHECKS = 1`)
|
||||
})
|
||||
}
|
||||
|
||||
run().catch((err) => {
|
||||
// biome-ignore lint/suspicious/noConsole: no logger present
|
||||
console.error('error on seeding', err)
|
||||
})
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { TransactionLinkInterface } from './TransactionLinkInterface'
|
||||
export type { TransactionLinkInterface }
|
||||
|
||||
export const transactionLinks: TransactionLinkInterface[] = [
|
||||
{
|
||||
|
||||
@ -4,8 +4,19 @@ import { garrickOllivander } from './garrick-ollivander'
|
||||
import { peterLustig } from './peter-lustig'
|
||||
import { raeuberHotzenplotz } from './raeuber-hotzenplotz'
|
||||
import { stephenHawking } from './stephen-hawking'
|
||||
import { UserInterface } from './UserInterface'
|
||||
|
||||
export const users = [
|
||||
export {
|
||||
type UserInterface,
|
||||
bibiBloxberg,
|
||||
bobBaumeister,
|
||||
garrickOllivander,
|
||||
peterLustig,
|
||||
raeuberHotzenplotz,
|
||||
stephenHawking
|
||||
}
|
||||
|
||||
export const users: UserInterface[] = [
|
||||
peterLustig,
|
||||
bibiBloxberg,
|
||||
bobBaumeister,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user