Skip to content

Commit

Permalink
chore: add tests for campaign application file fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
gparlakov committed Sep 29, 2024
1 parent 1e30672 commit baf0689
Show file tree
Hide file tree
Showing 227 changed files with 1,988 additions and 1,275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ describe('CampaignApplicationService', () => {
const mockS3Service = {
uploadObject: jest.fn(),
deleteObject: jest.fn(),
streamFile: jest.fn().mockResolvedValue(1234),
}

const mockEmailService = {
Expand Down Expand Up @@ -290,6 +291,18 @@ describe('CampaignApplicationService', () => {

expect(result).toEqual(mockSingleCampaignApplication)
expect(prismaMock.campaignApplication.findUnique).toHaveBeenCalledTimes(1)
expect(prismaMock.campaignApplication.findUnique).toHaveBeenCalledWith({
where: { id: 'id' },
include: {
documents: {
select: {
id: true,
filename: true,
mimetype: true,
},
},
},
})
})

it('should throw a NotFoundException if no campaign-application is found', async () => {
Expand Down Expand Up @@ -422,4 +435,68 @@ describe('CampaignApplicationService', () => {
})
})
})

describe('getFile', () => {
it('should return a single campaign-application file', async () => {
prismaMock.campaignApplication.findFirst.mockResolvedValue(mockSingleCampaignApplication)
prismaMock.campaignApplicationFile.findFirst.mockResolvedValue({
id: '123',
filename: 'my-file',
} as File)

const result = await service.getFile('id', false, mockPerson)

expect(result).toEqual({
filename: 'my-file',
stream: 1234,
})
expect(prismaMock.campaignApplication.findFirst).toHaveBeenCalledTimes(1)
expect(prismaMock.campaignApplication.findFirst).toHaveBeenCalledWith({
where: {
documents: {
some: {
id: 'id',
},
},
},
})

expect(prismaMock.campaignApplicationFile.findFirst).toHaveBeenNthCalledWith(1, {
where: { id: 'id' },
})
})

it('should throw a NotFoundException if no campaign-application is found', async () => {
prismaMock.campaignApplication.findUnique.mockResolvedValue(null)

await expect(service.getFile('id', false, mockPerson)).rejects.toThrow(
new NotFoundException('File does not exist'),
)
})

it('should handle errors and throw an exception', async () => {
const errorMessage = 'error'
prismaMock.campaignApplication.findFirst.mockRejectedValue(new Error(errorMessage))

await expect(service.getFile('id', false, mockPerson)).rejects.toThrow(errorMessage)
})

it('should not allow non-admin users to see files belonging to other users', async () => {
prismaMock.campaignApplication.findFirst.mockResolvedValue(mockSingleCampaignApplication)
await expect(
service.getFile('id', false, { ...mockPerson, organizer: { id: 'different-id' } }),
).rejects.toThrow(new ForbiddenException('User is not admin or organizer of the campaignApplication'))
})

it('should allow admin users to see files belonging to other users', async () => {
prismaMock.campaignApplication.findFirst.mockResolvedValue(mockSingleCampaignApplication)
prismaMock.campaignApplicationFile.findFirst.mockResolvedValue({
id: '123',
filename: 'my-file',
} as File)
await expect(
service.getFile('id', true, { ...mockPerson, organizer: { id: 'different-id' } }),
).resolves.not.toThrow(new ForbiddenException('User is not admin or organizer of the campaignApplication'))
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export class ConnectAffiliateDto {
id?: string
affiliateCode?: string
companyId?: string
}

export class ConnectAffiliateDto {
id?: string;
affiliateCode?: string;
companyId?: string;
}

Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@






export class CreateAffiliateDto {
affiliateCode?: string
affiliateCode?: string;
}
7 changes: 4 additions & 3 deletions apps/api/src/domain/generated/affiliate/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './connect-affiliate.dto'
export * from './create-affiliate.dto'
export * from './update-affiliate.dto'

export * from './connect-affiliate.dto';
export * from './create-affiliate.dto';
export * from './update-affiliate.dto';
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@






export class UpdateAffiliateDto {
affiliateCode?: string
affiliateCode?: string;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { AffiliateStatus } from '@prisma/client'
import { Company } from '../../company/entities/company.entity'
import { Payment } from '../../payment/entities/payment.entity'

import {AffiliateStatus} from '@prisma/client'
import {Company} from '../../company/entities/company.entity'
import {Payment} from '../../payment/entities/payment.entity'


export class Affiliate {
id: string
status: AffiliateStatus
affiliateCode: string | null
companyId: string
createdAt: Date
updatedAt: Date | null
company?: Company
payments?: Payment[]
id: string ;
status: AffiliateStatus ;
affiliateCode: string | null;
companyId: string ;
createdAt: Date ;
updatedAt: Date | null;
company?: Company ;
payments?: Payment[] ;
}
3 changes: 2 additions & 1 deletion apps/api/src/domain/generated/affiliate/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './affiliate.entity'

export * from './affiliate.entity';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export class ConnectBankAccountDto {
id: string
}

export class ConnectBankAccountDto {
id: string;
}

Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { AccountHolderType } from '@prisma/client'
import { ApiProperty } from '@nestjs/swagger'

import {AccountHolderType} from '@prisma/client'
import {ApiProperty} from '@nestjs/swagger'




export class CreateBankAccountDto {
ibanNumber: string
accountHolderName: string
@ApiProperty({ enum: AccountHolderType })
accountHolderType: AccountHolderType
bankName?: string
bankIdCode?: string
fingerprint?: string
ibanNumber: string;
accountHolderName: string;
@ApiProperty({ enum: AccountHolderType})
accountHolderType: AccountHolderType;
bankName?: string;
bankIdCode?: string;
fingerprint?: string;
}
7 changes: 4 additions & 3 deletions apps/api/src/domain/generated/bankAccount/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './connect-bankAccount.dto'
export * from './create-bankAccount.dto'
export * from './update-bankAccount.dto'

export * from './connect-bankAccount.dto';
export * from './create-bankAccount.dto';
export * from './update-bankAccount.dto';
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { AccountHolderType } from '@prisma/client'
import { ApiProperty } from '@nestjs/swagger'

import {AccountHolderType} from '@prisma/client'
import {ApiProperty} from '@nestjs/swagger'




export class UpdateBankAccountDto {
ibanNumber?: string
accountHolderName?: string
@ApiProperty({ enum: AccountHolderType })
accountHolderType?: AccountHolderType
bankName?: string
bankIdCode?: string
fingerprint?: string
ibanNumber?: string;
accountHolderName?: string;
@ApiProperty({ enum: AccountHolderType})
accountHolderType?: AccountHolderType;
bankName?: string;
bankIdCode?: string;
fingerprint?: string;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { BankAccountStatus, AccountHolderType } from '@prisma/client'
import { Withdrawal } from '../../withdrawal/entities/withdrawal.entity'

import {BankAccountStatus,AccountHolderType} from '@prisma/client'
import {Withdrawal} from '../../withdrawal/entities/withdrawal.entity'


export class BankAccount {
id: string
status: BankAccountStatus
ibanNumber: string
accountHolderName: string
accountHolderType: AccountHolderType
bankName: string | null
bankIdCode: string | null
fingerprint: string | null
createdAt: Date
updatedAt: Date | null
withdraws?: Withdrawal[]
id: string ;
status: BankAccountStatus ;
ibanNumber: string ;
accountHolderName: string ;
accountHolderType: AccountHolderType ;
bankName: string | null;
bankIdCode: string | null;
fingerprint: string | null;
createdAt: Date ;
updatedAt: Date | null;
withdraws?: Withdrawal[] ;
}
3 changes: 2 additions & 1 deletion apps/api/src/domain/generated/bankAccount/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './bankAccount.entity'

export * from './bankAccount.entity';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export class ConnectBankTransactionDto {
id: string
}

export class ConnectBankTransactionDto {
id: string;
}

Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import { BankTransactionType, BankDonationStatus } from '@prisma/client'
import { ApiProperty } from '@nestjs/swagger'

import {BankTransactionType,BankDonationStatus} from '@prisma/client'
import {ApiProperty} from '@nestjs/swagger'




export class CreateBankTransactionDto {
id: string
ibanNumber: string
bankName: string
bankIdCode: string
transactionDate: Date
senderName?: string
recipientName?: string
senderIban?: string
recipientIban?: string
description: string
matchedRef?: string
@ApiProperty({ enum: BankTransactionType })
type: BankTransactionType
@ApiProperty({ enum: BankDonationStatus })
bankDonationStatus?: BankDonationStatus
notified?: boolean
id: string;
ibanNumber: string;
bankName: string;
bankIdCode: string;
transactionDate: Date;
senderName?: string;
recipientName?: string;
senderIban?: string;
recipientIban?: string;
description: string;
matchedRef?: string;
@ApiProperty({ enum: BankTransactionType})
type: BankTransactionType;
@ApiProperty({ enum: BankDonationStatus})
bankDonationStatus?: BankDonationStatus;
notified?: boolean;
}
7 changes: 4 additions & 3 deletions apps/api/src/domain/generated/bankTransaction/dto/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './connect-bankTransaction.dto'
export * from './create-bankTransaction.dto'
export * from './update-bankTransaction.dto'

export * from './connect-bankTransaction.dto';
export * from './create-bankTransaction.dto';
export * from './update-bankTransaction.dto';
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import { BankTransactionType, BankDonationStatus } from '@prisma/client'
import { ApiProperty } from '@nestjs/swagger'

import {BankTransactionType,BankDonationStatus} from '@prisma/client'
import {ApiProperty} from '@nestjs/swagger'




export class UpdateBankTransactionDto {
ibanNumber?: string
bankName?: string
bankIdCode?: string
transactionDate?: Date
senderName?: string
recipientName?: string
senderIban?: string
recipientIban?: string
description?: string
matchedRef?: string
@ApiProperty({ enum: BankTransactionType })
type?: BankTransactionType
@ApiProperty({ enum: BankDonationStatus })
bankDonationStatus?: BankDonationStatus
notified?: boolean
ibanNumber?: string;
bankName?: string;
bankIdCode?: string;
transactionDate?: Date;
senderName?: string;
recipientName?: string;
senderIban?: string;
recipientIban?: string;
description?: string;
matchedRef?: string;
@ApiProperty({ enum: BankTransactionType})
type?: BankTransactionType;
@ApiProperty({ enum: BankDonationStatus})
bankDonationStatus?: BankDonationStatus;
notified?: boolean;
}
Loading

0 comments on commit baf0689

Please sign in to comment.