mirror of
https://github.com/IT4Change/gradido.git
synced 2026-01-20 20:01:31 +00:00
Merge branch '2878-trigger-export-klicktipp' of github.com:gradido/gradido into 2878-trigger-export-klicktipp
This commit is contained in:
commit
9959a69693
87
backend/src/util/klicktipp.test.ts
Normal file
87
backend/src/util/klicktipp.test.ts
Normal file
@ -0,0 +1,87 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
import { Connection } from '@dbTools/typeorm'
|
||||
import { Event as DbEvent } from '@entity/Event'
|
||||
import { ApolloServerTestClient } from 'apollo-server-testing'
|
||||
|
||||
import { testEnvironment, cleanDB, resetToken } from '@test/helpers'
|
||||
|
||||
import { addFieldsToSubscriber } from '@/apis/KlicktippController'
|
||||
import { creations } from '@/seeds/creation'
|
||||
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'
|
||||
|
||||
jest.mock('@/apis/KlicktippController', () => {
|
||||
const originalModule = jest.requireActual('@/apis/KlicktippController')
|
||||
return {
|
||||
__esModule: true,
|
||||
...originalModule,
|
||||
getKlickTippUser: jest.fn((email) => originalModule.getKlickTippUser(email)),
|
||||
addFieldsToSubscriber: jest.fn((email, a) => originalModule.addFieldsToSubscriber(email, a)),
|
||||
}
|
||||
})
|
||||
|
||||
// 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
|
||||
let testEnv: {
|
||||
mutate: ApolloServerTestClient['mutate']
|
||||
query: ApolloServerTestClient['query']
|
||||
con: Connection
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
testEnv = await testEnvironment()
|
||||
mutate = testEnv.mutate
|
||||
query = testEnv.query
|
||||
con = testEnv.con
|
||||
await DbEvent.clear()
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await cleanDB()
|
||||
await con.close()
|
||||
})
|
||||
|
||||
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!)
|
||||
await mutate({
|
||||
mutation: login,
|
||||
variables: { email: 'bibi@bloxberg.de', password: 'Aa12345_' },
|
||||
})
|
||||
await con.close()
|
||||
void exportEventDataToKlickTipp()
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
resetToken()
|
||||
})
|
||||
|
||||
describe('exportEventDataToKlickTipp', () => {
|
||||
it('calls the KlicktippController', () => {
|
||||
expect(addFieldsToSubscriber).toBeCalled()
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -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,6 +40,10 @@ async function klickTippSendFieldToUser(
|
||||
}
|
||||
}
|
||||
|
||||
function getMyConnection(): Promise<Connection | null> {
|
||||
return connection()
|
||||
}
|
||||
|
||||
export async function exportEventDataToKlickTipp(): Promise<void> {
|
||||
const connectionInstance = await getConnection()
|
||||
if (!connectionInstance) {
|
||||
@ -46,22 +51,24 @@ export async function exportEventDataToKlickTipp(): Promise<void> {
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user