-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #789 from hngprojects/dev
Merge dev branch into staging
- Loading branch information
Showing
11 changed files
with
228 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,4 +190,4 @@ export class HelpCenterController { | |
} | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { IsString, IsOptional } from 'class-validator'; | ||
import { ApiPropertyOptional } from '@nestjs/swagger'; | ||
|
||
export class UpdateTestimonialDto { | ||
@ApiPropertyOptional({ description: 'Updated content of the testimonial' }) | ||
@IsString() | ||
@IsOptional() | ||
content?: string; | ||
|
||
@ApiPropertyOptional({ description: 'Updated name associated with the testimonial' }) | ||
@IsString() | ||
@IsOptional() | ||
name?: string; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/modules/testimonials/dto/update-testimonial.response.dto.ts
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export class UpdateTestimonialResponseDto { | ||
status: string; | ||
message: string; | ||
data: any; | ||
} | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { InternalServerErrorException, NotFoundException, HttpStatus } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { getRepositoryToken } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { Profile } from '../../profile/entities/profile.entity'; | ||
import { User } from '../../user/entities/user.entity'; | ||
import UserService from '../../user/user.service'; | ||
import { UpdateTestimonialDto } from '../dto/update-testimonial.dto'; | ||
import { Testimonial } from '../entities/testimonials.entity'; | ||
import { TestimonialsService } from '../testimonials.service'; | ||
|
||
describe('TestimonialsService', () => { | ||
let service: TestimonialsService; | ||
let userService: UserService; | ||
let testimonialRepository: Repository<Testimonial>; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
TestimonialsService, | ||
UserService, | ||
{ | ||
provide: getRepositoryToken(Testimonial), | ||
useClass: Repository, | ||
}, | ||
{ | ||
provide: getRepositoryToken(User), | ||
useClass: Repository, | ||
}, | ||
{ | ||
provide: getRepositoryToken(Profile), | ||
useClass: Repository, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<TestimonialsService>(TestimonialsService); | ||
userService = module.get<UserService>(UserService); | ||
testimonialRepository = module.get<Repository<Testimonial>>(getRepositoryToken(Testimonial)); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
describe('updateTestimonial', () => { | ||
it('should successfully update a testimonial', async () => { | ||
const id = 'testimonial_id'; | ||
const updateTestimonialDto: UpdateTestimonialDto = { | ||
name: 'Updated Name', | ||
content: 'Updated content!', | ||
}; | ||
const userId = 'user_id'; | ||
const testimonial = { id, user: { id: userId }, ...updateTestimonialDto } as Testimonial; | ||
|
||
jest.spyOn(testimonialRepository, 'findOne').mockResolvedValue(testimonial); | ||
jest.spyOn(testimonialRepository, 'save').mockResolvedValue(testimonial); | ||
|
||
const result = await service.updateTestimonial(id, updateTestimonialDto, userId); | ||
|
||
expect(result).toEqual({ | ||
id, | ||
user_id: userId, | ||
...updateTestimonialDto, | ||
updated_at: expect.any(Date), | ||
}); | ||
}); | ||
|
||
it('should throw a NotFoundException if testimonial is not found', async () => { | ||
const id = 'testimonial_id'; | ||
const updateTestimonialDto: UpdateTestimonialDto = { | ||
name: 'Updated Name', | ||
content: 'Updated content!', | ||
}; | ||
const userId = 'user_id'; | ||
|
||
jest.spyOn(testimonialRepository, 'findOne').mockResolvedValue(null); | ||
|
||
await expect(service.updateTestimonial(id, updateTestimonialDto, userId)).rejects.toThrow( | ||
new NotFoundException('Testimonial not found') | ||
); | ||
}); | ||
}); | ||
}); |