Skip to content

[feature/23] :: birth certificate mock pt br#39

Merged
wellfernandes merged 30 commits intodevelopfrom
feature/23-birth-certificate-mock-pt-br
Mar 21, 2025
Merged

[feature/23] :: birth certificate mock pt br#39
wellfernandes merged 30 commits intodevelopfrom
feature/23-birth-certificate-mock-pt-br

Conversation

@wellfernandes
Copy link
Copy Markdown
Member

@wellfernandes wellfernandes commented Mar 18, 2025

  • added brazilian birth certificate mock generation
  • changed how to import a brazilian company in examples file
  • updated main readme
  • updated readme in pt

#23

Summary by CodeRabbit

  • New Features

    • Extended mock data generation now includes additional Brazilian company details and vital certificate information (birth, marriage, and death).
    • Introduced validation for Brazilian birth certificate numbers.
  • Documentation

    • Enhanced and reformatted example code in both English and localized versions for improved clarity and ease of use.
  • Refactor

    • Improved error handling and output messaging to provide more informative and reliable sample data displays.

@wellfernandes wellfernandes requested a review from BertBR March 18, 2025 20:30
@wellfernandes wellfernandes self-assigned this Mar 18, 2025
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2025

Walkthrough

This pull request restructures the mock data generation examples and updates several related modules. The example code in the README files now uses a dedicated GenerateMockExample function within a renamed package. Company generation functions have been updated to accept a formatting flag and improved error handling, with a new error constant for CNPJ generation. In addition, a suite of new certificate generation functions and related error/validation logic for Brazilian vital certificates has been introduced, and an unused generator interface has been removed.

Changes

File(s) Summary
README.md, docs/localization/pt/README-PT.md Updated example code: changed package from main to examples, replaced main() with GenerateMockExample(), added additional mock generation (company, certificates), and improved error handling and output messages.
examples/mock_example.go Modified imports and updated calls: company mock now uses a boolean flag; introduced certificate generation with corresponding error handling and enhanced output details.
pkg/mocai/entities/company/countries/brazilian_company.go, pkg/mocai/entities/company/generator.go, pkg/mocai/entities/company/countries/generator_test.go, pkg/mocai/entities/company/countries/errors.go Updated function signatures to include a formatted boolean parameter; updated error messaging and added the new ErrGeneratingCNPJ constant; adjusted tests to pass the flag.
pkg/mocai/generator/interface.go Removed the unused Generator interface.
pkg/mocai/entities/certificate/countries/brazilian_certificates.go, pkg/mocai/entities/certificate/countries/errors.go, pkg/mocai/entities/certificate/countries/validator.go, pkg/mocai/entities/certificate/generator.go Introduced new certificate generation functionality for Brazilian certificates (birth, marriage, death), including helper functions, error variables, validation logic, and a check-digit algorithm.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Example as GenerateMockExample
    participant Company as Company.GenerateCompany
    participant Certificate as Certificate.GenerateCertificate
    User->>Example: Run mock example
    Example->>Company: Call GenerateCompany(false)
    Company-->>Example: Return company data / error
    Example->>Certificate: Call GenerateCertificate(false)
    Certificate-->>Example: Return certificate data / error
    Example->>User: Print output with mock data
Loading

Possibly related issues

  • birth certificate mock pt-br #23: Restructuring of the mock generation and addition of birth certificate generation directly addresses the issue for a mock birth certificate in the pt-br translation.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • DODOSUBI
  • rluders
  • BertBR

Poem

I'm a bunny in the code garden, hopping through the change,
New functions bloom like carrots, fresh and rearranged.
Certificates and companies now dance in a row,
Errors handled with care – watch the logic grow!
With a twitch of my nose and a hop so spry,
I celebrate these changes 'neath the digital sky!
🥕🐇 Happy coding, every byte in line!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74d8055 and dd1d8a8.

📒 Files selected for processing (1)
  • pkg/mocai/entities/certificate/generator.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/mocai/entities/certificate/generator.go

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (6)
docs/localization/pt/README-PT.md (1)

1-128: Fix hard tabs in markdown code block

The static analysis tool detected hard tabs in the code blocks. While this doesn't affect functionality, it's generally recommended to use spaces for consistent formatting in markdown files.

Consider converting tabs to spaces in your markdown code blocks for better cross-platform rendering consistency.

🧰 Tools
🪛 LanguageTool

[grammar] ~123-~123: Esta palavra é hifenizada.
Context: ...o. Seja bem-vindo ao projeto e sinta-se à vontade para explorar, usar e contribuir! ## ?...

(PT_COMPOUNDS_PRE_REFORM_À_VONTADE)


[typographical] ~126-~126: Símbolo sem par: “]” aparentemente está ausente
Context: ...icipe do servidor Mocai no Discord: [Clique aqui e junte-se a nós!](https://d...

(UNPAIRED_BRACKETS)

🪛 markdownlint-cli2 (0.17.2)

31-31: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


38-38: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


42-42: Hard tabs
Column: 1

(MD010, no-hard-tabs)


44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


45-45: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


54-54: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


63-63: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


74-74: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


79-79: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


85-85: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


89-89: Hard tabs
Column: 1

(MD010, no-hard-tabs)


91-91: Hard tabs
Column: 1

(MD010, no-hard-tabs)


92-92: Hard tabs
Column: 1

(MD010, no-hard-tabs)


93-93: Hard tabs
Column: 1

(MD010, no-hard-tabs)


100-100: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


122-122: Trailing punctuation in heading
Punctuation: '.'

(MD026, no-trailing-punctuation)

README.md (1)

1-130: Fix hard tabs in markdown code block

The static analysis tool detected hard tabs in the code blocks. While this doesn't affect functionality, it's generally recommended to use spaces for consistent formatting in markdown files.

Consider converting tabs to spaces in your markdown code blocks for better cross-platform rendering consistency.

🧰 Tools
🪛 LanguageTool

[grammar] ~12-~12: This phrase is duplicated. You should probably use “the Name” only once.
Context: ...reliable manner. ## 🌟 Curiosity about the Name The name Mocaí is a tribute to the Brazilian ini...

(PHRASE_REPETITION)


[style] ~125-~125: The phrase ‘feel free to’ is used quite frequently. Consider using a less frequent alternative to set your writing apart from others and make it sound more professional.
Context: ...evelopment. Welcome to the project, and feel free to explore, use, and contribute! ## 🌐 Di...

(FEEL_FREE_TO_STYLE_ME)

🪛 markdownlint-cli2 (0.17.2)

5-5: Heading levels should only increment by one level at a time
Expected: h2; Actual: h4

(MD001, heading-increment)


33-33: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


40-40: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


50-50: Hard tabs
Column: 1

(MD010, no-hard-tabs)


51-51: Hard tabs
Column: 1

(MD010, no-hard-tabs)


55-55: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


61-61: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


66-66: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


71-71: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


74-74: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


77-77: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


83-83: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


86-86: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


89-89: Hard tabs
Column: 1

(MD010, no-hard-tabs)


91-91: Hard tabs
Column: 1

(MD010, no-hard-tabs)


93-93: Hard tabs
Column: 1

(MD010, no-hard-tabs)


94-94: Hard tabs
Column: 1

(MD010, no-hard-tabs)


95-95: Hard tabs
Column: 1

(MD010, no-hard-tabs)


102-102: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)


124-124: Trailing punctuation in heading
Punctuation: '.'

(MD026, no-trailing-punctuation)

pkg/mocai/entities/birth_certificate/brazil/generator.go (4)

1-7: Package name doesn't match directory structure.

The package is named birth_certificate but the file is located in the brazil subdirectory. Typically, the package name should match the directory name for better organization and clarity. Consider renaming the package to brazil to match the directory structure.


74-75: Remove debug print statements.

The print statements should be removed or replaced with proper logging mechanisms. Debug statements shouldn't be included in production code.

- 		print(numberWithoutCheckDigits)
+ 		// Remove or replace with proper logging if needed
- 	print("checkDigits: ", checkDigits)
+ 	// Remove or replace with proper logging if needed

Also applies to: 80-81


47-48: Consider extending the birth year range.

The birth year is currently limited to 2010 onwards, which seems restrictive for a general-purpose mock data generator. Consider allowing a wider range of years for more diverse mock data.

- 	birthYear := r.Intn(currentYear-2010+1) + 2010
+ 	// Allow a wider range of birth years, e.g., from 1950 onwards
+ 	birthYear := r.Intn(currentYear-1950+1) + 1950

30-31: Consider using crypto/rand for better randomness.

Using math/rand instead of crypto/rand might result in less random output. While not critical for mock data, consider using crypto/rand for better randomness.

- 	r := rand.New(rand.NewSource(time.Now().UnixNano()))
+ 	// Use crypto/rand for better randomness
+ 	import (
+ 		"crypto/rand"
+ 		"math/big"
+ 	)
+ 	
+ 	// Then replace the random number generation with something like:
+ 	// max := big.NewInt(899999)
+ 	// n, _ := rand.Int(rand.Reader, max)
+ 	// vitalRecordsOffice := n.Int64() + 100000
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3c37a6 and 71163aa.

📒 Files selected for processing (6)
  • README.md (2 hunks)
  • docs/localization/pt/README-PT.md (2 hunks)
  • examples/mock_example.go (3 hunks)
  • pkg/mocai/entities/birth_certificate/brazil/errors.go (1 hunks)
  • pkg/mocai/entities/birth_certificate/brazil/generator.go (1 hunks)
  • pkg/mocai/entities/birth_certificate/brazil/validator.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
examples/mock_example.go (1)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-12T13:19:49.329Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
🧬 Code Definitions (1)
examples/mock_example.go (1)
pkg/mocai/entities/company/brazil/generator.go (1) (1)
  • GenerateCompany (23:54)
🪛 markdownlint-cli2 (0.17.2)
docs/localization/pt/README-PT.md

42-42: Hard tabs
Column: 1

(MD010, no-hard-tabs)


44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


45-45: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


54-54: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


63-63: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


74-74: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


79-79: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


85-85: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


89-89: Hard tabs
Column: 1

(MD010, no-hard-tabs)


91-91: Hard tabs
Column: 1

(MD010, no-hard-tabs)


92-92: Hard tabs
Column: 1

(MD010, no-hard-tabs)


93-93: Hard tabs
Column: 1

(MD010, no-hard-tabs)

README.md

44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


50-50: Hard tabs
Column: 1

(MD010, no-hard-tabs)


51-51: Hard tabs
Column: 1

(MD010, no-hard-tabs)


55-55: Hard tabs
Column: 1

(MD010, no-hard-tabs)


74-74: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


77-77: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


83-83: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


86-86: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


89-89: Hard tabs
Column: 1

(MD010, no-hard-tabs)


91-91: Hard tabs
Column: 1

(MD010, no-hard-tabs)


93-93: Hard tabs
Column: 1

(MD010, no-hard-tabs)


94-94: Hard tabs
Column: 1

(MD010, no-hard-tabs)


95-95: Hard tabs
Column: 1

(MD010, no-hard-tabs)

🔇 Additional comments (12)
pkg/mocai/entities/birth_certificate/brazil/validator.go (1)

1-37:

Details

✅ Verification successful

Implementation looks solid with one missing dependency

The birth certificate validation implementation follows a clear and methodical approach by:

  1. Cleaning the input string
  2. Validating the length and character content
  3. Extracting and verifying check digits

However, there's a dependency on calculateCheckDigits() function (line 33) that's not defined in this file.


🏁 Script executed:

#!/bin/bash
# Check if the calculateCheckDigits function is defined in the package
fd -e go -x grep -l "func calculateCheckDigits" {} \; pkg/mocai/entities/birth_certificate/brazil/

Length of output: 585


🏁 Script executed:

#!/bin/bash
# Correctly searching for the definition of calculateCheckDigits in the pkg/mocai/entities/birth_certificate/brazil/ directory
rg "func calculateCheckDigits" pkg/mocai/entities/birth_certificate/brazil/

Length of output: 184


Dependency Check Verified
The birth certificate validation implementation is solid. The dependency on calculateCheckDigits() is resolved as its definition was found in pkg/mocai/entities/birth_certificate/brazil/generator.go. No further changes are needed.

docs/localization/pt/README-PT.md (2)

39-94: Example code updated with new birth certificate generation

The Portuguese documentation now correctly demonstrates the birth certificate mock generation functionality, maintaining consistency with the changes in the English version. Error handling for all mock generation functions is properly implemented.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

42-42: Hard tabs
Column: 1

(MD010, no-hard-tabs)


44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


45-45: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


54-54: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


63-63: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


74-74: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


79-79: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


85-85: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


89-89: Hard tabs
Column: 1

(MD010, no-hard-tabs)


91-91: Hard tabs
Column: 1

(MD010, no-hard-tabs)


92-92: Hard tabs
Column: 1

(MD010, no-hard-tabs)


93-93: Hard tabs
Column: 1

(MD010, no-hard-tabs)


14-24: README formatting enhancements look good

The bullet points now use bold text for each feature, making the documentation more readable.

pkg/mocai/entities/birth_certificate/brazil/errors.go (1)

1-18:

Details

❓ Verification inconclusive

Well-structured error definitions for birth certificate validation

The error definitions are clear, descriptive, and follow best practices. The documentation comment explaining that these errors should be wrapped with additional context is especially helpful for maintainability.

However, I noticed these errors aren't currently used in the validator.go file. They're likely used in the generator.go file that implements the birth certificate generation logic.


🏁 Script executed:

#!/bin/bash
# Check where these errors are actually used
rg -A 1 "ErrInvalid.*Certificate" pkg/mocai/entities/birth_certificate/

Length of output: 347


Attention: Validate Error Usage Across Modules

The error definitions in pkg/mocai/entities/birth_certificate/brazil/errors.go are well-structured, descriptive, and documented. However, as previously noted, these errors don't appear to be used in validator.go. Please confirm that their usage is intended for other modules, such as the birth certificate generation logic (e.g., in generator.go). If these errors remain unused, consider either removing them or adding documentation to clarify their purpose and usage to prevent any potential confusion in future developments.

README.md (1)

41-96: Example code updated with birth certificate mock generation

The README now demonstrates the new birth certificate mock generation functionality, which aligns with the PR objective. The code is well-structured with proper error handling for all mock generation functions.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


50-50: Hard tabs
Column: 1

(MD010, no-hard-tabs)


51-51: Hard tabs
Column: 1

(MD010, no-hard-tabs)


55-55: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


61-61: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


66-66: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


71-71: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


74-74: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


77-77: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


83-83: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


86-86: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


89-89: Hard tabs
Column: 1

(MD010, no-hard-tabs)


91-91: Hard tabs
Column: 1

(MD010, no-hard-tabs)


93-93: Hard tabs
Column: 1

(MD010, no-hard-tabs)


94-94: Hard tabs
Column: 1

(MD010, no-hard-tabs)


95-95: Hard tabs
Column: 1

(MD010, no-hard-tabs)

examples/mock_example.go (4)

8-9: Good improvement on import naming for clarity.

The renaming from company to brazilian_company improves clarity by explicitly identifying the origin of the company entity. The addition of the birth certificate import is aligned with the PR objectives of adding Brazilian birth certificate mock generation.


35-39: Improved error handling.

The updated error handling with the added return statement is a good enhancement as it prevents the function from continuing execution after encountering an error during company generation. This ensures the function fails fast and avoids potential null pointer issues.


41-45: Birth certificate mock generation looks good.

The implementation correctly integrates the new Brazilian birth certificate generation functionality, following the same error handling pattern used for other entities. The false parameter indicates that an unformatted certificate number will be generated.


53-54: Good output formatting.

The birth certificate output follows the same formatting pattern used for other entities, maintaining consistency in the codebase.

pkg/mocai/entities/birth_certificate/brazil/generator.go (3)

9-22: Well-structured birth certificate type with good documentation.

The BrazilianBirthCertificate struct is well-designed with appropriate fields for all components of a Brazilian birth certificate. The documentation provides a clear description of the purpose of the struct.


104-148: Well-implemented check digit calculation.

The check digit calculation is well-implemented with appropriate comments explaining the algorithm. The weights and calculation logic appear to follow the specified algorithm for Brazilian birth certificates.


35-37:

Details

✅ Verification successful

Error variables are referenced but not defined.

The code references error variables like ErrInvalidVitalRecordsOffice, ErrInvalidBookNumber, etc., but these don't appear to be defined in this file. There should be an accompanying errors.go file or these errors should be defined within this file.

Let's check if there's an errors.go file:

Also applies to: 54-56, 60-62, 66-68, 73-76


🏁 Script executed:

#!/bin/bash
# Check if there's an errors.go file in the birth certificate directory
fd "errors.go" --type f --exec head -n 20 {} \; | grep "birth_certificate"

Length of output: 209


Verification: Error variables are defined in a shared errors.go file

The error variables referenced in pkg/mocai/entities/birth_certificate/brazil/generator.go are correctly defined in the errors.go file located in the pkg/mocai/entities/birth_certificate/ directory. This design centralizes error definitions, and no further modifications are required in the generator file.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/mocai/entities/company/countries/brazilian_company.go (1)

22-22: Function signature update adds flexibility but breaks backward compatibility.

The function now accepts a formatted boolean parameter that determines whether the CNPJ should be formatted with separators. This is consistent with other generation functions in the codebase and improves flexibility for callers.

However, this change breaks backward compatibility. Existing code calling this function will need to be updated to pass the new parameter.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 71163aa and ca76f5f.

📒 Files selected for processing (9)
  • examples/mock_example.go (3 hunks)
  • pkg/mocai/entities/birth_certificate/countries/brazilian_birth_certificate.go (1 hunks)
  • pkg/mocai/entities/birth_certificate/countries/errors.go (1 hunks)
  • pkg/mocai/entities/birth_certificate/countries/validator.go (1 hunks)
  • pkg/mocai/entities/birth_certificate/generator.go (1 hunks)
  • pkg/mocai/entities/company/countries/brazilian_company.go (3 hunks)
  • pkg/mocai/entities/company/countries/errors.go (1 hunks)
  • pkg/mocai/entities/company/generator.go (1 hunks)
  • pkg/mocai/generator/interface.go (0 hunks)
💤 Files with no reviewable changes (1)
  • pkg/mocai/generator/interface.go
🧰 Additional context used
🧠 Learnings (1)
pkg/mocai/entities/company/countries/errors.go (1)
Learnt from: BertBR
PR: brazzcore/mocai#31
File: pkg/mocai/entities/company/brazil/generator.go:42-43
Timestamp: 2025-03-19T20:31:48.611Z
Learning: In the mocai project, the constant `ERROR_GENERATING_BRAZILIAN_COMPANY` is defined in the `pkg/mocai/entities/company/brazil/errors.go` file and is accessible from other files in the same `company` package, such as `generator.go`.
🧬 Code Definitions (6)
pkg/mocai/entities/company/generator.go (1)
pkg/mocai/entities/company/countries/brazilian_company.go (1) (1)
  • GenerateBrazilianCompany (22-57)
examples/mock_example.go (1)
pkg/mocai/entities/company/generator.go (1) (1)
  • GenerateCompany (11-19)
pkg/mocai/entities/birth_certificate/generator.go (1)
pkg/mocai/entities/birth_certificate/countries/brazilian_birth_certificate.go (2) (2)
  • BrazilianBirthCertificate (11-22)
  • GenerateBirthCertificate (27-106)
pkg/mocai/entities/company/countries/brazilian_company.go (1)
pkg/mocai/entities/company/countries/errors.go (1) (1)
  • ErrGeneratingCNPJ (10-10)
pkg/mocai/entities/birth_certificate/countries/validator.go (1)
pkg/mocai/entities/birth_certificate/countries/brazilian_birth_certificate.go (1) (1)
  • calculateCheckDigits (110-152)
pkg/mocai/entities/birth_certificate/countries/brazilian_birth_certificate.go (2)
pkg/mocai/entities/birth_certificate/generator.go (1) (1)
  • GenerateBirthCertificate (9-16)
pkg/mocai/entities/birth_certificate/countries/errors.go (6) (6)
  • ErrInvalidVitalRecordsOffice (10-10)
  • ErrInvalidBookNumber (14-14)
  • ErrInvalidPageNumber (15-15)
  • ErrInvalidTermNumber (16-16)
  • ErrInvalidNumberWithoutCheckDigits (17-17)
  • ErrInvalidBirthCertificate (9-9)
🔇 Additional comments (17)
pkg/mocai/entities/company/countries/errors.go (2)

5-5: Documentation update looks good.

This minor change to the comment is appropriate, simplifying while preserving the original intent.


10-10: Good addition of a specific error constant.

Adding the ErrGeneratingCNPJ constant improves error handling by providing more specific error messaging for CNPJ generation failures, separating these from general company generation errors.

pkg/mocai/entities/company/generator.go (1)

11-12: Function signature enhancement with formatting option.

The addition of the formatted boolean parameter enhances flexibility by allowing callers to control CNPJ formatting. This change properly propagates the parameter to the GenerateBrazilianCompany function.

pkg/mocai/entities/birth_certificate/generator.go (2)

1-8: Well-structured implementation of birth certificate entity.

The implementation follows the same pattern as the company entity, creating a consistent API design across the package. The BirthCertificate struct properly wraps the country-specific implementation.


9-16: Clean implementation of the generator function.

The GenerateBirthCertificate function correctly delegates to the country-specific implementation and handles errors appropriately. The function signature with the formatted parameter maintains consistency with other entity generators.

pkg/mocai/entities/birth_certificate/countries/validator.go (2)

1-7: Package and imports look good.

The imports and package declaration are appropriate for the functionality being implemented.


8-37: Comprehensive validation implementation.

The ValidateBirthCertificate function effectively validates Brazilian birth certificates by:

  1. Cleaning input formatting
  2. Checking length (32 digits)
  3. Verifying numeric-only content using regex
  4. Extracting and comparing check digits

The function follows a clear step-by-step approach with good documentation.

pkg/mocai/entities/company/countries/brazilian_company.go (2)

37-37: Properly passing the formatted parameter to the underlying CNPJ generator.

The formatted parameter is correctly passed to the CNPJ generation function, ensuring consistent behavior throughout the codebase.


48-48: More specific error reporting for CNPJ generation failures.

The error message now references ErrGeneratingCNPJ instead of ErrGeneratingBrazilianCompany, which is more precise and helps with debugging by pinpointing the exact failure point.

examples/mock_example.go (4)

8-8: New import for birth certificate functionality.

The import statement correctly includes the new birth certificate package, aligning with the PR objective of adding Brazilian birth certificate mock generation.


35-39: Updated company generation call with improved error handling.

The code now:

  1. Passes false to company.GenerateCompany() to generate an unformatted CNPJ
  2. Adds proper error handling with an early return if an error occurs

This prevents the function from continuing execution after an error, which is a good practice.


41-45: New birth certificate mock generation with proper error handling.

The implementation correctly calls the new birth certificate generation function with appropriate error handling, consistent with the PR's objective of adding Brazilian birth certificate mock generation.


53-53: Output added for the new birth certificate mock.

The code properly displays the generated birth certificate number in the output, providing a complete example of the new functionality.

pkg/mocai/entities/birth_certificate/countries/brazilian_birth_certificate.go (3)

9-22: Well-structured Brazilian birth certificate type definition.

The BrazilianBirthCertificate struct has clear field names that accurately represent the components of a Brazilian birth certificate, with appropriate data types for each field.


24-27: Clear function documentation.

The function documentation clearly explains what the function does, the purpose of the formatted parameter, and what it returns. This makes the code more maintainable and easier to use.


108-152: Well-implemented check digit calculation function.

The function implements the Mod 11 algorithm for calculating check digits, with detailed comments explaining the process. The weights are correctly defined, and the calculation handles edge cases appropriately.

pkg/mocai/entities/birth_certificate/countries/errors.go (1)

5-18: Well-defined and documented error constants.

The error constants are:

  1. Specific to different types of validation failures
  2. Well-documented with comments explaining their purpose
  3. Following a consistent naming convention
  4. Properly grouped in a var block

This implementation will make error handling more specific and maintainable throughout the codebase.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
pkg/mocai/entities/company/countries/generator_test.go (1)

9-18: Consider adding a test case for formatted CNPJs

The current test only verifies the unformatted CNPJ generation case. Since the function now supports both formatted and unformatted CNPJs, it would be beneficial to have test coverage for both scenarios.

func TestGenerateCompany(t *testing.T) {
	company, err := GenerateBrazilianCompany(false)
	if err != nil {
		t.Fatalf("Failed to generate company: %v", err)
	}

	if company.CompanyName == "" || company.CNPJ == "" {
		t.Errorf("Generated company has empty fields: %+v", company)
	}
+
+	// Test with formatted CNPJ
+	formattedCompany, err := GenerateBrazilianCompany(true)
+	if err != nil {
+		t.Fatalf("Failed to generate company with formatted CNPJ: %v", err)
+	}
+
+	if formattedCompany.CompanyName == "" || formattedCompany.CNPJ == "" {
+		t.Errorf("Generated formatted company has empty fields: %+v", formattedCompany)
+	}
+
+	// Check if CNPJ is formatted (contains punctuation)
+	if !strings.Contains(formattedCompany.CNPJ, ".") || !strings.Contains(formattedCompany.CNPJ, "/") || !strings.Contains(formattedCompany.CNPJ, "-") {
+		t.Errorf("CNPJ is not properly formatted: %s", formattedCompany.CNPJ)
+	}
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ca76f5f and c145019.

📒 Files selected for processing (1)
  • pkg/mocai/entities/company/countries/generator_test.go (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
pkg/mocai/entities/company/countries/generator_test.go (1)
pkg/mocai/entities/company/countries/brazilian_company.go (1) (1)
  • GenerateBrazilianCompany (22-57)
🔇 Additional comments (2)
pkg/mocai/entities/company/countries/generator_test.go (2)

10-10: Test parameter addition looks good

The code has been updated to pass the false parameter to GenerateBrazilianCompany(), which is consistent with the function signature change in the implementation file.


21-21: Test parameter addition looks good

The code has been updated correctly to pass the false parameter to GenerateBrazilianCompany(), maintaining consistency with the implementation.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (10)
pkg/mocai/entities/certificate/generator.go (1)

9-16: Good implementation of certificate generation with proper error handling.

The GenerateCertificate function correctly passes the formatting preference to the underlying generator and properly handles any errors that might occur during generation.

Consider adding a documentation comment to explain the purpose of the formatted parameter and how it affects the generated certificate.

+// GenerateCertificate creates a new certificate with Brazilian vital records.
+// The formatted parameter determines whether the certificate numbers should be formatted
+// with separators for better readability.
 func GenerateCertificate(formatted bool) (*Certificate, error) {
pkg/mocai/entities/certificate/countries/validator.go (1)

20-24: Improve error handling in regex match.

The regular expression match discards the error value, which could hide potential issues with the regex pattern.

-	match, _ := regexp.MatchString("^[0-9]+$", certificate)
+	match, err := regexp.MatchString("^[0-9]+$", certificate)
+	if err != nil {
+		return false
+	}
pkg/mocai/entities/certificate/countries/errors.go (1)

5-18: Comprehensive error definitions for certificate validation.

The error variables are clearly defined with descriptive messages, covering various validation scenarios for certificates. This will make error handling more specific and informative throughout the codebase.

Consider organizing these errors into logical groups with additional comments if they apply to specific parts of the certificate validation process. For instance, you might group errors related to the certificate structure, errors related to demographic information, etc.

pkg/mocai/entities/certificate/countries/brazilian_certificates.go (7)

13-17: Consider using iota for certificate type constants

While the current approach is perfectly valid, using iota would make it clearer that these are sequential, related constants.

const (
-	brazilianBirthCertificateType    = 1
-	brazilianMarriageCertificateType = 2
-	brazilianDeathCertificateType    = 3
+	brazilianBirthCertificateType    = iota + 1
+	brazilianMarriageCertificateType
+	brazilianDeathCertificateType
)

55-58: Fix comment to match function name and clarify its purpose

The function name is singular (GenerateBrazilianCertificates) but the comment implies it generates multiple certificates, which it does. Let's make the comment clearer.

-// GenerateBrazilianCertificates generates a valid brazilian certificates
+// GenerateBrazilianCertificates generates all three types of valid Brazilian certificates
// If formatted is true, returns the number with separators (-)
// Returns a pointer to BrazilianCertificates and error if any validation fails

83-87: Fix function name inconsistency

The comment says "generateCertificates" (plural) but the function name is singular.

-// generateCertificates generates a valid brazilian certificate
+// generateCertificate generates a valid brazilian certificate
// If formatted is true, returns the number with separators (-)
// certificateType is the type of certificate [1 - for birth certificate, 2 - for marriage certificate, 3 - for death certificate]
// Returns a pointer to BaseCertificate and error if any validation fails

95-100: Document the fixed values for archiveCode and serviceType

The values for archiveCode and serviceType are hardcoded without explanation. If these are standard values for Brazilian certificates, please add a comment to explain.

// 2. Archive [2 digits]
archiveCode := 1
+// Archive code is fixed as 1 for standard Brazilian certificates

// 3. Civil Registry of Natural Persons [2 digits]
serviceType := 55
+// Service type 55 represents the Civil Registry of Natural Persons in Brazil

105-106: Remove redundant comment

Line 106 has a commented variable name that doesn't provide any information.

// 5. Certificate type [1 digit]
-//certificateType

203-206: Validate input parameters in generateRandomNumber

The function doesn't check if min is less than max, which could lead to unexpected results or negative return values.

// generateRandomNumber generates a random number between min and max
func generateRandomNumber(min, max int) int {
+	if min > max {
+		return -1 // Error indicator, matches how errors are checked in the calling code
+	}
	return rand.Intn(max-min+1) + min
}

19-159: Consider reducing duplicated error handling code

Each certificate type generation follows the same pattern. Consider implementing a more generic approach to reduce duplication.

You could create a factory function that takes the certificate type as a parameter:

func createCertificate(formatted bool, certificateType int) (interface{}, error) {
    base, err := generateCertificate(formatted, certificateType)
    if err != nil {
        return nil, err
    }

    switch certificateType {
    case brazilianBirthCertificateType:
        return &BirthCertificate{BaseCertificate: *base}, nil
    case brazilianMarriageCertificateType:
        return &MarriageCertificate{BaseCertificate: *base}, nil
    case brazilianDeathCertificateType:
        return &DeathCertificate{BaseCertificate: *base}, nil
    default:
        return nil, fmt.Errorf("invalid certificate type: %d", certificateType)
    }
}

This would simplify your code in GenerateBrazilianCertificates.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe5796f and 0cfefc9.

📒 Files selected for processing (5)
  • examples/mock_example.go (3 hunks)
  • pkg/mocai/entities/certificate/countries/brazilian_certificates.go (1 hunks)
  • pkg/mocai/entities/certificate/countries/errors.go (1 hunks)
  • pkg/mocai/entities/certificate/countries/validator.go (1 hunks)
  • pkg/mocai/entities/certificate/generator.go (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
examples/mock_example.go (1)
pkg/mocai/entities/company/generator.go (1) (1)
  • GenerateCompany (11-19)
🔇 Additional comments (9)
pkg/mocai/entities/certificate/generator.go (1)

1-7: Well-structured Certificate type definition.

The Certificate struct with a field for Brazilian certificates is well-designed. This approach allows for future expansion to include certificates from other countries.

pkg/mocai/entities/certificate/countries/validator.go (3)

8-10: Good documentation for the validator function.

The comments clearly explain the purpose of the function and what it validates.


10-19: Input sanitization and length validation look good.

The function properly cleans the input by removing dashes and spaces, and checks that the certificate has exactly 32 digits.


26-36:

Details

✅ Verification successful

Calculation of check digits is missing.

The function calls calculateCheckDigits, but this function is not defined in the provided file. Ensure this function is defined elsewhere and correctly calculates the check digits according to Brazilian birth certificate rules.


🏁 Script executed:

#!/bin/bash
# Check if the calculateCheckDigits function is defined in the same package
grep -r "func calculateCheckDigits" pkg/mocai/entities/certificate/countries/

Length of output: 196


Check digit calculation confirmed:
The function calculateCheckDigits is indeed defined in pkg/mocai/entities/certificate/countries/brazilian_certificates.go, so the check digits are calculated as expected. There's no missing logic in the code snippet provided in the validator.go file.

examples/mock_example.go (4)

3-13: Good import addition for the certificate package.

The import for the certificate package is properly added to support the new certificate generation functionality.


35-39: Updated company generation with improved error handling.

The company generation now accepts a formatting parameter and includes proper error handling with an early return on failure.


41-45: Good implementation of certificate generation with error handling.

The certificate generation follows the same pattern as other mock generations, with proper error handling.


53-58: Good display of generated certificate information.

The output now includes the generated certificate numbers, making the example more comprehensive.

pkg/mocai/entities/certificate/countries/brazilian_certificates.go (1)

214-258: Well-implemented check digit calculation algorithm

The implementation of the MOD 11 algorithm for calculating check digits is thorough and well-commented. The use of clear variable names and detailed comments makes the complex algorithm easy to follow.

@wellfernandes wellfernandes requested a review from DODOSUBI March 21, 2025 14:37
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
docs/localization/pt/README-PT.md (1)

53-101: Comprehensive GenerateMockExample Function Implementation

The new GenerateMockExample function effectively demonstrates the generation of various mocks (person, address, phone, company, and certificates). The error handling—with simple prints via fmt.Print(err) and conditional returns on critical failures—is appropriate for demo purposes. As a minor suggestion, consider using fmt.Println(err) for clearer error message separation or a dedicated logging approach, and ensure consistency in error handling across all mock generations.

README.md (1)

55-101: Comprehensive GenerateMockExample Function in README

The GenerateMockExample function now provides a detailed demonstration of generating comprehensive mock data, including person, address, phone, company, and certificates. Improved error handling (with conditional returns on critical steps) ensures that users see practical examples of managing failures. For consistency, consider using fmt.Println instead of fmt.Print for error messages so that the outputs are clearly separated by newlines.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


61-61: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


63-63: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


66-66: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


71-71: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


77-77: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


79-79: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


83-83: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


85-85: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


88-88: Hard tabs
Column: 1

(MD010, no-hard-tabs)


90-90: Hard tabs
Column: 1

(MD010, no-hard-tabs)


92-92: Hard tabs
Column: 1

(MD010, no-hard-tabs)


94-94: Hard tabs
Column: 1

(MD010, no-hard-tabs)


96-96: Hard tabs
Column: 1

(MD010, no-hard-tabs)


98-98: Hard tabs
Column: 1

(MD010, no-hard-tabs)


99-99: Hard tabs
Column: 1

(MD010, no-hard-tabs)


100-100: Hard tabs
Column: 1

(MD010, no-hard-tabs)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cfefc9 and 74d8055.

📒 Files selected for processing (2)
  • README.md (2 hunks)
  • docs/localization/pt/README-PT.md (2 hunks)
🧰 Additional context used
🪛 markdownlint-cli2 (0.17.2)
README.md

44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


50-50: Hard tabs
Column: 1

(MD010, no-hard-tabs)


51-51: Hard tabs
Column: 1

(MD010, no-hard-tabs)


52-52: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


75-75: Hard tabs
Column: 1

(MD010, no-hard-tabs)


76-76: Hard tabs
Column: 1

(MD010, no-hard-tabs)


77-77: Hard tabs
Column: 1

(MD010, no-hard-tabs)


78-78: Hard tabs
Column: 1

(MD010, no-hard-tabs)


79-79: Hard tabs
Column: 1

(MD010, no-hard-tabs)


81-81: Hard tabs
Column: 1

(MD010, no-hard-tabs)


82-82: Hard tabs
Column: 1

(MD010, no-hard-tabs)


83-83: Hard tabs
Column: 1

(MD010, no-hard-tabs)


84-84: Hard tabs
Column: 1

(MD010, no-hard-tabs)


85-85: Hard tabs
Column: 1

(MD010, no-hard-tabs)


87-87: Hard tabs
Column: 1

(MD010, no-hard-tabs)


88-88: Hard tabs
Column: 1

(MD010, no-hard-tabs)


90-90: Hard tabs
Column: 1

(MD010, no-hard-tabs)


92-92: Hard tabs
Column: 1

(MD010, no-hard-tabs)


94-94: Hard tabs
Column: 1

(MD010, no-hard-tabs)


96-96: Hard tabs
Column: 1

(MD010, no-hard-tabs)


98-98: Hard tabs
Column: 1

(MD010, no-hard-tabs)


99-99: Hard tabs
Column: 1

(MD010, no-hard-tabs)


100-100: Hard tabs
Column: 1

(MD010, no-hard-tabs)

🔇 Additional comments (6)
docs/localization/pt/README-PT.md (4)

14-18: Enhanced Formatting for Feature List

The bullet points under "Principais Recursos" are now bolded for improved visibility. This change enhances readability and emphasizes the key features.


21-24: Improved "Por que usar o Mocai?" Section

The updated bullet points clearly outline the benefits of using Mocai. The emphasis provided by bold text helps capture the reader's attention.


39-52: Updated Package Declaration and Imports

The example code now uses package examples and includes new imports such as the certificate module. This update aligns well with the PR objectives for introducing the birth certificate mock and reflects a cohesive change across documentation.


102-109: Clear Example Execution Instructions

The instructions to run the examples (i.e., navigating to the project root and running go run main.go) are clear and straightforward, making it easy for users to test the functionality.

README.md (2)

41-54: Updated Package Declaration and Imports

The package declaration is now updated to package examples, and new imports—especially the added certificate module—ensure that the example code supports the generation of Brazilian birth certificates. This aligns the README with other documentation changes and the overall PR objectives.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

44-44: Hard tabs
Column: 1

(MD010, no-hard-tabs)


46-46: Hard tabs
Column: 1

(MD010, no-hard-tabs)


47-47: Hard tabs
Column: 1

(MD010, no-hard-tabs)


48-48: Hard tabs
Column: 1

(MD010, no-hard-tabs)


49-49: Hard tabs
Column: 1

(MD010, no-hard-tabs)


50-50: Hard tabs
Column: 1

(MD010, no-hard-tabs)


51-51: Hard tabs
Column: 1

(MD010, no-hard-tabs)


52-52: Hard tabs
Column: 1

(MD010, no-hard-tabs)


104-109: Clear Instructions for Running Examples

The section detailing how to run the examples is clear and concise. The instructions ensure that users understand the correct directory context and command (go run main.go) to execute the example code.

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

107-107: Fenced code blocks should have a language specified
null

(MD040, fenced-code-language)

@wellfernandes wellfernandes merged commit c5f28ae into develop Mar 21, 2025
2 checks passed
@wellfernandes wellfernandes deleted the feature/23-birth-certificate-mock-pt-br branch March 21, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants