(t *testing.T)
| 76 | } |
| 77 | |
| 78 | func TestGetIdentity(t *testing.T) { |
| 79 | datasource, mock, err := newTestDataSource() |
| 80 | if err != nil { |
| 81 | t.Fatalf("Error creating test data source: %s", err) |
| 82 | } |
| 83 | |
| 84 | d, err := NewLedgerForge(datasource) |
| 85 | if err != nil { |
| 86 | t.Fatalf("Error creating LedgerForge instance: %s", err) |
| 87 | } |
| 88 | |
| 89 | testID := "test-id" |
| 90 | |
| 91 | // Expect transaction to begin |
| 92 | mock.ExpectBegin() |
| 93 | |
| 94 | // Updated mock data with all fields |
| 95 | row := sqlmock.NewRows([]string{ |
| 96 | "identity_id", "identity_type", "first_name", "last_name", "other_names", "gender", "dob", |
| 97 | "email_address", "phone_number", "nationality", "organization_name", "category", |
| 98 | "street", "country", "state", "post_code", "city", "created_at", "meta_data", |
| 99 | }).AddRow( |
| 100 | testID, "Individual", "John", "Doe", "Other Names", "Male", time.Now(), |
| 101 | "john@example.com", "1234567890", "Nationality", "Organization", "Category", |
| 102 | "Street", "Country", "State", "PostCode", "City", time.Now(), `{"key":"value"}`, |
| 103 | ) |
| 104 | |
| 105 | // Updated query to match the actual method's query |
| 106 | mock.ExpectQuery("SELECT .* FROM ledgerforge.identity WHERE identity_id ="). |
| 107 | WithArgs(testID). |
| 108 | WillReturnRows(row) |
| 109 | |
| 110 | // Expect transaction to commit |
| 111 | mock.ExpectCommit() |
| 112 | |
| 113 | result, err := d.GetIdentity(testID) |
| 114 | |
| 115 | // Updated assertions for all fields |
| 116 | assert.NoError(t, err) |
| 117 | assert.NotNil(t, result) |
| 118 | assert.Equal(t, testID, result.IdentityID) |
| 119 | assert.Equal(t, "Individual", result.IdentityType) |
| 120 | assert.Equal(t, "John", result.FirstName) |
| 121 | // ... continue with assertions for all fields ... |
| 122 | |
| 123 | if err := mock.ExpectationsWereMet(); err != nil { |
| 124 | t.Errorf("there were unfulfilled expectations: %s", err) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | func TestGetAllIdentities(t *testing.T) { |
| 129 | datasource, mock, err := newTestDataSource() |
nothing calls this directly
no test coverage detected