(t *testing.T)
| 10085 | } |
| 10086 | |
| 10087 | func TestUpdateAIBridgeInterceptionEnded(t *testing.T) { |
| 10088 | t.Parallel() |
| 10089 | db, _ := dbtestutil.NewDB(t) |
| 10090 | |
| 10091 | t.Run("NonExistingInterception", func(t *testing.T) { |
| 10092 | t.Parallel() |
| 10093 | ctx := testutil.Context(t, testutil.WaitLong) |
| 10094 | |
| 10095 | got, err := db.UpdateAIBridgeInterceptionEnded(ctx, database.UpdateAIBridgeInterceptionEndedParams{ |
| 10096 | ID: uuid.New(), |
| 10097 | EndedAt: time.Now(), |
| 10098 | CredentialHint: "sk-a...efgh", |
| 10099 | }) |
| 10100 | require.ErrorContains(t, err, "no rows in result set") |
| 10101 | require.EqualValues(t, database.AIBridgeInterception{}, got) |
| 10102 | }) |
| 10103 | |
| 10104 | t.Run("OK", func(t *testing.T) { |
| 10105 | t.Parallel() |
| 10106 | ctx := testutil.Context(t, testutil.WaitLong) |
| 10107 | |
| 10108 | user := dbgen.User(t, db, database.User{}) |
| 10109 | interceptions := []database.AIBridgeInterception{} |
| 10110 | |
| 10111 | for _, uid := range []uuid.UUID{{1}, {2}, {3}} { |
| 10112 | insertParams := database.InsertAIBridgeInterceptionParams{ |
| 10113 | ID: uid, |
| 10114 | InitiatorID: user.ID, |
| 10115 | Metadata: json.RawMessage("{}"), |
| 10116 | Client: sql.NullString{String: "client", Valid: true}, |
| 10117 | CredentialKind: database.CredentialKindCentralized, |
| 10118 | } |
| 10119 | |
| 10120 | intc, err := db.InsertAIBridgeInterception(ctx, insertParams) |
| 10121 | require.NoError(t, err) |
| 10122 | require.Equal(t, uid, intc.ID) |
| 10123 | require.False(t, intc.EndedAt.Valid) |
| 10124 | require.True(t, intc.Client.Valid) |
| 10125 | require.Equal(t, "client", intc.Client.String) |
| 10126 | interceptions = append(interceptions, intc) |
| 10127 | } |
| 10128 | |
| 10129 | intc0 := interceptions[0] |
| 10130 | endedAt := time.Now() |
| 10131 | // Mark first interception as done |
| 10132 | updated, err := db.UpdateAIBridgeInterceptionEnded(ctx, database.UpdateAIBridgeInterceptionEndedParams{ |
| 10133 | ID: intc0.ID, |
| 10134 | EndedAt: endedAt, |
| 10135 | CredentialHint: "sk-a...efgh", |
| 10136 | }) |
| 10137 | require.NoError(t, err) |
| 10138 | require.EqualValues(t, updated.ID, intc0.ID) |
| 10139 | require.True(t, updated.EndedAt.Valid) |
| 10140 | require.WithinDuration(t, endedAt, updated.EndedAt.Time, 5*time.Second) |
| 10141 | require.Equal(t, "sk-a...efgh", updated.CredentialHint) |
| 10142 | |
| 10143 | // Updating first interception again should fail |
| 10144 | updated, err = db.UpdateAIBridgeInterceptionEnded(ctx, database.UpdateAIBridgeInterceptionEndedParams{ |
nothing calls this directly
no test coverage detected