-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add create campaign agreements validation (#649)
* add create campaign agreements validation if any of the 3 agreements for creating campaign are not checked -> throw a HttpException with status 405 * fix http error status code in campaign-application.service http error code is now 400 in validation for all 3 agreements in create method * fix throw new BadRequestException changed the error from HttpException to BadRequestException for the agreements validation in create method in campaign-application.service.ts
- Loading branch information
Showing
3 changed files
with
76 additions
and
4 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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { Test, TestingModule } from '@nestjs/testing' | ||
import { CampaignApplicationService } from './campaign-application.service' | ||
import { CreateCampaignApplicationDto } from './dto/create-campaign-application.dto' | ||
import { BadRequestException, HttpStatus } from '@nestjs/common' | ||
|
||
describe('CampaignApplicationService', () => { | ||
let service: CampaignApplicationService | ||
|
@@ -15,4 +17,67 @@ describe('CampaignApplicationService', () => { | |
it('should be defined', () => { | ||
expect(service).toBeDefined() | ||
}) | ||
|
||
describe('createNewApplication', () => { | ||
const baseDto = { | ||
campaignName: 'Test Campaign', | ||
organizerName: 'Test Organizer', | ||
organizerEmail: '[email protected]', | ||
organizerPhone: '123456789', | ||
beneficiary: 'Test Beneficiary', | ||
organizerBeneficiaryRel: 'Test Relation', | ||
goal: 'Test Goal', | ||
amount: '1000', | ||
toEntity: jest.fn(), // Mock implementation | ||
} | ||
it('should throw an error if acceptTermsAndConditions are not accepted', () => { | ||
const dto: CreateCampaignApplicationDto = { | ||
...baseDto, | ||
acceptTermsAndConditions: false, | ||
transparencyTermsAccepted: true, | ||
personalInformationProcessingAccepted: true, | ||
} | ||
|
||
expect(() => service.create(dto)).toThrow( | ||
new BadRequestException('All agreements must be checked'), | ||
) | ||
}) | ||
|
||
it('should throw an error if transparencyTermsAccepted are not accepted', () => { | ||
const dto: CreateCampaignApplicationDto = { | ||
...baseDto, | ||
acceptTermsAndConditions: true, | ||
transparencyTermsAccepted: false, | ||
personalInformationProcessingAccepted: true, | ||
} | ||
|
||
expect(() => service.create(dto)).toThrow( | ||
new BadRequestException('All agreements must be checked'), | ||
) | ||
}) | ||
|
||
it('should throw an error if personalInformationProcessingAccepted is not accepted', () => { | ||
const dto: CreateCampaignApplicationDto = { | ||
...baseDto, | ||
acceptTermsAndConditions: true, | ||
transparencyTermsAccepted: true, | ||
personalInformationProcessingAccepted: false, | ||
} | ||
|
||
expect(() => service.create(dto)).toThrow( | ||
new BadRequestException('All agreements must be checked'), | ||
) | ||
}) | ||
|
||
it('should add a new campaign application if all agreements are accepted', () => { | ||
const dto: CreateCampaignApplicationDto = { | ||
...baseDto, | ||
acceptTermsAndConditions: true, | ||
transparencyTermsAccepted: true, | ||
personalInformationProcessingAccepted: true, | ||
} | ||
|
||
expect(service.create(dto)).toBe('This action adds a new campaignApplication') | ||
}) | ||
}) | ||
}) |
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