diff --git a/apps/api/src/campaign-application/campaign-application.service.spec.ts b/apps/api/src/campaign-application/campaign-application.service.spec.ts index 42c9cb5e..b48a5fb9 100644 --- a/apps/api/src/campaign-application/campaign-application.service.spec.ts +++ b/apps/api/src/campaign-application/campaign-application.service.spec.ts @@ -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: 'organizer@example.com', + 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') + }) + }) }) diff --git a/apps/api/src/campaign-application/campaign-application.service.ts b/apps/api/src/campaign-application/campaign-application.service.ts index 296c03a8..532bbba1 100644 --- a/apps/api/src/campaign-application/campaign-application.service.ts +++ b/apps/api/src/campaign-application/campaign-application.service.ts @@ -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' @@ -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' } diff --git a/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts b/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts index 69ad1ebc..43ad8f02 100644 --- a/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts +++ b/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts @@ -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()