Skip to content

Commit

Permalink
fix: Connect non anonymous donation by personId
Browse files Browse the repository at this point in the history
It is not necessary for the billlingEmail to be the one of the registered user(e.g. company emails for billing)
  • Loading branch information
sashko9807 committed Nov 24, 2024
1 parent e494382 commit 4c98762
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 5 additions & 3 deletions apps/api/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export class DonationsService {
create: {
amount: paymentData.netAmount,
type: paymentData.type as DonationType,
person: paymentData.personId ? { connect: { email: paymentData.billingEmail } } : {},
person: paymentData.personId ? { connect: { id: paymentData.personId } } : {},
targetVault: targetVaultData,
},
},
Expand All @@ -928,7 +928,7 @@ export class DonationsService {
donation.amount,
tx,
)
this.notificationService.sendNotification('successfulDonation', donation)
this.notificationService.sendNotification('successfulDonation', donation.donations[0])
}

return donation
Expand Down Expand Up @@ -966,7 +966,9 @@ export class DonationsService {
},
include: { donations: true },
})
Logger.debug('Donation found by subscription: ', donation)
if (donation) {
Logger.debug('Donation found by subscription: ', donation)
}
}
return donation
}
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/sockets/notifications/notification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ export const donationNotificationSelect = Prisma.validator<Prisma.PaymentSelect>
amount: true,
extPaymentMethodId: true,
createdAt: true,

donations: {
select: {
id: true,
targetVaultId: true,
createdAt: true,
amount: true,
person: {
select: {
firstName: true,
Expand Down
3 changes: 0 additions & 3 deletions apps/api/src/stripe/stripe.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export class StripeService {
): Promise<Stripe.Response<Stripe.SetupIntent>> {
if (!inputDto.metadata.campaignId)
throw new BadRequestException('campaignId is missing from metadata')
const campaign = await this.campaignService.validateCampaignId(
inputDto.metadata.campaignId as string,
)
return await this.stripeClient.setupIntents.update(id, inputDto, { idempotencyKey })

Check failure on line 40 in apps/api/src/stripe/stripe.service.ts

View workflow job for this annotation

GitHub Actions / JEST Tests

StripeController ► StripeController should not call setupintents.update if campaign can't accept donations ► StripeController should not call setupintents.update if campaign can't accept donations

Failed test found in: test-results.xml Error: Error: expect(received).rejects.toThrow(expected)
Raw output
Error: expect(received).rejects.toThrow(expected)

Expected message: "Campaign cannot accept donations in state: complete"
Received message: "this.stripeClient.setupIntents.update is not a function"

      38 |     if (!inputDto.metadata.campaignId)
      39 |       throw new BadRequestException('campaignId is missing from metadata')
    > 40 |     return await this.stripeClient.setupIntents.update(id, inputDto, { idempotencyKey })
         |                                                 ^
      41 |   }
      42 |   /**
      43 |    * Create a payment intent for a donation

      at StripeService.updateSetupIntent (apps/api/src/stripe/stripe.service.ts:40:49)
      at StripeController.updateSetupIntent (apps/api/src/stripe/stripe.controller.ts:86:31)
      at Object.<anonymous> (apps/api/src/stripe/stripe.controller.spec.ts:215:29)
    at Object.toThrow (/home/runner/work/api/api/node_modules/expect/build/index.js:210:22)
    at Object.<anonymous> (/home/runner/work/api/api/apps/api/src/stripe/stripe.controller.spec.ts:215:88)
    at Promise.then.completed (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/utils.js:293:28)
    at new Promise (<anonymous>)
    at callAsyncCircusFn (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/utils.js:226:10)
    at _callCircusTest (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/run.js:297:40)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at _runTest (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/run.js:233:3)
    at _runTestsForDescribeBlock (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/run.js:135:9)
    at _runTestsForDescribeBlock (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/run.js:130:9)
    at run (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/run.js:68:3)
    at runAndTransformResultsToJestFormat (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:122:21)
    at jestAdapter (/home/runner/work/api/api/node_modules/@jest/core/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:79:19)
    at runTestInternal (/home/runner/work/api/api/node_modules/jest-runner/build/runTest.js:367:16)
    at runTest (/home/runner/work/api/api/node_modules/jest-runner/build/runTest.js:444:34)
    at Object.worker (/home/runner/work/api/api/node_modules/jest-runner/build/testWorker.js:106:12)
}
/**
Expand Down

0 comments on commit 4c98762

Please sign in to comment.