-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] 🧪 tests: fix company tests
- Loading branch information
1 parent
b6c8d3a
commit 617dd75
Showing
17 changed files
with
149 additions
and
112 deletions.
There are no files selected for viewing
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
13 changes: 13 additions & 0 deletions
13
packages/core/__tests__/mocks/providers/ai-provider-mock.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 { IAiProvider } from '../../../src/interfaces' | ||
|
||
export class AiProviderMock implements IAiProvider { | ||
propmt = '' | ||
|
||
async generateContent( | ||
propmt: string, | ||
onGenerateChunk: (chunk: string) => void, | ||
): Promise<void> { | ||
this.propmt = propmt | ||
onGenerateChunk('fake chunk') | ||
} | ||
} |
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
65 changes: 45 additions & 20 deletions
65
packages/core/__tests__/mocks/repositories/company-repository-mock.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 |
---|---|---|
@@ -1,28 +1,53 @@ | ||
import type { Company } from "../../../src/domain/entities"; | ||
import type { ICompaniesRepository } from "../../../src/interfaces"; | ||
import type { Company } from '../../../src/domain/entities' | ||
import type { Role } from '../../../src/domain/structs' | ||
import type { ICompaniesRepository } from '../../../src/interfaces' | ||
|
||
export class CompanyRepositoryMock implements ICompaniesRepository { | ||
companies: Company[] = [] | ||
companies: Company[] = [] | ||
roles: Record<string, Role[]> = {} | ||
|
||
async add(company: Company): Promise<void> { | ||
this.companies.push(company) | ||
} | ||
async add(company: Company): Promise<void> { | ||
this.companies.push(company) | ||
} | ||
|
||
async delete(companyId: string): Promise<void> { | ||
this.companies = this.companies.filter((company) => company.id !== companyId); | ||
} | ||
async delete(companyId: string): Promise<void> { | ||
this.companies = this.companies.filter((company) => company.id !== companyId) | ||
} | ||
|
||
async findByCnpj(companyCnpj: string): Promise<Company | null> { | ||
const company = this.companies.find((company) => company.cnpj === companyCnpj) ?? null | ||
return company | ||
} | ||
async findByCnpj(companyCnpj: string): Promise<Company | null> { | ||
const company = this.companies.find((company) => company.cnpj === companyCnpj) ?? null | ||
return company | ||
} | ||
|
||
async findById(companyId: string): Promise<Company | null> { | ||
const company = this.companies.find((company) => company.id === companyId) ?? null | ||
return company | ||
} | ||
async findById(companyId: string): Promise<Company | null> { | ||
const company = this.companies.find((company) => company.id === companyId) ?? null | ||
return company | ||
} | ||
|
||
async update(company: Company, companyId: string): Promise<Company> { | ||
throw new Error('Method not implemented.') | ||
} | ||
|
||
async update(company: Company, companyId: string): Promise<Company> { | ||
throw new Error('Method not implemented.') | ||
async addRole(role: Role, companyId: string): Promise<void> { | ||
if (!(companyId in this.roles)) { | ||
this.roles[companyId] = [] | ||
} | ||
} | ||
|
||
this.roles[companyId]?.push(role) | ||
} | ||
|
||
async findRolesById(companyId: string): Promise<Role[]> { | ||
return this.roles[companyId] ?? [] | ||
} | ||
|
||
async findRoleById(roleName: string, companyId: string): Promise<Role | null> { | ||
console.log('roles', await this.findRolesById(companyId)) | ||
return ( | ||
(await this.findRolesById(companyId)).find((role) => role.name === roleName) ?? null | ||
) | ||
} | ||
|
||
async updateRole(role: Role, companyId: string): Promise<void> { | ||
this.roles[companyId] = [role] | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -3,21 +3,25 @@ import { beforeEach, describe, expect, it } from 'vitest' | |
import { QueueProviderMock } from '../../../../__tests__/mocks/providers' | ||
import { CryptoProviderMock } from '../../../../__tests__/mocks/providers/crypto-provider-mock' | ||
import { RequestPasswordResetUseCase } from '../request-password-reset-use-case' | ||
import { UsersRepositoryMock } from '../../../../__tests__/mocks/repositories' | ||
import { UsersFaker } from '../../../../__tests__/fakers' | ||
|
||
let usersRepository: UsersRepositoryMock | ||
let cryptoProvider: CryptoProviderMock | ||
let queueProvider: QueueProviderMock | ||
let useCase: RequestPasswordResetUseCase | ||
|
||
describe('Request password reset use case', () => { | ||
beforeEach(() => { | ||
usersRepository = new UsersRepositoryMock() | ||
cryptoProvider = new CryptoProviderMock() | ||
queueProvider = new QueueProviderMock() | ||
useCase = new RequestPasswordResetUseCase(cryptoProvider, queueProvider) | ||
useCase = new RequestPasswordResetUseCase(usersRepository, cryptoProvider, queueProvider) | ||
}) | ||
|
||
it('should push to the queue a job that sends password reset email', async () => { | ||
const fakeRecipientEmail = '[email protected]' | ||
|
||
await usersRepository.add(UsersFaker.fake({email: fakeRecipientEmail})) | ||
expect(queueProvider.jobs).toHaveLength(0) | ||
|
||
const confirmationToken = await useCase.execute(fakeRecipientEmail) | ||
|
@@ -33,4 +37,13 @@ describe('Request password reset use case', () => { | |
}, | ||
]) | ||
}) | ||
|
||
it('should not push a job to the queue when the recipient user does not exist', async () => { | ||
const fakeRecipientEmail = '[email protected]' | ||
expect(queueProvider.jobs).toHaveLength(0) | ||
|
||
await useCase.execute(fakeRecipientEmail) | ||
expect(queueProvider.jobs).toHaveLength(0) | ||
|
||
}) | ||
}) |
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
Oops, something went wrong.