feat(contacts): filter by referer

This commit is contained in:
2026-06-07 06:00:38 +08:00
parent 6df3fead53
commit 46eb7aafbd
3 changed files with 36 additions and 5 deletions
@@ -933,6 +933,31 @@ func (s *ContactHandlerCRUDTestSuite) TestFilter_ChatwootPayloadStandardAndAddit
s.Equal(float64(s.contact.ID), payload[0].(map[string]interface{})["id"])
}
func (s *ContactHandlerCRUDTestSuite) TestFilter_ContactRefererFromFrontendProvider() {
s.contact.AdditionalAttributes = datatypes.JSON(`{"referer":"https://docs.example.com/pricing"}`)
s.Require().NoError(s.db.Save(s.contact).Error)
other := &model.Contact{AccountID: s.account.ID, Name: "Other User", Email: "other@example.com", AdditionalAttributes: datatypes.JSON(`{"referer":"https://blog.example.com/news"}`)}
s.Require().NoError(s.db.Create(other).Error)
body, _ := json.Marshal(map[string]interface{}{
"payload": []map[string]interface{}{
{"attribute_key": "referer", "filter_operator": "contains", "values": []string{"pricing"}},
},
})
w := httptest.NewRecorder()
req, _ := http.NewRequest("POST", fmt.Sprintf("/api/v1/accounts/%d/contacts/filter", s.account.ID), bytes.NewReader(body))
req.Header.Set("Content-Type", "application/json")
s.router.ServeHTTP(w, req)
s.Equal(http.StatusOK, w.Code, w.Body.String())
var resp map[string]interface{}
s.NoError(json.Unmarshal(w.Body.Bytes(), &resp))
payload := resp["payload"].([]interface{})
s.Len(payload, 1)
s.Equal(float64(s.contact.ID), payload[0].(map[string]interface{})["id"])
}
func (s *ContactHandlerCRUDTestSuite) TestFilter_ChatwootPayloadLabelsAndDate() {
tag := &model.Tag{AccountID: s.account.ID, Name: "support", Color: "#1f93ff"}
s.Require().NoError(s.db.Create(tag).Error)