-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stripe): Don't initiate intent/subscription if campaign is compl…
…eted
- Loading branch information
1 parent
7367091
commit 2c9fee9
Showing
3 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,10 @@ import { VaultService } from '../vault/vault.service' | |
import { ExportService } from '../export/export.service' | ||
import { NotificationModule } from '../sockets/notifications/notification.module' | ||
import { CACHE_MANAGER } from '@nestjs/cache-manager' | ||
|
||
import { CreateSubscriptionPaymentDto } from './dto/create-subscription-payment.dto' | ||
import { mockDeep } from 'jest-mock-extended' | ||
import { Grant } from 'keycloak-connect' | ||
import { KeycloakTokenParsed } from '../auth/keycloak' | ||
describe('StripeController', () => { | ||
let controller: StripeController | ||
|
||
|
@@ -182,4 +185,45 @@ describe('StripeController', () => { | |
reason: 'requested_by_customer', | ||
}) | ||
}) | ||
it(`should not call setupintents.update if campaign can't accept donations`, async () => { | ||
prismaMock.campaign.findFirst.mockResolvedValue({ | ||
id: 'complete-campaign', | ||
allowDonationOnComplete: false, | ||
state: CampaignState.complete, | ||
} as Campaign) | ||
|
||
const payload = { | ||
metadata: { | ||
campaignId: 'complete-campaign', | ||
}, | ||
} | ||
|
||
await expect(controller.updateSetupIntent('123', payload)).rejects.toThrow( | ||
new NotAcceptableException('Campaign cannot accept donations in state: complete'), | ||
) | ||
}) | ||
it(`should not call subscription.create if campaign can't accept donations`, async () => { | ||
prismaMock.campaign.findFirst.mockResolvedValue({ | ||
id: 'complete-campaign', | ||
allowDonationOnComplete: false, | ||
state: CampaignState.complete, | ||
} as Campaign) | ||
|
||
const user: KeycloakTokenParsed = { | ||
sub: '00000000-0000-0000-0000-000000000013', | ||
'allowed-origins': [], | ||
email: '[email protected]', | ||
} | ||
const subscribtionObj: CreateSubscriptionPaymentDto = { | ||
type: 'donation', | ||
email: '[email protected]', | ||
campaignId: 'complete-campaign', | ||
amount: 200, | ||
currency: 'BGN', | ||
} | ||
|
||
await expect(controller.createSubscription(user, subscribtionObj)).rejects.toThrow( | ||
new NotAcceptableException('Campaign cannot accept donations in state: complete'), | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters