Skip to content

Commit

Permalink
Merge pull request #17 from flagship-io/feature-FS3-608
Browse files Browse the repository at this point in the history
Feature fs3 608
  • Loading branch information
kjose authored Aug 22, 2022
2 parents 8a27844 + 57f133e commit 43d9d69
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
git.mills.io/prologic/bitcask v1.0.2
github.com/aws/aws-sdk-go v1.40.45
github.com/flagship-io/flagship-common v0.0.18-beta.1
github.com/flagship-io/flagship-proto v0.0.15
github.com/flagship-io/flagship-proto v0.0.16
github.com/go-kit/kit v0.12.0
github.com/go-redis/redis/v8 v8.11.4
github.com/sirupsen/logrus v1.8.1
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ github.com/flagship-io/flagship-common v0.0.18-beta.1 h1:CBo4xCpGG4ui77GhGcOmejA
github.com/flagship-io/flagship-common v0.0.18-beta.1/go.mod h1:9NsiiubOPN6ZD8T4VvrSSwOWTloHTkoWftvRnmr4W7Y=
github.com/flagship-io/flagship-proto v0.0.15 h1:2sK9DWtnTkUEBiGtjLdwhMaaGsXuU+QRmAOhxlwj7bQ=
github.com/flagship-io/flagship-proto v0.0.15/go.mod h1:Nv5epf8wbbAEx6sAnjPumFy+YQOClXyXlxZzUMUqidw=
github.com/flagship-io/flagship-proto v0.0.16-0.20220816134540-8b1aa2ad5a0a h1:4FmZvUtZ2KjDD7V7nSJFodiAH7RYKUnMd0EQvHCFEYU=
github.com/flagship-io/flagship-proto v0.0.16-0.20220816134540-8b1aa2ad5a0a/go.mod h1:Nv5epf8wbbAEx6sAnjPumFy+YQOClXyXlxZzUMUqidw=
github.com/flagship-io/flagship-proto v0.0.16 h1:Mz/ljPweSR44Ek0moW5/yHPDz5DZO4fPTp+zHzC9nzQ=
github.com/flagship-io/flagship-proto v0.0.16/go.mod h1:Nv5epf8wbbAEx6sAnjPumFy+YQOClXyXlxZzUMUqidw=
github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/franela/goblin v0.0.0-20210519012713-85d372ac71e2/go.mod h1:VzmDKDJVZI3aJmnRI9VjAn9nJ8qPPsN1fqzr9dqInIo=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
Expand Down
3 changes: 2 additions & 1 deletion internal/apilogic/handle_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func BuildHandleRequest(req *http.Request) (*handle.Request, error) {
handleRequest.ExposeAllKeys = exposeAllKeys == "true"
}

handleRequest.SendContextEvent = req.URL.Query().Get("sendContextEvent") != "false"
hasVisitorConsented := decisionRequest.VisitorConsent == nil || decisionRequest.VisitorConsent.GetValue()
handleRequest.SendContextEvent = req.URL.Query().Get("sendContextEvent") != "false" && hasVisitorConsented
handleRequest.DecisionRequest = decisionRequest
handleRequest.FullVisitorContext = &targeting.Context{
Standard: decisionRequest.GetContext(),
Expand Down
53 changes: 53 additions & 0 deletions internal/apilogic/handle_request_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package apilogic

import (
"io"
"net/http"
"net/url"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func TestBuildHandleRequestHasCorrectSendContextEvent(t *testing.T) {
tests := map[string]struct {
queryVisitorConsent string
bodyVisitorConsent string
result bool
}{
"VisitorConsentEmpty": {"", "", true},
"BodyVisitorConsentFalse": {"\"visitor_consent\": false,", "", false},
"BodyVisitorConsentTrue": {"\"visitor_consent\": true,", "", true},
"QueryVisitorConsentFalse": {"", "sendContextEvent=false", false},
"QueryVisitorConsentTrue": {"", "sendContextEvent=true", true},
"VisitorConsentBothTrue": {"\"visitor_consent\": true,", "sendContextEvent=true", true},
"VisitorConsentBothFalse": {"\"visitor_consent\": false,", "sendContextEvent=false", false},
"VisitorConsentBothDifferent": {"\"visitor_consent\": true,", "sendContextEvent=false", false},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
body := `{
"visitor_id": "123",
` + test.queryVisitorConsent + `
"context": {}
}`

req := &http.Request{
URL: &url.URL{
RawQuery: test.bodyVisitorConsent,
},
Body: io.NopCloser(strings.NewReader(body)),
Method: "POST",
}

hr, err := BuildHandleRequest(req)

assert.NotNil(t, hr)
assert.Nil(t, err)
assert.Equal(t, test.result, hr.SendContextEvent)
})
}

}

0 comments on commit 43d9d69

Please sign in to comment.