Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add create campaign agreements validation #649

Merged
merged 3 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading