fix list outgoing notificaions not to include which are assigned to user itself, small prompt enhancement
This commit is contained in:
@@ -77,7 +77,7 @@ func (n *Notifications) ListOutgoing(ctx context.Context, initiatorID uuid.UUID)
|
||||
rows, err := n.conn.QueryContext(ctx, `
|
||||
SELECT id, user_id, initiator_id, scheduled_at, content, repeat_on
|
||||
FROM notifications
|
||||
WHERE initiator_id = $1
|
||||
WHERE initiator_id = $1 AND user_id != initiator_id
|
||||
ORDER BY scheduled_at DESC
|
||||
`, initiatorID)
|
||||
if err != nil {
|
||||
|
||||
@@ -36,9 +36,7 @@ func TestNotifications_ConcurrentPop(t *testing.T) {
|
||||
popped := make(chan uuid.UUID, 1000)
|
||||
|
||||
for range 10 {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
wg.Go(func() {
|
||||
for {
|
||||
notifs, err := db.notifications.Pop(ctx, 10)
|
||||
require.NoError(t, err)
|
||||
@@ -49,7 +47,7 @@ func TestNotifications_ConcurrentPop(t *testing.T) {
|
||||
popped <- n.ID
|
||||
}
|
||||
}
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
@@ -191,6 +189,37 @@ func TestNotifications_ListOutgoing_ScanError(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestNotifications_ListOutgoing_ExcludesSelfAssigned(t *testing.T) {
|
||||
db := setupTestDB(t)
|
||||
user := setupTestUser(t, db)
|
||||
contact := setupTestUser(t, db)
|
||||
|
||||
self := &database.Notification{
|
||||
ID: uuid.New(),
|
||||
UserID: user.ID,
|
||||
InitiatorID: user.ID,
|
||||
ScheduledAt: time.Now().UTC(),
|
||||
Content: "self reminder",
|
||||
RepeatOn: "",
|
||||
}
|
||||
outgoing := &database.Notification{
|
||||
ID: uuid.New(),
|
||||
UserID: contact.ID,
|
||||
InitiatorID: user.ID,
|
||||
ScheduledAt: time.Now().UTC().Add(time.Hour),
|
||||
Content: "reminder for friend",
|
||||
RepeatOn: "",
|
||||
}
|
||||
|
||||
db.Notifications().Push(t.Context(), self)
|
||||
db.Notifications().Push(t.Context(), outgoing)
|
||||
|
||||
notifs, err := db.Notifications().ListOutgoing(t.Context(), user.ID)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, notifs, 1)
|
||||
assert.Equal(t, "reminder for friend", notifs[0].Content)
|
||||
}
|
||||
|
||||
func TestNotifications_Delete_Error(t *testing.T) {
|
||||
conn, mock, _ := sqlmock.New()
|
||||
defer conn.Close()
|
||||
|
||||
+12
-11
@@ -47,7 +47,8 @@ FOCUS ONLY ON THE CURRENT MESSAGE - PAST MESSAGES ARE CONTEXT, NOT ORDERS
|
||||
NEVER REPEAT OLD QUESTIONS OR RESPOND TO ALREADY-HANDLED TOPICS
|
||||
MAX 4 MESSAGES PER RESPONSE TOTAL
|
||||
FOR QUESTIONS: MAX 2 MESSAGES (CONTEXT + QUESTION)
|
||||
YOU MAY "THINK" IN PLAIN TEXT BEFORE JSON — THIS TEXT IS STRIPPED AND NEVER SHOWN TO USER
|
||||
YOU MAY "THINK" IN PLAIN TEXT BEFORE JSON — THIS TEXT IS STRIPPED AND NEVER SHOWN TO USER (not interpreted by system at all)
|
||||
YOUR ANSWERS TO USER SHOULD ALWAYS BE PUT INSIDE MESSAGE COMMANDS
|
||||
`
|
||||
|
||||
onboarding = `
|
||||
@@ -151,13 +152,13 @@ const (
|
||||
AgeOld = "AGE OLD"
|
||||
)
|
||||
|
||||
var behaviourMap = map[[2]string]string{
|
||||
{GenderMale, AgeYoung}: behaviourManYoung,
|
||||
{GenderMale, AgeMiddle}: behaviourManMiddle,
|
||||
{GenderMale, AgeOld}: behaviourManOld,
|
||||
{GenderFemale, AgeYoung}: behaviourWomanYoung,
|
||||
{GenderFemale, AgeMiddle}: behaviourWomanMiddle,
|
||||
{GenderFemale, AgeOld}: behaviourWomanOld,
|
||||
var behaviourMapping = [6][3]string{ //nolint:gochecknoglobals // here not to use in-function mapping
|
||||
{GenderMale, AgeYoung, behaviourManYoung},
|
||||
{GenderMale, AgeMiddle, behaviourManMiddle},
|
||||
{GenderMale, AgeOld, behaviourManOld},
|
||||
{GenderFemale, AgeYoung, behaviourWomanYoung},
|
||||
{GenderFemale, AgeMiddle, behaviourWomanMiddle},
|
||||
{GenderFemale, AgeOld, behaviourWomanOld},
|
||||
}
|
||||
|
||||
type buildParams struct {
|
||||
@@ -205,9 +206,9 @@ func Build(user *user.User, source, content string, params ...any) string {
|
||||
b.WriteString(onboarding)
|
||||
}
|
||||
|
||||
for key, behaviour := range behaviourMap {
|
||||
if checkFacts(user, key[0], key[1]) {
|
||||
b.WriteString(behaviour)
|
||||
for _, entry := range behaviourMapping {
|
||||
if checkFacts(user, entry[0], entry[1]) {
|
||||
b.WriteString(entry[2])
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user