Merge branch 'master' into dissolve_admin_resolver

This commit is contained in:
Ulf Gebhardt 2022-12-01 21:45:19 +01:00 committed by GitHub
commit ac578b3f10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 23 deletions

View File

@ -291,7 +291,6 @@ describe('send coins', () => {
await cleanDB() await cleanDB()
}) })
/*
describe('trying to send negative amount', () => { describe('trying to send negative amount', () => {
it('throws an error', async () => { it('throws an error', async () => {
expect( expect(
@ -305,18 +304,15 @@ describe('send coins', () => {
}), }),
).toEqual( ).toEqual(
expect.objectContaining({ expect.objectContaining({
errors: [new GraphQLError(`user hasn't enough GDD or amount is < 0`)], errors: [new GraphQLError(`Amount to send must be positive`)],
}), }),
) )
}) })
it('logs the error thrown', () => { it('logs the error thrown', () => {
expect(logger.error).toBeCalledWith( expect(logger.error).toBeCalledWith(`Amount to send must be positive`)
`user hasn't enough GDD or amount is < 0 : balance=null`,
)
}) })
}) })
*/
describe('good transaction', () => { describe('good transaction', () => {
it('sends the coins', async () => { it('sends the coins', async () => {

View File

@ -309,6 +309,10 @@ export class TransactionResolver {
@Ctx() context: Context, @Ctx() context: Context,
): Promise<boolean> { ): Promise<boolean> {
logger.info(`sendCoins(email=${email}, amount=${amount}, memo=${memo})`) logger.info(`sendCoins(email=${email}, amount=${amount}, memo=${memo})`)
if (amount.lte(0)) {
logger.error(`Amount to send must be positive`)
throw new Error('Amount to send must be positive')
}
// TODO this is subject to replay attacks // TODO this is subject to replay attacks
const senderUser = getUser(context) const senderUser = getUser(context)
@ -319,22 +323,7 @@ export class TransactionResolver {
// validate recipient user // validate recipient user
const recipientUser = await findUserByEmail(email) const recipientUser = await findUserByEmail(email)
/*
const emailContact = await UserContact.findOne({ email }, { withDeleted: true })
if (!emailContact) {
logger.error(`Could not find UserContact with email: ${email}`)
throw new Error(`Could not find UserContact with email: ${email}`)
}
*/
// const recipientUser = await dbUser.findOne({ id: emailContact.userId })
/* Code inside this if statement is unreachable (useless by so),
in findUserByEmail() an error is already thrown if the user is not found
*/
if (!recipientUser) {
logger.error(`unknown recipient to UserContact: email=${email}`)
throw new Error('unknown recipient')
}
if (recipientUser.deletedAt) { if (recipientUser.deletedAt) {
logger.error(`The recipient account was deleted: recipientUser=${recipientUser}`) logger.error(`The recipient account was deleted: recipientUser=${recipientUser}`)
throw new Error('The recipient account was deleted') throw new Error('The recipient account was deleted')

View File

@ -170,8 +170,11 @@ describe('util/creation', () => {
const targetDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 0, 0) const targetDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 0, 0)
beforeAll(() => { beforeAll(() => {
const halfMsToRun = (targetDate.getTime() - now.getTime()) / 2
jest.useFakeTimers() jest.useFakeTimers()
setTimeout(jest.fn(), targetDate.getTime() - now.getTime()) setTimeout(jest.fn(), halfMsToRun)
jest.runAllTimers()
setTimeout(jest.fn(), halfMsToRun)
jest.runAllTimers() jest.runAllTimers()
}) })
@ -225,8 +228,10 @@ describe('util/creation', () => {
}) })
it('has the clock set correctly', () => { it('has the clock set correctly', () => {
const targetMonth = nextMonthTargetDate.getMonth() + 1
const targetMonthString = (targetMonth < 10 ? '0' : '') + String(targetMonth)
expect(new Date().toISOString()).toContain( expect(new Date().toISOString()).toContain(
`${nextMonthTargetDate.getFullYear()}-${nextMonthTargetDate.getMonth() + 1}-01T01:`, `${nextMonthTargetDate.getFullYear()}-${targetMonthString}-01T01:`,
) )
}) })