Test for the klicktipp tag export.

This commit is contained in:
elweyn 2023-05-12 18:23:36 +02:00
parent 4da0f8d0f7
commit 10c0cf8370
2 changed files with 28 additions and 9 deletions

View File

@ -14,6 +14,8 @@ import { creationFactory } from '@/seeds/factory/creation'
import { userFactory } from '@/seeds/factory/user'
import { login } from '@/seeds/graphql/mutations'
import { bibiBloxberg } from '@/seeds/users/bibi-bloxberg'
import { peterLustig } from '@/seeds/users/peter-lustig'
import { connection } from '@/typeorm/connection'
import { exportEventDataToKlickTipp } from './klicktipp'
@ -27,6 +29,15 @@ jest.mock('@/apis/KlicktippController', () => {
}
})
// jest.mock('@/typeorm/connection', () => {
// const originalModule = jest.requireActual('@/typeorm/connection')
// return {
// __esModule: true,
// ...originalModule,
// connection: jest.fn(() => Promise.resolve(con)),
// }
// })
let mutate: ApolloServerTestClient['mutate'],
query: ApolloServerTestClient['query'],
con: Connection
@ -52,6 +63,7 @@ afterAll(async () => {
describe('klicktipp', () => {
beforeAll(async () => {
await userFactory(testEnv, bibiBloxberg)
await userFactory(testEnv, peterLustig)
const bibisCreation = creations.find((creation) => creation.email === 'bibi@bloxberg.de')
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await creationFactory(testEnv, bibisCreation!)
@ -59,11 +71,11 @@ describe('klicktipp', () => {
mutation: login,
variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' },
})
await con.close()
void exportEventDataToKlickTipp()
})
afterAll(async () => {
await cleanDB()
afterAll(() => {
resetToken()
})

View File

@ -1,4 +1,5 @@
// eslint-disable @typescript-eslint/no-explicit-any
import { Connection } from '@dbTools/typeorm'
import { User } from '@entity/User'
import { getKlickTippUser, addFieldsToSubscriber } from '@/apis/KlicktippController'
@ -39,29 +40,35 @@ async function klickTippSendFieldToUser(
}
}
function getMyConnection(): Promise<Connection | null> {
return connection()
}
export async function exportEventDataToKlickTipp(): Promise<void> {
const connectionInstance = await connection()
const connectionInstance = await getMyConnection()
if (!connectionInstance) {
throw new LogError('No connection to database')
}
const lastLoginEvents = await lastDateTimeEvents(EventType.USER_LOGIN)
void klickTippSendFieldToUser(lastLoginEvents, 'field186060')
await klickTippSendFieldToUser(lastLoginEvents, 'field186060')
const registeredEvents = await lastDateTimeEvents(EventType.USER_ACTIVATE_ACCOUNT)
void klickTippSendFieldToUser(registeredEvents, 'field186061')
await klickTippSendFieldToUser(registeredEvents, 'field186061')
const receiveTransactionEvents = await lastDateTimeEvents(EventType.TRANSACTION_RECEIVE)
void klickTippSendFieldToUser(receiveTransactionEvents, 'field185674')
await klickTippSendFieldToUser(receiveTransactionEvents, 'field185674')
const contributionCreateEvents = await lastDateTimeEvents(EventType.TRANSACTION_SEND)
void klickTippSendFieldToUser(contributionCreateEvents, 'field185673')
await klickTippSendFieldToUser(contributionCreateEvents, 'field185673')
const linkRedeemedEvents = await lastDateTimeEvents(EventType.TRANSACTION_LINK_REDEEM)
void klickTippSendFieldToUser(linkRedeemedEvents, 'field185676')
await klickTippSendFieldToUser(linkRedeemedEvents, 'field185676')
const confirmContributionEvents = await lastDateTimeEvents(EventType.ADMIN_CONTRIBUTION_CONFIRM)
void klickTippSendFieldToUser(confirmContributionEvents, 'field185675')
await klickTippSendFieldToUser(confirmContributionEvents, 'field185675')
await connectionInstance.close()
}
void exportEventDataToKlickTipp()
// void retrieveNotRegisteredEmails()