diff --git a/backend/Dockerfile b/backend/Dockerfile index 6225a4cd7..c09e5aaf8 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -98,10 +98,18 @@ COPY --from=build ${DOCKER_WORKDIR}/../database/build ../database/build # We also copy the node_modules express and serve-static for the run script COPY --from=build ${DOCKER_WORKDIR}/node_modules ./node_modules COPY --from=build ${DOCKER_WORKDIR}/../database/node_modules ../database/node_modules + # Copy static files # COPY --from=build ${DOCKER_WORKDIR}/public ./public # Copy package.json for script definitions (lock file should not be needed) COPY --from=build ${DOCKER_WORKDIR}/package.json ./package.json +# Copy tsconfig.json to provide alias path definitions +COPY --from=build ${DOCKER_WORKDIR}/tsconfig.json ./tsconfig.json +# Copy log4js-config.json to provide log configuration +COPY --from=build ${DOCKER_WORKDIR}/log4js-config.json ./log4js-config.json +# Copy memonic type since its referenced in the sources +# TODO: remove +COPY --from=build ${DOCKER_WORKDIR}/src/config/mnemonic.uncompressed_buffer13116.txt ./src/config/mnemonic.uncompressed_buffer13116.txt # Copy run scripts run/ # COPY --from=build ${DOCKER_WORKDIR}/run ./run diff --git a/backend/src/graphql/resolver/TransactionResolver.test.ts b/backend/src/graphql/resolver/TransactionResolver.test.ts index f4315d359..1d4fe5708 100644 --- a/backend/src/graphql/resolver/TransactionResolver.test.ts +++ b/backend/src/graphql/resolver/TransactionResolver.test.ts @@ -291,7 +291,6 @@ describe('send coins', () => { await cleanDB() }) - /* describe('trying to send negative amount', () => { it('throws an error', async () => { expect( @@ -305,18 +304,15 @@ describe('send coins', () => { }), ).toEqual( 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', () => { - expect(logger.error).toBeCalledWith( - `user hasn't enough GDD or amount is < 0 : balance=null`, - ) + expect(logger.error).toBeCalledWith(`Amount to send must be positive`) }) }) - */ describe('good transaction', () => { it('sends the coins', async () => { diff --git a/backend/src/graphql/resolver/TransactionResolver.ts b/backend/src/graphql/resolver/TransactionResolver.ts index 594039cfd..3dbd4afb9 100644 --- a/backend/src/graphql/resolver/TransactionResolver.ts +++ b/backend/src/graphql/resolver/TransactionResolver.ts @@ -314,6 +314,10 @@ export class TransactionResolver { @Ctx() context: Context, ): Promise { 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 const senderUser = getUser(context) @@ -324,22 +328,7 @@ export class TransactionResolver { // validate recipient user 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) { logger.error(`The recipient account was deleted: recipientUser=${recipientUser}`) throw new Error('The recipient account was deleted') diff --git a/backend/src/graphql/resolver/util/creations.test.ts b/backend/src/graphql/resolver/util/creations.test.ts index 8d747e989..6be317e16 100644 --- a/backend/src/graphql/resolver/util/creations.test.ts +++ b/backend/src/graphql/resolver/util/creations.test.ts @@ -170,8 +170,11 @@ describe('util/creation', () => { const targetDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 0, 0) beforeAll(() => { + const halfMsToRun = (targetDate.getTime() - now.getTime()) / 2 jest.useFakeTimers() - setTimeout(jest.fn(), targetDate.getTime() - now.getTime()) + setTimeout(jest.fn(), halfMsToRun) + jest.runAllTimers() + setTimeout(jest.fn(), halfMsToRun) jest.runAllTimers() }) @@ -225,8 +228,10 @@ describe('util/creation', () => { }) it('has the clock set correctly', () => { + const targetMonth = nextMonthTargetDate.getMonth() + 1 + const targetMonthString = (targetMonth < 10 ? '0' : '') + String(targetMonth) expect(new Date().toISOString()).toContain( - `${nextMonthTargetDate.getFullYear()}-${nextMonthTargetDate.getMonth() + 1}-01T01:`, + `${nextMonthTargetDate.getFullYear()}-${targetMonthString}-01T01:`, ) })