| 48 | }) |
| 49 | |
| 50 | func AuditLog(t testing.TB, db database.Store, seed database.AuditLog) database.AuditLog { |
| 51 | log, err := db.InsertAuditLog(genCtx, database.InsertAuditLogParams{ |
| 52 | ID: takeFirst(seed.ID, uuid.New()), |
| 53 | Time: takeFirst(seed.Time, dbtime.Now()), |
| 54 | UserID: takeFirst(seed.UserID, uuid.New()), |
| 55 | // Default to the nil uuid. So by default audit logs are not org scoped. |
| 56 | OrganizationID: takeFirst(seed.OrganizationID), |
| 57 | Ip: pqtype.Inet{ |
| 58 | IPNet: takeFirstIP(seed.Ip.IPNet, net.IPNet{}), |
| 59 | Valid: takeFirst(seed.Ip.Valid, false), |
| 60 | }, |
| 61 | UserAgent: sql.NullString{ |
| 62 | String: takeFirst(seed.UserAgent.String, ""), |
| 63 | Valid: takeFirst(seed.UserAgent.Valid, false), |
| 64 | }, |
| 65 | ResourceType: takeFirst(seed.ResourceType, database.ResourceTypeOrganization), |
| 66 | ResourceID: takeFirst(seed.ResourceID, uuid.New()), |
| 67 | ResourceTarget: takeFirst(seed.ResourceTarget, uuid.NewString()), |
| 68 | Action: takeFirst(seed.Action, database.AuditActionCreate), |
| 69 | Diff: takeFirstSlice(seed.Diff, []byte("{}")), |
| 70 | StatusCode: takeFirst(seed.StatusCode, 200), |
| 71 | AdditionalFields: takeFirstSlice(seed.AdditionalFields, []byte("{}")), |
| 72 | RequestID: takeFirst(seed.RequestID, uuid.New()), |
| 73 | ResourceIcon: takeFirst(seed.ResourceIcon, ""), |
| 74 | }) |
| 75 | require.NoError(t, err, "insert audit log") |
| 76 | return log |
| 77 | } |
| 78 | |
| 79 | func Chat(t testing.TB, db database.Store, seed database.Chat) database.Chat { |
| 80 | t.Helper() |