-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add DeleteUserAccountsService to account services
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/features/account/services/delete-user-accounts-service.test.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,38 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
import { AccountMock } from '@/shared/test-helpers/mocks/account.mock.js'; | ||
import { DeleteUserAccountsService } from './delete-user-accounts-service.js'; | ||
import { BadRequestError } from '@/shared/errors/bad-request-error.js'; | ||
|
||
const makeSut = () => { | ||
const accountRepository = { | ||
deleteAccountsBySocialMediaId: vi.fn(), | ||
getAccounts: vi.fn(), | ||
}; | ||
const deleteUserAccountsService = new DeleteUserAccountsService( | ||
accountRepository | ||
); | ||
|
||
return { accountRepository, deleteUserAccountsService }; | ||
}; | ||
|
||
describe('DeleteUserAccountsService', () => { | ||
it('deletes accounts by social media id', async () => { | ||
const { accountRepository, deleteUserAccountsService } = makeSut(); | ||
const account = AccountMock.create(); | ||
|
||
await deleteUserAccountsService.execute(account); | ||
|
||
expect( | ||
accountRepository.deleteAccountsBySocialMediaId | ||
).toHaveBeenCalledWith(account.socialMediaId); | ||
}); | ||
|
||
it('throws BadRequestError if socialMediaId is not provided', async () => { | ||
const { deleteUserAccountsService } = makeSut(); | ||
const account = AccountMock.create({ socialMediaId: undefined }); | ||
|
||
await expect(deleteUserAccountsService.execute(account)).rejects.toThrow( | ||
BadRequestError | ||
); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
src/features/account/services/delete-user-accounts-service.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,13 @@ | ||
import type { Service } from '@/shared/protocols/service.js'; | ||
import type { AccountRepository } from '../repositories/account-repository/account-repository.js'; | ||
import type { AccountModel } from '../models/account-model.js'; | ||
import { BadRequestError } from '@/shared/errors/bad-request-error.js'; | ||
|
||
export class DeleteUserAccountsService implements Service<AccountModel> { | ||
constructor(private readonly accountRepository: AccountRepository) {} | ||
|
||
async execute({ socialMediaId }: AccountModel) { | ||
if (!socialMediaId) throw new BadRequestError('undefined social media id'); | ||
await this.accountRepository.deleteAccountsBySocialMediaId(socialMediaId); | ||
} | ||
} |