diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index deb5d05f..c356c440 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -1,8 +1,6 @@ -version: '3.8' - services: db: - image: postgres + image: postgres:16-alpine container_name: petjournal_db restart: always ports: diff --git a/src/application/controllers/signup.ts b/src/application/controllers/signup.ts index 82cfd86b..e2a1ea60 100644 --- a/src/application/controllers/signup.ts +++ b/src/application/controllers/signup.ts @@ -29,13 +29,15 @@ export class SignUpController implements Controller { } const { firstName, lastName, email, phone, password } = httpRequest.body + const image = httpRequest.file ?? null const guardian = await this.addGuardian.add({ firstName, lastName, email, phone, password, - verificationToken: '' + verificationToken: '', + image }) if (!guardian) { diff --git a/src/data/protocols/db/guardian/index.ts b/src/data/protocols/db/guardian/index.ts index a6237ba9..a7b35cd9 100644 --- a/src/data/protocols/db/guardian/index.ts +++ b/src/data/protocols/db/guardian/index.ts @@ -7,3 +7,4 @@ export * from './update-verification-token-repository' export * from './update-guardian-password-repository' export * from './save-token-repository' export * from './update-email-confirmation-repository' +export * from './update-guardian-image-repository' diff --git a/src/data/protocols/db/guardian/update-guardian-image-repository.ts b/src/data/protocols/db/guardian/update-guardian-image-repository.ts new file mode 100644 index 00000000..98561453 --- /dev/null +++ b/src/data/protocols/db/guardian/update-guardian-image-repository.ts @@ -0,0 +1,19 @@ +export interface UpdateGuardianImageRepository { + updateImage: (params: UpdateGuardianImageRepository.Params) => Promise +} + +export namespace UpdateGuardianImageRepository { + export type Params = { + guardianId: string + image?: string + } + + export type Result = { + id: string + firstName: string + lastName: string + email: string + phone: string + image: string + } | undefined +} diff --git a/src/data/use-cases/db-add-guardian.ts b/src/data/use-cases/db-add-guardian.ts index 4e84e346..c8414903 100644 --- a/src/data/use-cases/db-add-guardian.ts +++ b/src/data/use-cases/db-add-guardian.ts @@ -1,17 +1,43 @@ import { type AddGuardian } from '@/domain/use-cases' -import { type AddGuardianRepository, type HashGenerator } from '@/data/protocols' +import { type FileStorage, type AddGuardianRepository, type HashGenerator, type UpdateGuardianImageRepository } from '@/data/protocols' export class DbAddGuardian implements AddGuardian { - private readonly guardianRepository: AddGuardianRepository + private readonly guardianRepository: AddGuardianRepository & UpdateGuardianImageRepository private readonly hashService: HashGenerator + private readonly fileStorage: FileStorage + private readonly defaultGuardianImageUrl: string - constructor ({ guardianRepository, hashService }: AddGuardian.Dependencies) { + constructor ({ guardianRepository, hashService, fileStorage, defaultGuardianImageUrl }: AddGuardian.Dependencies) { this.guardianRepository = guardianRepository this.hashService = hashService + this.fileStorage = fileStorage + this.defaultGuardianImageUrl = defaultGuardianImageUrl } async add (guardianData: AddGuardian.Params): Promise { const hashedPassword = await this.hashService.encrypt({ value: guardianData.password }) - return await this.guardianRepository.add(Object.assign({}, guardianData, { password: hashedPassword })) + const guardian = await this.guardianRepository.add(Object.assign({}, { ...guardianData, image: '' }, { password: hashedPassword })) + + if (!guardian) { + return undefined + } + + let imageUrl: string = '' + if (guardianData.image) { + imageUrl = await this.fileStorage.save({ file: guardianData.image, fileName: `images/guardian-${guardian?.id}` }) + } + + if (imageUrl) { + await this.guardianRepository.updateImage({ guardianId: guardian?.id, image: imageUrl }) + } + + return { + id: guardian?.id, + email: guardian?.email, + firstName: guardian?.firstName, + lastName: guardian?.lastName, + phone: guardian?.phone, + image: imageUrl ?? this.defaultGuardianImageUrl + } } } diff --git a/src/data/use-cases/pet/db-add-pet.ts b/src/data/use-cases/pet/db-add-pet.ts index 8b28cca2..2aa09220 100644 --- a/src/data/use-cases/pet/db-add-pet.ts +++ b/src/data/use-cases/pet/db-add-pet.ts @@ -17,20 +17,20 @@ export class DbAddPet implements AddPet { private readonly petRepository: AddPetRepository & UpdatePetRepository private readonly appointPet: AppointPet private readonly fileStorage: FileStorage - private readonly defaultImageUrl: string + private readonly defaultPetImageUrl: string constructor ({ guardianRepository, petRepository, appointPet, fileStorage, - defaultImageUrl + defaultPetImageUrl }: AddPet.Dependencies) { this.guardianRepository = guardianRepository this.petRepository = petRepository this.appointPet = appointPet this.fileStorage = fileStorage - this.defaultImageUrl = defaultImageUrl + this.defaultPetImageUrl = defaultPetImageUrl } async add (petData: AddPet.Params): Promise { @@ -96,7 +96,7 @@ export class DbAddPet implements AddPet { size: pet?.size as Size & { id: string }, castrated: pet?.castrated as boolean, dateOfBirth: pet?.dateOfBirth as Date, - image: imageUrl || this.defaultImageUrl + image: imageUrl || this.defaultPetImageUrl } } } diff --git a/src/domain/use-cases/add-guardian.ts b/src/domain/use-cases/add-guardian.ts index b82631b6..108df38b 100644 --- a/src/domain/use-cases/add-guardian.ts +++ b/src/domain/use-cases/add-guardian.ts @@ -1,4 +1,5 @@ -import { type AddGuardianRepository, type HashGenerator } from '@/data/protocols' +import { type FileStorage, type AddGuardianRepository, type HashGenerator } from '@/data/protocols' +import { type UpdateGuardianImageRepository } from '@/data/protocols/db/guardian/update-guardian-image-repository' export interface AddGuardian { add: (guardianData: AddGuardian.Params) => Promise @@ -12,6 +13,7 @@ export namespace AddGuardian { phone: string password: string verificationToken: string + image: Buffer | null } export type Result = { @@ -20,10 +22,13 @@ export namespace AddGuardian { lastName: string email: string phone: string + image: string } | undefined export type Dependencies = { - guardianRepository: AddGuardianRepository + guardianRepository: AddGuardianRepository & UpdateGuardianImageRepository hashService: HashGenerator + fileStorage: FileStorage + defaultGuardianImageUrl: string } } diff --git a/src/domain/use-cases/pet/add-pet.ts b/src/domain/use-cases/pet/add-pet.ts index 5a5c5fdd..4e013753 100644 --- a/src/domain/use-cases/pet/add-pet.ts +++ b/src/domain/use-cases/pet/add-pet.ts @@ -58,6 +58,6 @@ export namespace AddPet { petRepository: AddPetRepository & UpdatePetRepository appointPet: AppointPet fileStorage: FileStorage - defaultImageUrl: string + defaultPetImageUrl: string } } diff --git a/src/infra/repos/postgresql/guardian-account-repository.ts b/src/infra/repos/postgresql/guardian-account-repository.ts index 21c6860f..b86bcfb5 100644 --- a/src/infra/repos/postgresql/guardian-account-repository.ts +++ b/src/infra/repos/postgresql/guardian-account-repository.ts @@ -1,3 +1,4 @@ +import { type UpdateGuardianImageRepository } from '@/data/protocols/db/guardian/update-guardian-image-repository' import { prisma as db } from './prisma' import { type AddGuardianRepository, @@ -15,7 +16,8 @@ implements AddGuardianRepository, LoadGuardianByEmailRepository, UpdateAccessTokenRepository, UpdateGuardianPasswordRepository, UpdateVerificationTokenRepository, - UpdateEmailConfirmationRepository { + UpdateEmailConfirmationRepository, + UpdateGuardianImageRepository { async add ( guardianData: AddGuardianRepository.Params ): Promise { @@ -136,4 +138,19 @@ implements AddGuardianRepository, LoadGuardianByEmailRepository, return result.emailConfirmation } + + async updateImage (params: UpdateGuardianImageRepository.Params): Promise { + const { guardianId, image } = params + const result = await db.guardian.update({ + where: { id: guardianId }, + data: { image }, + omit: { + password: true, + verificationToken: true, + verificationTokenCreatedAt: true + } + }) + + return result + } } diff --git a/src/infra/repos/postgresql/prisma/migrations/20260207183158_add_image_guardian/migration.sql b/src/infra/repos/postgresql/prisma/migrations/20260207183158_add_image_guardian/migration.sql new file mode 100644 index 00000000..765fb8fa --- /dev/null +++ b/src/infra/repos/postgresql/prisma/migrations/20260207183158_add_image_guardian/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "guardians" ADD COLUMN "image" TEXT NOT NULL DEFAULT ''; diff --git a/src/infra/repos/postgresql/prisma/schema.prisma b/src/infra/repos/postgresql/prisma/schema.prisma index 9278fe1e..79ea4dee 100644 --- a/src/infra/repos/postgresql/prisma/schema.prisma +++ b/src/infra/repos/postgresql/prisma/schema.prisma @@ -19,6 +19,7 @@ model Guardian { verificationToken String @map("verification_token") verificationTokenCreatedAt DateTime @default(now()) @map("verification_token_created_at") emailConfirmation Boolean @default(false) @map("email_confirmation") + image String @default("") pets Pet[] tags Tag[] scheduler Scheduler[] diff --git a/src/main/config/env.ts b/src/main/config/env.ts index c1279585..8e7aa0be 100644 --- a/src/main/config/env.ts +++ b/src/main/config/env.ts @@ -14,7 +14,8 @@ export default { firebase: { projectId: process.env.FIREBASE_PROJECT_ID ?? '', storageBucket: process.env.FIREBASE_STORAGE_BUCKET ?? '', - defaultImageUrl: process.env.FIREBASE_DEFAULT_IMAGE_URL ?? '' + defaultPetImageUrl: process.env.FIREBASE_DEFAULT_PET_IMAGE_URL ?? '', + defaultGuardianImageUrl: process.env.FIREBASE_DEFAULT_GUARDIAN_IMAGE_URL ?? '' }, mailerooApiKey: process.env.MAILEROO_API_KEY ?? '', mailerooApiSenderUrl: process.env.MAILEROO_API_URL ?? '', diff --git a/src/main/docs/paths/signup-path.ts b/src/main/docs/paths/signup-path.ts index a965e7e3..c59bf01b 100644 --- a/src/main/docs/paths/signup-path.ts +++ b/src/main/docs/paths/signup-path.ts @@ -3,14 +3,42 @@ import { DocBuilder } from '../utils/doc-builder' export const signUpPath = DocBuilder.postBuilder() .addTags(['guardian']) .addSummary('adds a new guardian') - .addJsonBody('#/schemas/signUpParams', true, { - firstName: 'John', - lastName: 'Doe', - email: 'johndoe@email.com', - password: 'Teste@123', - passwordConfirmation: 'Teste@123', - phone: '11987654321', - isPrivacyPolicyAccepted: true + .addMultipartFormDataBody({ + type: 'object', + properties: { + firstName: { + type: 'string', + example: 'John' + }, + lastName: { + type: 'string', + example: 'Doe' + }, + email: { + type: 'string', + example: 'johndoe@email.com' + }, + password: { + type: 'string', + example: 'Teste@123' + }, + passwordConfirmation: { + type: 'string', + example: 'Teste@123' + }, + phone: { + type: 'string', + example: '11987654321' + }, + isPrivacyPolicyAccepted: { + type: 'boolean', + example: true + }, + image: { + type: 'string', + format: 'binary' + } + } }) .addResponse(201, { description: 'Success', diff --git a/src/main/docs/schemas/guardian-schema.ts b/src/main/docs/schemas/guardian-schema.ts index 46b1b297..1ec2ce8f 100644 --- a/src/main/docs/schemas/guardian-schema.ts +++ b/src/main/docs/schemas/guardian-schema.ts @@ -13,6 +13,9 @@ export const guardianSchema = { }, phone: { type: 'string' + }, + image: { + type: 'binary' } } } diff --git a/src/main/docs/schemas/signup-params-schema.ts b/src/main/docs/schemas/signup-params-schema.ts index c91661a9..8dd161fb 100644 --- a/src/main/docs/schemas/signup-params-schema.ts +++ b/src/main/docs/schemas/signup-params-schema.ts @@ -21,6 +21,9 @@ export const signUpParamsSchema = { }, isPrivacyPolicyAccepted: { type: 'boolean' + }, + image: { + type: 'binary' } } } diff --git a/src/main/factories/usecases/db-add-guardian-factory.ts b/src/main/factories/usecases/db-add-guardian-factory.ts index 0318a7fc..0475d9a3 100644 --- a/src/main/factories/usecases/db-add-guardian-factory.ts +++ b/src/main/factories/usecases/db-add-guardian-factory.ts @@ -3,14 +3,19 @@ import { type AddGuardian } from '@/domain/use-cases' import { BcryptAdapter } from '@/infra/cryptography' import { GuardianAccountRepository } from '@/infra/repos/postgresql' import { DbAddGuardian } from '@/data/use-cases' +import { FirebaseStorageAdapter } from '@/infra/repos/firebase' export const makeDbAddGuardian = (): AddGuardian => { const salt = Number(env.salt) const hashService = new BcryptAdapter(salt) const guardianRepository = new GuardianAccountRepository() + const fileStorage = new FirebaseStorageAdapter(env.firebase.projectId, env.firebase.storageBucket) + const defaultGuardianImageUrl = env.firebase.defaultGuardianImageUrl const addGuardian = new DbAddGuardian({ + fileStorage, guardianRepository, - hashService + hashService, + defaultGuardianImageUrl }) return addGuardian } diff --git a/src/main/factories/usecases/pet/db-add-pet-factory.ts b/src/main/factories/usecases/pet/db-add-pet-factory.ts index 525c5e38..baad021f 100644 --- a/src/main/factories/usecases/pet/db-add-pet-factory.ts +++ b/src/main/factories/usecases/pet/db-add-pet-factory.ts @@ -10,13 +10,13 @@ export const makeDbAddPet = (): AddPet => { const petRepository = new PetRepository() const appointPet = makeDbAppointPet() const fileStorage = new FirebaseStorageAdapter(env.firebase.projectId, env.firebase.storageBucket) - const defaultImageUrl = env.firebase.defaultImageUrl + const defaultPetImageUrl = env.firebase.defaultPetImageUrl const addPet = new DbAddPet({ guardianRepository, petRepository, appointPet, fileStorage, - defaultImageUrl + defaultPetImageUrl }) return addPet } diff --git a/src/main/routes/signup-routes.ts b/src/main/routes/signup-routes.ts index cf9a7409..3cbfd468 100644 --- a/src/main/routes/signup-routes.ts +++ b/src/main/routes/signup-routes.ts @@ -1,7 +1,8 @@ import { type Router } from 'express' import { adaptRoute } from '@/main/adapters' import { makeSignUpController } from '@/main/factories' +import { upload } from '../middlewares' export default (router: Router): void => { - router.post('/signup', adaptRoute(makeSignUpController())) + router.post('/signup', upload, adaptRoute(makeSignUpController())) } diff --git a/tests/helpers/prisma-helper.ts b/tests/helpers/prisma-helper.ts index 8a6b13b0..fbb38004 100644 --- a/tests/helpers/prisma-helper.ts +++ b/tests/helpers/prisma-helper.ts @@ -75,7 +75,8 @@ export const PrismaHelper = { password: await bcryptAdapter.encrypt({ value: 'Test@1234' }), phone: '11987654321', emailConfirmation: true, - verificationToken: '' + verificationToken: '', + image: '' } }) }, diff --git a/tests/src/application/controllers/signup.spec.ts b/tests/src/application/controllers/signup.spec.ts index 7c6e5fd7..995bb694 100644 --- a/tests/src/application/controllers/signup.spec.ts +++ b/tests/src/application/controllers/signup.spec.ts @@ -59,7 +59,8 @@ describe('SignUp Controller', () => { email: httpRequest.body.email, password: httpRequest.body.password, phone: httpRequest.body.phone, - verificationToken: '' + verificationToken: '', + image: httpRequest.file }) }) }) diff --git a/tests/src/data/use-cases/db-add-guardian.spec.ts b/tests/src/data/use-cases/db-add-guardian.spec.ts index 273a2702..ef6082af 100644 --- a/tests/src/data/use-cases/db-add-guardian.spec.ts +++ b/tests/src/data/use-cases/db-add-guardian.spec.ts @@ -1,7 +1,7 @@ import { type AddGuardian } from '@/domain/use-cases' import { type AddGuardianRepository, type HashGenerator } from '@/data/protocols' import { DbAddGuardian } from '@/data/use-cases' -import { makeFakeGuardianRepository, makeFakeHashService, mockHashService } from '@/tests/utils' +import { makeFakeFileStorage, makeFakeGuardianRepository, makeFakeHashService, mockHashService } from '@/tests/utils' interface SutTypes { sut: DbAddGuardian @@ -12,9 +12,13 @@ interface SutTypes { const makeSut = (): SutTypes => { const guardianRepositoryStub = makeFakeGuardianRepository() const hashServiceStub = makeFakeHashService() + const defaultGuardianImageUrlStub = 'any_url' + const fileStorageStub = makeFakeFileStorage() const dependencies: AddGuardian.Dependencies = { hashService: hashServiceStub, - guardianRepository: guardianRepositoryStub + guardianRepository: guardianRepositoryStub, + fileStorage: fileStorageStub, + defaultGuardianImageUrl: defaultGuardianImageUrlStub } const sut = new DbAddGuardian(dependencies) return { @@ -25,13 +29,14 @@ const makeSut = (): SutTypes => { } describe('DbAddGuardian use case', () => { - const params: AddGuardianRepository.Params = { + const params: AddGuardian.Params = { firstName: 'any_first_name', lastName: 'any_last_name', email: 'any_email@mail.com', password: 'any_password', phone: 'any_phone', - verificationToken: 'any_verification' + verificationToken: 'any_verification', + image: null } describe('HashService', () => { @@ -61,7 +66,8 @@ describe('DbAddGuardian use case', () => { email: params.email, password: mockHashService.hashedValue, phone: params.phone, - verificationToken: params.verificationToken + verificationToken: params.verificationToken, + image: '' }) }) @@ -80,7 +86,7 @@ describe('DbAddGuardian use case', () => { }) }) - test('Should return a guardian when saving the user successfully', async () => { + it('Should return a guardian when saving the user successfully', async () => { const { sut } = makeSut() const result = await sut.add(params) as any expect(result).toEqual({ @@ -88,7 +94,8 @@ describe('DbAddGuardian use case', () => { firstName: params.firstName, lastName: params.lastName, email: params.email, - phone: params.phone + phone: params.phone, + image: '' }) }) }) diff --git a/tests/src/data/use-cases/pet/db-add-pet.spec.ts b/tests/src/data/use-cases/pet/db-add-pet.spec.ts index 7e9b190d..155b3f38 100644 --- a/tests/src/data/use-cases/pet/db-add-pet.spec.ts +++ b/tests/src/data/use-cases/pet/db-add-pet.spec.ts @@ -28,14 +28,14 @@ const makeSut = (): SutTypes => { const petRepositoryStub = makeFakePetRepository() const appointPetStub = makeFakeAppointPetUseCase() const fileStorageStub = makeFakeFileStorage() - const defaultImageUrl = 'any_url' + const defaultPetImageUrl = 'any_url' const sut = new DbAddPet({ guardianRepository: guardianRepositoryStub, petRepository: petRepositoryStub, appointPet: appointPetStub, fileStorage: fileStorageStub, - defaultImageUrl + defaultPetImageUrl }) return { diff --git a/tests/src/main/routes/pet-routes.test.ts b/tests/src/main/routes/pet-routes.test.ts index e9a3bc1e..4e7fbb38 100644 --- a/tests/src/main/routes/pet-routes.test.ts +++ b/tests/src/main/routes/pet-routes.test.ts @@ -150,6 +150,7 @@ describe('Pet Routes', () => { Reflect.deleteProperty(fakeUser, 'accessToken') Reflect.deleteProperty(fakeUser, 'verificationToken') Reflect.deleteProperty(fakeUser, 'verificationTokenCreatedAt') + Reflect.deleteProperty(fakeUser, 'image') }) beforeEach(async () => { await prisma.pet.deleteMany() }) diff --git a/tests/src/main/routes/signup-routes.test.ts b/tests/src/main/routes/signup-routes.test.ts index 1222ebd3..60e410b6 100644 --- a/tests/src/main/routes/signup-routes.test.ts +++ b/tests/src/main/routes/signup-routes.test.ts @@ -1,5 +1,6 @@ import request from 'supertest' import app from '@/main/config/app' +import path from 'node:path' import { PrismaHelper } from '@/tests/helpers/prisma-helper' describe('SignUp Routes', () => { @@ -9,35 +10,34 @@ describe('SignUp Routes', () => { afterAll(async () => { await PrismaHelper.disconnect() }) + const image = path.join(__dirname, '..', '..', '..', 'utils', 'images', 'guardian.jpg') it('Should return 409 if guardian already exists on database', async () => { await PrismaHelper.createGuardian() await request(app) .post('/api/signup') - .send({ - firstName: 'John', - lastName: 'Doe', - email: 'johndoe@email.com', - password: 'Test@1234', - passwordConfirmation: 'Test@1234', - phone: '11987654321', - isPrivacyPolicyAccepted: true - }) + .field('firstName', 'John') + .field('lastName', 'Doe') + .field('email', 'johndoe@email.com') + .field('password', 'Test@1234') + .field('passwordConfirmation', 'Test@1234') + .field('phone', '11987654321') + .field('isPrivacyPolicyAccepted', 'true') + .attach('image', image) .expect(409) }) it('Should return a guardian account on success', async () => { await request(app) .post('/api/signup') - .send({ - firstName: 'John', - lastName: 'Doe', - email: 'johndoe@email.com', - password: 'Test@1234', - passwordConfirmation: 'Test@1234', - phone: '11987654321', - isPrivacyPolicyAccepted: true - }) + .field('firstName', 'John') + .field('lastName', 'Doe') + .field('email', 'johndoe@email.com') + .field('password', 'Test@1234') + .field('passwordConfirmation', 'Test@1234') + .field('phone', '11987654321') + .field('isPrivacyPolicyAccepted', 'true') + .attach('image', image) .expect(201) }) }) diff --git a/tests/utils/images/guardian.jpg b/tests/utils/images/guardian.jpg new file mode 100644 index 00000000..de182163 Binary files /dev/null and b/tests/utils/images/guardian.jpg differ diff --git a/tests/utils/mocks/entities.mocks.ts b/tests/utils/mocks/entities.mocks.ts index 4e09ea3c..8e609b6f 100644 --- a/tests/utils/mocks/entities.mocks.ts +++ b/tests/utils/mocks/entities.mocks.ts @@ -10,7 +10,8 @@ import { type LoadDogBreedsRepository, type LoadPetByGuardianIdRepository, type LoadPetByIdRepository, - type DeletePetByIdRepository + type DeletePetByIdRepository, + type UpdateGuardianImageRepository } from '@/data/protocols' import { type AppointPet } from '@/domain/use-cases' import { type Guardian } from '@/tests/utils/types' @@ -41,6 +42,17 @@ const mockFakeGuardianAdded = (): Exclude => { + return { + id: 'any_id', + firstName: 'any_first_name', + lastName: 'any_last_name', + email: 'any_email@mail.com', + phone: 'any_phone', + image: 'any_image' + } +} + const mockFakePetAdded = (): AddPetRepository.Result => { return { id: 'any_id', @@ -195,6 +207,7 @@ const mockFakeGuardianLoaded = (): Exclude { passwordConfirmation: mockGuardianRequest.passwordConfirmation, phone: mockGuardianRequest.phone } + const file = Buffer.from('any_image') - return { body } + return { body, file } } const makeFakeForgetPasswordRequest = (): ForgetPasswordRequest => { diff --git a/tests/utils/stubs/service.stub.ts b/tests/utils/stubs/service.stub.ts index fd9f9228..01a4e530 100644 --- a/tests/utils/stubs/service.stub.ts +++ b/tests/utils/stubs/service.stub.ts @@ -7,7 +7,8 @@ import { mockFakePetByGuardianIdLoaded, mockFakePetByIdLoaded, mockFakePetUpdated, - mockFakePetByIdDeleted + mockFakePetByIdDeleted, + mockFakeGuardianUpdated } from '@/tests/utils' import { type EmailService, @@ -47,7 +48,8 @@ import { type DeleteSchedulerByIdRepository, type LoadSettingsRepository, type UpdateSettingsRepository, - type LoadNextTasksByPetIdAndTagIdRepository + type LoadNextTasksByPetIdAndTagIdRepository, + type UpdateGuardianImageRepository } from '@/data/protocols' import { type LoadCatSizesRepository } from '@/data/protocols/db/size/load-cat-sizes-repository' import { type LoadDogSizesRepository } from '@/data/protocols/db/size/load-dog-sizes-repository' @@ -69,7 +71,8 @@ LoadGuardianByIdRepository & UpdateAccessTokenRepository & UpdateGuardianPasswordRepository & UpdateVerificationTokenRepository & -UpdateEmailConfirmationRepository => { +UpdateEmailConfirmationRepository & +UpdateGuardianImageRepository => { class GuardianRepositoryStub implements AddGuardianRepository, LoadGuardianByEmailRepository, @@ -77,7 +80,8 @@ UpdateEmailConfirmationRepository => { UpdateAccessTokenRepository, UpdateGuardianPasswordRepository, UpdateVerificationTokenRepository, - UpdateEmailConfirmationRepository { + UpdateEmailConfirmationRepository, + UpdateGuardianImageRepository { async add (guardian: AddGuardianRepository.Params): Promise { return mockFakeGuardianAdded() } @@ -105,6 +109,10 @@ UpdateEmailConfirmationRepository => { async updateEmailConfirmation (userId: UpdateEmailConfirmationRepository.Params): Promise { return true } + + async updateImage (params: UpdateGuardianImageRepository.Params): Promise { + return mockFakeGuardianUpdated() + } } return new GuardianRepositoryStub() } diff --git a/tests/utils/stubs/use-case.stub.ts b/tests/utils/stubs/use-case.stub.ts index 801a6169..2266b9a3 100644 --- a/tests/utils/stubs/use-case.stub.ts +++ b/tests/utils/stubs/use-case.stub.ts @@ -38,7 +38,8 @@ const mockGuardianUseCase = { email: 'any_email@mail.com', password: 'any_password', phone: 'any_phone', - accessToken: 'any_token' + accessToken: 'any_token', + image: '' } const makeFakeAddGuardianUseCase = (): AddGuardian => { @@ -50,7 +51,8 @@ const makeFakeAddGuardianUseCase = (): AddGuardian => { lastName: mockGuardianUseCase.lastName, email: mockGuardianUseCase.email, password: mockGuardianUseCase.password, - phone: mockGuardianUseCase.phone + phone: mockGuardianUseCase.phone, + image: mockGuardianUseCase.image } return result } diff --git a/tests/utils/types/request.type.ts b/tests/utils/types/request.type.ts index a033c017..c2f214b6 100644 --- a/tests/utils/types/request.type.ts +++ b/tests/utils/types/request.type.ts @@ -18,6 +18,7 @@ interface SignUpRequest { passwordConfirmation: string phone: string } + file?: Buffer } interface ForgetPasswordRequest {