2022-02-14 06:06:36 -06:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUserConsentOptions_Verify(t *testing.T) {
|
|
|
|
type args struct {
|
|
|
|
configErrors *ConfigErrors
|
|
|
|
isMonolith bool
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields UserConsentOptions
|
|
|
|
args args
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "template dir not set",
|
|
|
|
fields: UserConsentOptions{
|
|
|
|
RequireAtRegistration: true,
|
|
|
|
},
|
|
|
|
args: struct {
|
|
|
|
configErrors *ConfigErrors
|
|
|
|
isMonolith bool
|
|
|
|
}{configErrors: &ConfigErrors{}, isMonolith: true},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "template dir set",
|
|
|
|
fields: UserConsentOptions{
|
|
|
|
RequireAtRegistration: true,
|
|
|
|
TemplateDir: "testdata/privacy",
|
|
|
|
},
|
|
|
|
args: struct {
|
|
|
|
configErrors *ConfigErrors
|
|
|
|
isMonolith bool
|
|
|
|
}{configErrors: &ConfigErrors{}, isMonolith: true},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "policy name not set",
|
|
|
|
fields: UserConsentOptions{
|
|
|
|
RequireAtRegistration: true,
|
|
|
|
TemplateDir: "testdata/privacy",
|
|
|
|
},
|
|
|
|
args: struct {
|
|
|
|
configErrors *ConfigErrors
|
|
|
|
isMonolith bool
|
|
|
|
}{configErrors: &ConfigErrors{}, isMonolith: true},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "policy name set",
|
|
|
|
fields: UserConsentOptions{
|
|
|
|
RequireAtRegistration: true,
|
|
|
|
TemplateDir: "testdata/privacy",
|
|
|
|
PolicyName: "Privacy policy",
|
|
|
|
},
|
|
|
|
args: struct {
|
|
|
|
configErrors *ConfigErrors
|
|
|
|
isMonolith bool
|
|
|
|
}{configErrors: &ConfigErrors{}, isMonolith: true},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "version not set",
|
|
|
|
fields: UserConsentOptions{
|
|
|
|
RequireAtRegistration: true,
|
|
|
|
TemplateDir: "testdata/privacy",
|
|
|
|
},
|
|
|
|
args: struct {
|
|
|
|
configErrors *ConfigErrors
|
|
|
|
isMonolith bool
|
|
|
|
}{configErrors: &ConfigErrors{}, isMonolith: true},
|
|
|
|
wantErr: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "everyhing required set",
|
|
|
|
fields: UserConsentOptions{
|
|
|
|
RequireAtRegistration: true,
|
|
|
|
TemplateDir: "./testdata/privacy",
|
|
|
|
Version: "1.0",
|
|
|
|
PolicyName: "Privacy policy",
|
2022-03-07 02:45:24 -06:00
|
|
|
FormSecret: "helloWorld",
|
|
|
|
BaseURL: "http://localhost",
|
2022-02-14 06:06:36 -06:00
|
|
|
},
|
|
|
|
args: struct {
|
|
|
|
configErrors *ConfigErrors
|
|
|
|
isMonolith bool
|
|
|
|
}{configErrors: &ConfigErrors{}, isMonolith: true},
|
|
|
|
wantErr: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
c := &UserConsentOptions{
|
2022-03-07 02:45:24 -06:00
|
|
|
Enabled: true,
|
|
|
|
BaseURL: tt.fields.BaseURL,
|
|
|
|
FormSecret: tt.fields.FormSecret,
|
2022-02-14 06:06:36 -06:00
|
|
|
RequireAtRegistration: tt.fields.RequireAtRegistration,
|
|
|
|
PolicyName: tt.fields.PolicyName,
|
|
|
|
Version: tt.fields.Version,
|
|
|
|
TemplateDir: tt.fields.TemplateDir,
|
|
|
|
SendServerNoticeToGuest: tt.fields.SendServerNoticeToGuest,
|
|
|
|
ServerNoticeContent: tt.fields.ServerNoticeContent,
|
|
|
|
BlockEventsError: tt.fields.BlockEventsError,
|
|
|
|
}
|
|
|
|
c.Verify(tt.args.configErrors, tt.args.isMonolith)
|
2022-03-07 02:45:24 -06:00
|
|
|
if !tt.wantErr && len(*tt.args.configErrors) > 0 {
|
2022-02-14 06:06:36 -06:00
|
|
|
t.Errorf("expected no errors, got '%+v'", tt.args.configErrors)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|