Skip to content

Commit

Permalink
add create campaign agreements validation (#649)
Browse files Browse the repository at this point in the history
* 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
Martbul authored Jun 25, 2024
1 parent 7dc9b9b commit 544c19d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 4 deletions.
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
Expand All @@ -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')
})
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@nestjs/common'
import { BadRequestException, HttpException, HttpStatus, Injectable } from '@nestjs/common'
import { CreateCampaignApplicationDto } from './dto/create-campaign-application.dto'
import { UpdateCampaignApplicationDto } from './dto/update-campaign-application.dto'

Expand All @@ -9,6 +9,13 @@ export class CampaignApplicationService {
}

create(createCampaignApplicationDto: CreateCampaignApplicationDto) {
if (
!createCampaignApplicationDto.acceptTermsAndConditions ||
!createCampaignApplicationDto.transparencyTermsAccepted ||
!createCampaignApplicationDto.personalInformationProcessingAccepted
) {
throw new BadRequestException('All agreements must be checked')
}
return 'This action adds a new campaignApplication'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ export class CreateCampaignApplicationDto {
@ApiProperty()
@Expose()
@IsBoolean()
acceptTermsAndConditions: true
acceptTermsAndConditions: boolean

/** user needs to agree to this as a prerequisite to creating a campaign application */
@ApiProperty()
@Expose()
@IsBoolean()
transparencyTermsAccepted: true
transparencyTermsAccepted: boolean

/** user needs to agree to this as a prerequisite to creating a campaign application */
@ApiProperty()
@Expose()
@IsBoolean()
personalInformationProcessingAccepted: true
personalInformationProcessingAccepted: boolean

/** Who is organizing this campaign */
@ApiProperty()
Expand Down

0 comments on commit 544c19d

Please sign in to comment.