Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 228 additions & 0 deletions adapter/presenter/_create_account_output_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
// ********RoostGPT********
/*
Test generated by RoostGPT for test mayankzbio-go-clean using AI Type Claude AI and AI Model claude-3-5-sonnet-20240620

ROOST_METHOD_HASH=Output_176178cc60
ROOST_METHOD_SIG_HASH=Output_d83d35060a

FUNCTION_DEF=func (a createAccountPresenter) Output(account domain.Account) usecase.CreateAccountOutput
Based on the provided function and context, here are several test scenarios for the `Output` method of the `createAccountPresenter` struct:

```
Scenario 1: Successful Account Output Conversion

Details:
Description: This test verifies that the Output method correctly converts a domain.Account object to a usecase.CreateAccountOutput object with all fields properly mapped.

Execution:
Arrange:
- Create a mock domain.Account with known values for all fields.
- Initialize a createAccountPresenter instance.
Act:
- Call the Output method with the mock account.
Assert:
- Verify that the returned usecase.CreateAccountOutput matches the expected values from the input account.

Validation:
This test ensures that the presenter correctly translates internal domain objects to the expected output format. It's crucial for maintaining the contract between the use case and the external interfaces of the application.

Scenario 2: Zero Balance Account Output

Details:
Description: Test the Output method's handling of an account with a zero balance to ensure proper formatting.

Execution:
Arrange:
- Create a mock domain.Account with a balance of 0.
- Initialize a createAccountPresenter instance.
Act:
- Call the Output method with the zero-balance account.
Assert:
- Verify that the Balance field in the output is exactly 0.0 (not a small floating-point value).

Validation:
This test checks the precision of balance representation, which is important for financial applications where exact zero balances may have significance.

Scenario 3: Maximum Value Handling

Details:
Description: Verify that the Output method correctly handles an account with maximum possible values for its numeric fields.

Execution:
Arrange:
- Create a mock domain.Account with the maximum possible balance value.
- Initialize a createAccountPresenter instance.
Act:
- Call the Output method with the maximum-value account.
Assert:
- Check that the Balance field in the output correctly represents the maximum value without loss of precision.

Validation:
This edge case test ensures that the presenter can handle extreme values without overflow or loss of precision, which is critical for maintaining data integrity.

Scenario 4: Proper Time Formatting

Details:
Description: Ensure that the CreatedAt field is correctly formatted according to RFC3339 standard.

Execution:
Arrange:
- Create a mock domain.Account with a known creation time.
- Initialize a createAccountPresenter instance.
Act:
- Call the Output method with the account.
Assert:
- Verify that the CreatedAt field in the output is a string formatted exactly as per RFC3339.

Validation:
Consistent time formatting is crucial for interoperability and data consistency across different parts of the system or external integrations.

Scenario 5: ID String Conversion

Details:
Description: Test that the account ID is correctly converted to a string representation.

Execution:
Arrange:
- Create a mock domain.Account with a known ID value.
- Initialize a createAccountPresenter instance.
Act:
- Call the Output method with the account.
Assert:
- Check that the ID field in the output is a string and matches the expected string representation of the account's ID.

Validation:
Proper ID conversion ensures that the unique identifier of the account is preserved and correctly represented in the output format.

Scenario 6: Empty String Handling

Details:
Description: Verify that the Output method correctly handles an account with empty string values for name and CPF.

Execution:
Arrange:
- Create a mock domain.Account with empty strings for Name and CPF.
- Initialize a createAccountPresenter instance.
Act:
- Call the Output method with the account containing empty strings.
Assert:
- Confirm that the Name and CPF fields in the output are empty strings, not null or undefined.

Validation:
This test ensures that the presenter maintains data integrity even when dealing with empty input, which is important for consistent data handling and avoiding null pointer exceptions in consuming code.
```

These scenarios cover a range of normal operations, edge cases, and potential issues that could arise when using the `Output` method of the `createAccountPresenter`. They focus on data integrity, proper type conversion, formatting, and handling of various input conditions.
*/

// ********RoostGPT********
package presenter

import (
"testing"
"time"

"github.com/gsabadini/go-clean-architecture/domain"
"github.com/gsabadini/go-clean-architecture/usecase"
)

func TestcreateAccountPresenterOutput(t *testing.T) {
tests := []struct {
name string
input domain.Account
expected usecase.CreateAccountOutput
}{
{
name: "Successful Account Output Conversion",
input: domain.Account{
id: "123",
name: "John Doe",
cpf: "12345678901",
balance: 1000.50,
createdAt: time.Date(2023, 5, 1, 10, 30, 0, 0, time.UTC),
},
expected: usecase.CreateAccountOutput{
ID: "123",
Name: "John Doe",
CPF: "12345678901",
Balance: 1000.50,
CreatedAt: "2023-05-01T10:30:00Z",
},
},
{
name: "Zero Balance Account Output",
input: domain.Account{
id: "456",
name: "Jane Smith",
cpf: "98765432109",
balance: 0.0,
createdAt: time.Date(2023, 5, 2, 14, 45, 0, 0, time.UTC),
},
expected: usecase.CreateAccountOutput{
ID: "456",
Name: "Jane Smith",
CPF: "98765432109",
Balance: 0.0,
CreatedAt: "2023-05-02T14:45:00Z",
},
},
{
name: "Maximum Value Handling",
input: domain.Account{
id: "789",
name: "Max Balance",
cpf: "11122233344",
balance: 1e18, // Example of a very large balance
createdAt: time.Date(2023, 5, 3, 9, 0, 0, 0, time.UTC),
},
expected: usecase.CreateAccountOutput{
ID: "789",
Name: "Max Balance",
CPF: "11122233344",
Balance: 1e18,
CreatedAt: "2023-05-03T09:00:00Z",
},
},
{
name: "Empty String Handling",
input: domain.Account{
id: "101",
name: "",
cpf: "",
balance: 100.0,
createdAt: time.Date(2023, 5, 4, 12, 15, 0, 0, time.UTC),
},
expected: usecase.CreateAccountOutput{
ID: "101",
Name: "",
CPF: "",
Balance: 100.0,
CreatedAt: "2023-05-04T12:15:00Z",
},
},
}

presenter := createAccountPresenter{}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := presenter.Output(tt.input)

if result.ID != tt.expected.ID {
t.Errorf("ID mismatch. Got %s, want %s", result.ID, tt.expected.ID)
}
if result.Name != tt.expected.Name {
t.Errorf("Name mismatch. Got %s, want %s", result.Name, tt.expected.Name)
}
if result.CPF != tt.expected.CPF {
t.Errorf("CPF mismatch. Got %s, want %s", result.CPF, tt.expected.CPF)
}
if result.Balance != tt.expected.Balance {
t.Errorf("Balance mismatch. Got %f, want %f", result.Balance, tt.expected.Balance)
}
if result.CreatedAt != tt.expected.CreatedAt {
t.Errorf("CreatedAt mismatch. Got %s, want %s", result.CreatedAt, tt.expected.CreatedAt)
}
})
}
}
167 changes: 167 additions & 0 deletions adapter/presenter/_create_transfer_newcreatetransferpresenter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
// ********RoostGPT********
/*
Test generated by RoostGPT for test mayankzbio-go-clean using AI Type Claude AI and AI Model claude-3-5-sonnet-20240620

ROOST_METHOD_HASH=NewCreateTransferPresenter_33f736514b
ROOST_METHOD_SIG_HASH=NewCreateTransferPresenter_b55d5650f6

FUNCTION_DEF=func NewCreateTransferPresenter() usecase.CreateTransferPresenter
Existing Test Information:
These test cases are already implemented and not included for test generation scenario:
File: go-clean-architecture/adapter/presenter/create_transfer_test.go
Test Cases:
[Test_createTransferPresenter_Output]

Based on the provided function and context, here are several test scenarios for the `NewCreateTransferPresenter` function:

Scenario 1: Create a New Transfer Presenter Successfully

Details:
Description: This test verifies that the NewCreateTransferPresenter function returns a valid CreateTransferPresenter interface.
Execution:
Arrange: No specific arrangement needed as the function doesn't take any parameters.
Act: Call NewCreateTransferPresenter() and store the result.
Assert: Check that the returned value is not nil and implements the usecase.CreateTransferPresenter interface.
Validation:
The assertion ensures that the function returns a non-nil value that satisfies the CreateTransferPresenter interface. This is crucial to confirm that the returned object can be used as expected in the application.

Scenario 2: Verify Returned Presenter Type

Details:
Description: This test checks if the returned presenter is of the correct underlying type (createTransferPresenter).
Execution:
Arrange: No specific arrangement needed.
Act: Call NewCreateTransferPresenter() and store the result.
Assert: Use type assertion to check if the returned value is of type createTransferPresenter.
Validation:
This test ensures that the correct concrete type is being returned, which is important for maintaining consistency in the codebase and avoiding potential type-related issues.

Scenario 3: Test Output Method of Returned Presenter

Details:
Description: This scenario tests the Output method of the returned presenter to ensure it correctly formats a Transfer object.
Execution:
Arrange: Create a sample domain.Transfer object with known values.
Act: Call NewCreateTransferPresenter() to get a presenter, then call its Output method with the sample Transfer.
Assert: Verify that the returned CreateTransferOutput matches the expected format and values.
Validation:
This test is crucial to ensure that the presenter correctly translates domain objects into the expected output format, which is a key responsibility of the presenter in the clean architecture.

Scenario 4: Consistency of Multiple Calls

Details:
Description: This test checks if multiple calls to NewCreateTransferPresenter return consistent results.
Execution:
Arrange: No specific arrangement needed.
Act: Call NewCreateTransferPresenter() multiple times and store the results.
Assert: Compare the returned presenters to ensure they are functionally equivalent.
Validation:
This test ensures that the function behaves consistently across multiple invocations, which is important for reliability in a production environment.

Scenario 5: Performance Test (Optional)

Details:
Description: This scenario measures the performance of creating multiple presenters.
Execution:
Arrange: Set up a benchmark test.
Act: Call NewCreateTransferPresenter() in a loop for a large number of iterations.
Assert: Measure and report the time taken.
Validation:
While not strictly necessary for functionality, this test can help identify any unexpected performance issues in presenter creation, which could be important in high-load scenarios.

These scenarios cover the creation of the presenter, its type, functionality, consistency, and performance. They ensure that the NewCreateTransferPresenter function works as expected in various situations, providing a comprehensive test suite for this part of the application.
*/

// ********RoostGPT********
package presenter

import (
"reflect"
"testing"
"time"

"github.com/gsabadini/go-clean-architecture/domain"
"github.com/gsabadini/go-clean-architecture/usecase"
)

func TestNewCreateTransferPresenter(t *testing.T) {
tests := []struct {
name string
want usecase.CreateTransferPresenter
}{
{
name: "Create a New Transfer Presenter Successfully",
want: createTransferPresenter{},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := NewCreateTransferPresenter()

if got == nil {
t.Error("NewCreateTransferPresenter() returned nil")
}

if _, ok := got.(usecase.CreateTransferPresenter); !ok {
t.Error("Returned value does not implement usecase.CreateTransferPresenter")
}

if reflect.TypeOf(got) != reflect.TypeOf(createTransferPresenter{}) {
t.Errorf("Expected type %T, got %T", createTransferPresenter{}, got)
}

// Test Output method
transfer := domain.Transfer{
id: func() domain.TransferID { return "test-id" },
accountOriginID: func() domain.AccountID { return "origin-id" },
accountDestinationID: func() domain.AccountID { return "destination-id" },
amount: func() domain.Money { return 100.0 },
createdAt: func() time.Time { return time.Now() },
}

output := got.Output(transfer)

if output.ID != transfer.id() {
t.Errorf("Expected ID %s, got %s", transfer.id(), output.ID)
}
if output.AccountOriginID != transfer.accountOriginID() {
t.Errorf("Expected AccountOriginID %s, got %s", transfer.accountOriginID(), output.AccountOriginID)
}
if output.AccountDestinationID != transfer.accountDestinationID() {
t.Errorf("Expected AccountDestinationID %s, got %s", transfer.accountDestinationID(), output.AccountDestinationID)
}
if output.Amount != float64(transfer.amount()) {
t.Errorf("Expected Amount %.2f, got %.2f", transfer.amount(), output.Amount)
}
if output.CreatedAt != transfer.createdAt().Format(time.RFC3339) {
t.Errorf("Expected CreatedAt %v, got %v", transfer.createdAt().Format(time.RFC3339), output.CreatedAt)
}
})
}

// Test consistency of multiple calls
t.Run("Consistency of Multiple Calls", func(t *testing.T) {
presenter1 := NewCreateTransferPresenter()
presenter2 := NewCreateTransferPresenter()

if reflect.TypeOf(presenter1) != reflect.TypeOf(presenter2) {
t.Errorf("Inconsistent types: %T vs %T", presenter1, presenter2)
}

transfer := domain.Transfer{
id: func() domain.TransferID { return "test-id" },
accountOriginID: func() domain.AccountID { return "origin-id" },
accountDestinationID: func() domain.AccountID { return "destination-id" },
amount: func() domain.Money { return 100.0 },
createdAt: func() time.Time { return time.Now() },
}

output1 := presenter1.Output(transfer)
output2 := presenter2.Output(transfer)

if !reflect.DeepEqual(output1, output2) {
t.Error("Inconsistent output from multiple presenters")
}
})
}
Loading