-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CCPA Phase 1: AMP Endpoint #1125
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,77 @@ | ||
package privacy | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/mxmCherry/openrtb" | ||
"github.com/prebid/prebid-server/privacy/ccpa" | ||
"github.com/prebid/prebid-server/privacy/gdpr" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
func TestWrite(t *testing.T) { | ||
polciies := Policies{ | ||
GDPR: gdpr.Policy{Consent: "anyConsent"}, | ||
CCPA: ccpa.Policy{Value: "anyValue"}, | ||
} | ||
expectedRequest := &openrtb.BidRequest{ | ||
Regs: &openrtb.Regs{ | ||
Ext: json.RawMessage(`{"us_privacy":"anyValue"}`)}, | ||
User: &openrtb.User{ | ||
Ext: json.RawMessage(`{"consent":"anyConsent"}`)}, | ||
} | ||
|
||
func TestWritePolicieNone(t *testing.T) { | ||
request := &openrtb.BidRequest{} | ||
err := polciies.Write(request) | ||
policyWriters := []policyWriter{} | ||
|
||
err := writePolicies(request, policyWriters) | ||
|
||
assert.NoError(t, err) | ||
assert.Equal(t, expectedRequest, request) | ||
} | ||
|
||
func TestWriteWithErrorFromGDPR(t *testing.T) { | ||
polciies := Policies{ | ||
GDPR: gdpr.Policy{Consent: "anyConsent"}, | ||
CCPA: ccpa.Policy{Value: "anyValue"}, | ||
} | ||
request := &openrtb.BidRequest{ | ||
User: &openrtb.User{ | ||
Ext: json.RawMessage(`malformed`)}, | ||
func TestWritePolicieOne(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless nitpick: "TestWritePolicyOne" |
||
request := &openrtb.BidRequest{} | ||
mockWriter := new(mockPolicyWriter) | ||
policyWriters := []policyWriter{ | ||
mockWriter, | ||
} | ||
|
||
err := polciies.Write(request) | ||
mockWriter.On("Write", request).Return(nil).Once() | ||
|
||
assert.Error(t, err) | ||
err := writePolicies(request, policyWriters) | ||
|
||
assert.NoError(t, err) | ||
mockWriter.AssertExpectations(t) | ||
} | ||
|
||
func TestWriteWithErrorFromCCPA(t *testing.T) { | ||
polciies := Policies{ | ||
GDPR: gdpr.Policy{Consent: "anyConsent"}, | ||
CCPA: ccpa.Policy{Value: "anyValue"}, | ||
func TestWritePolicieMany(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless nitpick: "TestWritePoliciesMany" |
||
request := &openrtb.BidRequest{} | ||
mockWriter1 := new(mockPolicyWriter) | ||
mockWriter2 := new(mockPolicyWriter) | ||
policyWriters := []policyWriter{ | ||
mockWriter1, mockWriter2, | ||
} | ||
request := &openrtb.BidRequest{ | ||
Regs: &openrtb.Regs{ | ||
Ext: json.RawMessage(`malformed`)}, | ||
|
||
mockWriter1.On("Write", request).Return(nil).Once() | ||
mockWriter2.On("Write", request).Return(nil).Once() | ||
|
||
err := writePolicies(request, policyWriters) | ||
|
||
assert.NoError(t, err) | ||
mockWriter1.AssertExpectations(t) | ||
mockWriter2.AssertExpectations(t) | ||
} | ||
|
||
func TestWritePolicieError(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless nitpick: "TestWritePolicyError" |
||
request := &openrtb.BidRequest{} | ||
mockWriter := new(mockPolicyWriter) | ||
policyWriters := []policyWriter{ | ||
mockWriter, | ||
} | ||
|
||
err := polciies.Write(request) | ||
expectedErr := errors.New("anyError") | ||
mockWriter.On("Write", request).Return(expectedErr).Once() | ||
|
||
err := writePolicies(request, policyWriters) | ||
|
||
assert.Error(t, err, expectedErr) | ||
mockWriter.AssertExpectations(t) | ||
} | ||
|
||
type mockPolicyWriter struct { | ||
mock.Mock | ||
} | ||
|
||
assert.Error(t, err) | ||
func (m *mockPolicyWriter) Write(req *openrtb.BidRequest) error { | ||
args := m.Called(req) | ||
return args.Error(0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless nitpick: "TestWritePolicyNone"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! Ooops.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed everywhere to TestWritePoliciesNone since its testing the private writePolicies func.