(t *testing.T)
| 30 | ) |
| 31 | |
| 32 | func TestCreateIdentity_Success(t *testing.T) { |
| 33 | db, mock, err := sqlmock.New() |
| 34 | assert.NoError(t, err) |
| 35 | defer func() { _ = db.Close() }() |
| 36 | |
| 37 | ds := Datasource{Conn: db} |
| 38 | |
| 39 | identity := model.Identity{ |
| 40 | IdentityType: "individual", |
| 41 | FirstName: "John", |
| 42 | LastName: "Doe", |
| 43 | OtherNames: "JD", |
| 44 | Gender: "Male", |
| 45 | DOB: time.Now(), |
| 46 | EmailAddress: "john.doe@example.com", |
| 47 | PhoneNumber: "123456789", |
| 48 | Nationality: "US", |
| 49 | OrganizationName: "Acme Corp", |
| 50 | Category: "Customer", |
| 51 | Street: "123 Main St", |
| 52 | Country: "USA", |
| 53 | State: "CA", |
| 54 | PostCode: "90210", |
| 55 | City: "Los Angeles", |
| 56 | MetaData: map[string]interface{}{ |
| 57 | "key": "value", |
| 58 | }, |
| 59 | } |
| 60 | |
| 61 | metaDataJSON, err := json.Marshal(identity.MetaData) |
| 62 | assert.NoError(t, err) |
| 63 | |
| 64 | mock.ExpectExec("INSERT INTO ledgerforge.identity"). |
| 65 | WithArgs(sqlmock.AnyArg(), identity.IdentityType, identity.FirstName, identity.LastName, identity.OtherNames, identity.Gender, identity.DOB, identity.EmailAddress, identity.PhoneNumber, identity.Nationality, identity.OrganizationName, identity.Category, identity.Street, identity.Country, identity.State, identity.PostCode, identity.City, sqlmock.AnyArg(), metaDataJSON). |
| 66 | WillReturnResult(sqlmock.NewResult(1, 1)) |
| 67 | |
| 68 | createdIdentity, err := ds.CreateIdentity(identity) |
| 69 | assert.NoError(t, err) |
| 70 | assert.NotEmpty(t, createdIdentity.IdentityID) |
| 71 | assert.WithinDuration(t, time.Now(), createdIdentity.CreatedAt, time.Second) |
| 72 | } |
| 73 | |
| 74 | func TestCreateIdentity_Fail(t *testing.T) { |
| 75 | db, mock, err := sqlmock.New() |
nothing calls this directly
no test coverage detected