Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kaufon committed Dec 2, 2024
2 parents a8d5b66 + 39046a6 commit 1db13b2
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 236 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Para acessar os MVP's, acesse o link: <a href="https://drive.google.com/drive/fo

- Sprint 3: [Acessar](https://github.com/CtrI-Alt-Del/stocker/blob/main/documentation/sprints-reports/sprint-3.md)

- Sprint 4: Work in progress... 🚧
- Sprint 4: [Acessar](https://github.com/CtrI-Alt-Del/stocker/blob/main/documentation/sprints-reports/sprint-4.md)

---

Expand Down
Binary file added documentation/images/burndown-chart-sprint-4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions documentation/sprints-reports/sprint-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## User Stories realizados nessa sprint 📖

<img src="../images/users-stories-sprint-4.png" width="2223" height="1240" />
<img src="../images/user-stories-sprint-4.jpg" width="2223" height="1240" />

## Critérios de aceitação para cada User Story 📒

Expand Down Expand Up @@ -87,7 +87,7 @@ Clique [aqui](https://github.com/orgs/CtrI-Alt-Del/projects/4/views/1?filterQuer

## Gráfico Burndown 📈

<img src="../images/burndown-chart-sprint-4.png" width="1000" height="500" alt="Grágico Burndown da primeira Sprint" />
<img src="../images/burndown-chart-sprint-4.jpg" width="1000" height="500" alt="Grágico Burndown da primeira Sprint" />

## Slides para apresentação 🎞️

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,10 @@ export class RegisterSupplierUseCase {
}

async execute({ supplierDto }: Request) {
const existingEmailSupplier = await this.suppliersRepository.findByEmail(
supplierDto.email,
)
if (existingEmailSupplier) {
throw new ConflictError('Email já em uso')
}
const existingSupplier = await this.suppliersRepository.findByCnpj(supplierDto.cnpj)

const existingCNPJSupplier = await this.suppliersRepository.findByCnpj(
supplierDto.cnpj,
)
if (existingCNPJSupplier) {
throw new ConflictError('CNPJ já em uso')
}

const existingPhoneSupplier = await this.suppliersRepository.findByPhone(
supplierDto.phone,
)
if (existingPhoneSupplier) {
throw new ConflictError('Telefone já em uso')
if (existingSupplier && existingSupplier.companyId === supplierDto.companyId) {
throw new ConflictError('Fornecedor já cadastrado nessa empresa')
}

const supplier = Supplier.create(supplierDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,76 +35,58 @@ describe('Register supplier use case', () => {
expect(supplierRepository.suppliers[0]?.dto).toEqual(supplierDto)
})

it('Should not register a supplier with an existing email', async () => {
it('Should not register a supplier with an existing CNPJ in the same company', async () => {
const existingSupplierDto = SuppliersFaker.fakeDto({
email: 'existing-email@example.com',
cnpj: '12.345.678/0001-90',
companyId: 'company-1',
})

const existingSupplier = Supplier.create(existingSupplierDto)
await supplierRepository.add(existingSupplier)
await supplierRepository.add(existingSupplier)
expect(supplierRepository.suppliers).toHaveLength(1)

const supplierDto = SuppliersFaker.fakeDto({
email: 'existing-email@example.com',
cnpj: '12.345.678/0001-90',
companyId: 'company-1',
})

const companyDto = CompanyFaker.fakeDto({ id: supplierDto.companyId })
const company = Company.create(companyDto)
await companiesRepository.add(company)

await expect(useCase.execute({ supplierDto })).rejects.toThrowError(
new ConflictError('Emailem uso')
new ConflictError('Fornecedorcadastrado nessa empresa')
)

expect(supplierRepository.suppliers).toHaveLength(1)
})

it('Should not register a supplier with an existing CNPJ', async () => {
it('Should register a supplier with an existing CNPJ in a different company', async () => {
const existingSupplierDto = SuppliersFaker.fakeDto({
cnpj: '12.345.678/0001-90',
companyId: 'company-1',
})

const existingSupplier = Supplier.create(existingSupplierDto)
await supplierRepository.add(existingSupplier)
await supplierRepository.add(existingSupplier)
expect(supplierRepository.suppliers).toHaveLength(1)

const supplierDto = SuppliersFaker.fakeDto({
cnpj: '12.345.678/0001-90',
companyId: 'company-2',
})

const companyDto = CompanyFaker.fakeDto({ id: supplierDto.companyId })
const company = Company.create(companyDto)
await companiesRepository.add(company)

await expect(useCase.execute({ supplierDto })).rejects.toThrowError(
new ConflictError('CNPJ já em uso')
)

expect(supplierRepository.suppliers).toHaveLength(1)
})
const companyDto1 = CompanyFaker.fakeDto({ id: existingSupplierDto.companyId })
const company1 = Company.create(companyDto1)
await companiesRepository.add(company1)

it('Should not register a supplier with an existing phone', async () => {
const existingSupplierDto = SuppliersFaker.fakeDto({
cnpj: '1',
phone: '984567789',
})
const companyDto2 = CompanyFaker.fakeDto({ id: supplierDto.companyId })
const company2 = Company.create(companyDto2)
await companiesRepository.add(company2)

const existingSupplier = Supplier.create(existingSupplierDto)
await supplierRepository.add(existingSupplier)
expect(supplierRepository.suppliers).toHaveLength(1)

const supplierDto = SuppliersFaker.fakeDto({
phone: '984567789',
})

const companyDto = CompanyFaker.fakeDto({ id: supplierDto.companyId })
const company = Company.create(companyDto)
await companiesRepository.add(company)

await expect(useCase.execute({ supplierDto })).rejects.toThrowError(
new ConflictError('Telefone já em uso')
)
await useCase.execute({ supplierDto })

expect(supplierRepository.suppliers).toHaveLength(1)
expect(supplierRepository.suppliers).toHaveLength(2)
expect(supplierRepository.suppliers[1]?.dto).toEqual(supplierDto)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ describe('Update supplier use case', () => {
it('should not update supplier if the supplier does not exist', async () => {
const fakeSupplier = SuppliersFaker.fake()

expect(async () => {
await useCase.execute({
await expect(
useCase.execute({
supplierDto: fakeSupplier.dto,
supplierId: fakeSupplier.id,
})
}).rejects.toThrowError(NotFoundError)
).rejects.toThrowError(NotFoundError)
})

it('should update supplier', async () => {
Expand All @@ -31,16 +31,10 @@ describe('Update supplier use case', () => {
email: 'email@gmail.com',
cnpj: '28.193.784/0001-49',
phone: '12982567488',
companyId: 'original companyId',
companyId: 'company-1',
})
await supplierRepository.add(fakeSupplier)

expect(supplierRepository.suppliers[0]?.name).toEqual('original name')
expect(supplierRepository.suppliers[0]?.email).toEqual('email@gmail.com')
expect(supplierRepository.suppliers[0]?.cnpj).toEqual('28.193.784/0001-49')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982567488')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')

await useCase.execute({
supplierDto: {
name: 'updated name',
Expand All @@ -53,175 +47,48 @@ describe('Update supplier use case', () => {
expect(supplierRepository.suppliers[0]?.name).toEqual('updated name')
expect(supplierRepository.suppliers[0]?.email).toEqual('updateemail@gmail.com')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982785922')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('company-1')
})


it('should not update supplier with the same email', async () => {
const fakeSupplier = SuppliersFaker.fake({
name: 'original name',
email: 'email@gmail.com',
it('should not update supplier with an existing CNPJ in the same company', async () => {
const fakeSupplier1 = SuppliersFaker.fake({
cnpj: '28.193.784/0001-49',
phone: '12982567488',
companyId: 'original companyId',
companyId: 'company-1',
})
await supplierRepository.add(fakeSupplier)

expect(supplierRepository.suppliers[0]?.name).toEqual('original name')
expect(supplierRepository.suppliers[0]?.email).toEqual('email@gmail.com')
expect(supplierRepository.suppliers[0]?.cnpj).toEqual('28.193.784/0001-49')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982567488')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')
await supplierRepository.add(fakeSupplier1)

const fakeSupplier2 = SuppliersFaker.fake({
name: 'original name2',
email: 'email2@gmail.com',
cnpj: '28.193.784/0001-50',
phone: '12982567489',
companyId: 'original companyId2',
companyId: 'company-1',
})
await supplierRepository.add(fakeSupplier2)

expect(supplierRepository.suppliers[1]?.name).toEqual('original name2')
expect(supplierRepository.suppliers[1]?.email).toEqual('email2@gmail.com')
expect(supplierRepository.suppliers[1]?.cnpj).toEqual('28.193.784/0001-50')
expect(supplierRepository.suppliers[1]?.phone).toEqual('12982567489')
expect(supplierRepository.suppliers[1]?.companyId).toEqual('original companyId2')

await expect(
useCase.execute({
supplierDto: {
name: 'updated name',
email: 'email@gmail.com',
phone: '12982785922',
},
supplierDto: { cnpj: '28.193.784/0001-49' },
supplierId: fakeSupplier2.id,
}),
).rejects.toThrowError(new ConflictError('Esse Email já está em uso'))

expect(supplierRepository.suppliers[0]?.name).toEqual('original name')
expect(supplierRepository.suppliers[0]?.email).toEqual('email@gmail.com')
expect(supplierRepository.suppliers[0]?.cnpj).toEqual('28.193.784/0001-49')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982567488')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')

expect(supplierRepository.suppliers[1]?.name).toEqual('original name2')
expect(supplierRepository.suppliers[1]?.email).toEqual('email2@gmail.com')
expect(supplierRepository.suppliers[1]?.cnpj).toEqual('28.193.784/0001-50')
expect(supplierRepository.suppliers[1]?.phone).toEqual('12982567489')
expect(supplierRepository.suppliers[1]?.companyId).toEqual('original companyId2')
})


it('should not update supplier with the same CNPJ', async () => {
const fakeSupplier = SuppliersFaker.fake({
name: 'original name',
email: 'email@gmail.com',
cnpj: '28.193.784/0001-49',
phone: '12982567488',
companyId: 'original companyId',
})
await supplierRepository.add(fakeSupplier)

expect(supplierRepository.suppliers[0]?.name).toEqual('original name')
expect(supplierRepository.suppliers[0]?.email).toEqual('email@gmail.com')
expect(supplierRepository.suppliers[0]?.cnpj).toEqual('28.193.784/0001-49')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982567488')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')

const fakeSupplier2 = SuppliersFaker.fake({
name: 'original name2',
email: 'email2@gmail.com',
cnpj: '28.193.784/0001-50',
phone: '12982567489',
companyId: 'original companyId2',
})
await supplierRepository.add(fakeSupplier2)

expect(supplierRepository.suppliers[1]?.name).toEqual('original name2')
expect(supplierRepository.suppliers[1]?.email).toEqual('email2@gmail.com')
expect(supplierRepository.suppliers[1]?.cnpj).toEqual('28.193.784/0001-50')
expect(supplierRepository.suppliers[1]?.phone).toEqual('12982567489')
expect(supplierRepository.suppliers[1]?.companyId).toEqual('original companyId2')

await expect(
useCase.execute({
supplierDto: {
name: 'updated name',
email: 'email2@gmail.com',
cnpj: '28.193.784/0001-49',
phone: '12982567922',
},
supplierId: fakeSupplier2.id,
}),
})
).rejects.toThrowError(new ConflictError('Esse CNPJ já está em uso'))

expect(supplierRepository.suppliers[0]?.name).toEqual('original name')
expect(supplierRepository.suppliers[0]?.email).toEqual('email@gmail.com')
expect(supplierRepository.suppliers[0]?.cnpj).toEqual('28.193.784/0001-49')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982567488')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')

expect(supplierRepository.suppliers[1]?.name).toEqual('original name2')
expect(supplierRepository.suppliers[1]?.email).toEqual('email2@gmail.com')
expect(supplierRepository.suppliers[1]?.cnpj).toEqual('28.193.784/0001-50')
expect(supplierRepository.suppliers[1]?.phone).toEqual('12982567489')
expect(supplierRepository.suppliers[1]?.companyId).toEqual('original companyId2')
})


it('should not update supplier with the same telefone', async () => {
const fakeSupplier = SuppliersFaker.fake({
name: 'original name',
email: 'email@gmail.com',
it('should update supplier with an existing CNPJ in a different company', async () => {
const fakeSupplier1 = SuppliersFaker.fake({
cnpj: '28.193.784/0001-49',
phone: '12982567488',
companyId: 'original companyId',
companyId: 'company-1',
})
await supplierRepository.add(fakeSupplier)

expect(supplierRepository.suppliers[0]?.name).toEqual('original name')
expect(supplierRepository.suppliers[0]?.email).toEqual('email@gmail.com')
expect(supplierRepository.suppliers[0]?.cnpj).toEqual('28.193.784/0001-49')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982567488')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')
await supplierRepository.add(fakeSupplier1)

const fakeSupplier2 = SuppliersFaker.fake({
name: 'original name2',
email: 'email2@gmail.com',
cnpj: '28.193.784/0001-50',
phone: '12982567489',
companyId: 'original companyId2',
companyId: 'company-2',
})
await supplierRepository.add(fakeSupplier2)

expect(supplierRepository.suppliers[1]?.name).toEqual('original name2')
expect(supplierRepository.suppliers[1]?.email).toEqual('email2@gmail.com')
expect(supplierRepository.suppliers[1]?.cnpj).toEqual('28.193.784/0001-50')
expect(supplierRepository.suppliers[1]?.phone).toEqual('12982567489')
expect(supplierRepository.suppliers[1]?.companyId).toEqual('original companyId2')

await expect(
useCase.execute({
supplierDto: {
name: 'updated name',
email: 'email2@gmail.com',
phone: '12982567488',
},
supplierId: fakeSupplier2.id,
}),
).rejects.toThrowError(new ConflictError('Esse telefone já está em uso'))

expect(supplierRepository.suppliers[0]?.name).toEqual('original name')
expect(supplierRepository.suppliers[0]?.email).toEqual('email@gmail.com')
expect(supplierRepository.suppliers[0]?.cnpj).toEqual('28.193.784/0001-49')
expect(supplierRepository.suppliers[0]?.phone).toEqual('12982567488')
expect(supplierRepository.suppliers[0]?.companyId).toEqual('original companyId')
await useCase.execute({
supplierDto: { cnpj: '28.193.784/0001-49' },
supplierId: fakeSupplier2.id,
})

expect(supplierRepository.suppliers[1]?.name).toEqual('original name2')
expect(supplierRepository.suppliers[1]?.email).toEqual('email2@gmail.com')
expect(supplierRepository.suppliers[1]?.cnpj).toEqual('28.193.784/0001-50')
expect(supplierRepository.suppliers[1]?.phone).toEqual('12982567489')
expect(supplierRepository.suppliers[1]?.companyId).toEqual('original companyId2')
expect(supplierRepository.suppliers[1]?.cnpj).toEqual('28.193.784/0001-49')
})
})
Loading

0 comments on commit 1db13b2

Please sign in to comment.