Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Aug 18, 2023
1 parent 67edaa4 commit dba3fc1
Show file tree
Hide file tree
Showing 55 changed files with 187 additions and 11 deletions.
20 changes: 10 additions & 10 deletions envs/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Environment interface {
AllowedLanguages() []Language
DefaultCountry() Country
NumberFormat() *NumberFormat
RedactionPolicy() RedactionPolicy
InputCollation() Collation
RedactionPolicy() RedactionPolicy

DefaultLanguage() Language
DefaultLocale() Locale
Expand Down Expand Up @@ -65,8 +65,8 @@ func (e *environment) Timezone() *time.Location { return e.timezone }
func (e *environment) AllowedLanguages() []Language { return e.allowedLanguages }
func (e *environment) DefaultCountry() Country { return e.defaultCountry }
func (e *environment) NumberFormat() *NumberFormat { return e.numberFormat }
func (e *environment) RedactionPolicy() RedactionPolicy { return e.redactionPolicy }
func (e *environment) InputCollation() Collation { return e.inputCollation }
func (e *environment) RedactionPolicy() RedactionPolicy { return e.redactionPolicy }

// DefaultLanguage is the first allowed language
func (e *environment) DefaultLanguage() Language {
Expand Down Expand Up @@ -104,8 +104,8 @@ type envEnvelope struct {
AllowedLanguages []Language `json:"allowed_languages,omitempty" validate:"omitempty,dive,language"`
NumberFormat *NumberFormat `json:"number_format,omitempty"`
DefaultCountry Country `json:"default_country,omitempty" validate:"omitempty,country"`
InputCollation Collation `json:"input_collation"`
RedactionPolicy RedactionPolicy `json:"redaction_policy" validate:"omitempty,eq=none|eq=urns"`
InputCollation Collation `json:"input_collation,omitempty"`
}

// ReadEnvironment reads an environment from the given JSON
Expand All @@ -123,8 +123,8 @@ func ReadEnvironment(data json.RawMessage) (Environment, error) {
env.allowedLanguages = envelope.AllowedLanguages
env.defaultCountry = envelope.DefaultCountry
env.numberFormat = envelope.NumberFormat
env.redactionPolicy = envelope.RedactionPolicy
env.inputCollation = envelope.InputCollation
env.redactionPolicy = envelope.RedactionPolicy

tz, err := time.LoadLocation(envelope.Timezone)
if err != nil {
Expand All @@ -143,8 +143,8 @@ func (e *environment) toEnvelope() *envEnvelope {
AllowedLanguages: e.allowedLanguages,
DefaultCountry: e.defaultCountry,
NumberFormat: e.numberFormat,
RedactionPolicy: e.redactionPolicy,
InputCollation: e.inputCollation,
RedactionPolicy: e.redactionPolicy,
}
}

Expand Down Expand Up @@ -172,8 +172,8 @@ func NewBuilder() *EnvironmentBuilder {
allowedLanguages: nil,
defaultCountry: NilCountry,
numberFormat: DefaultNumberFormat,
redactionPolicy: RedactionPolicyNone,
inputCollation: CollationDefault,
redactionPolicy: RedactionPolicyNone,
},
}
}
Expand Down Expand Up @@ -210,13 +210,13 @@ func (b *EnvironmentBuilder) WithNumberFormat(numberFormat *NumberFormat) *Envir
return b
}

func (b *EnvironmentBuilder) WithRedactionPolicy(redactionPolicy RedactionPolicy) *EnvironmentBuilder {
b.env.redactionPolicy = redactionPolicy
func (b *EnvironmentBuilder) WithInputCollation(col Collation) *EnvironmentBuilder {
b.env.inputCollation = col
return b
}

func (b *EnvironmentBuilder) WithInputCollation(col Collation) *EnvironmentBuilder {
b.env.inputCollation = col
func (b *EnvironmentBuilder) WithRedactionPolicy(redactionPolicy RedactionPolicy) *EnvironmentBuilder {
b.env.redactionPolicy = redactionPolicy
return b
}

Expand Down
4 changes: 3 additions & 1 deletion envs/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ func TestEnvironmentMarshaling(t *testing.T) {
assert.Equal(t, []envs.Language{envs.Language("eng"), envs.Language("fra")}, env.AllowedLanguages())
assert.Equal(t, envs.Country("RW"), env.DefaultCountry())
assert.Equal(t, "en-RW", env.DefaultLocale().ToBCP47())
assert.Equal(t, envs.CollationDefault, env.InputCollation())
assert.Equal(t, envs.RedactionPolicyNone, env.RedactionPolicy())
assert.Nil(t, env.LocationResolver())

data, err := jsonx.Marshal(env)
require.NoError(t, err)
assert.Equal(t, string(data), `{"date_format":"DD-MM-YYYY","time_format":"tt:mm:ss","timezone":"Africa/Kigali","allowed_languages":["eng","fra"],"number_format":{"decimal_symbol":".","digit_grouping_symbol":","},"default_country":"RW","redaction_policy":"none"}`)
assert.Equal(t, string(data), `{"date_format":"DD-MM-YYYY","time_format":"tt:mm:ss","timezone":"Africa/Kigali","allowed_languages":["eng","fra"],"number_format":{"decimal_symbol":".","digit_grouping_symbol":","},"default_country":"RW","input_collation":"default","redaction_policy":"none"}`)
}

func TestEnvironmentEqual(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions flows/events/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ func TestEventMarshaling(t *testing.T) {
],
"date_format": "DD-MM-YYYY",
"default_country": "US",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
1 change: 1 addition & 0 deletions flows/triggers/testdata/TestTriggerMarshaling_manual.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
1 change: 1 addition & 0 deletions flows/triggers/testdata/TestTriggerMarshaling_msg.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"decimal_symbol": ".",
"digit_grouping_symbol": ","
},
"input_collation": "default",
"redaction_policy": "none"
},
"flow": {
Expand Down
2 changes: 2 additions & 0 deletions test/testdata/runner/airtime.test_successful_transfer.json
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -308,6 +309,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
2 changes: 2 additions & 0 deletions test/testdata/runner/all_actions.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -967,6 +968,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
4 changes: 4 additions & 0 deletions test/testdata/runner/brochure.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -147,6 +148,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -270,6 +272,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -439,6 +442,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
4 changes: 4 additions & 0 deletions test/testdata/runner/date_parse.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -133,6 +134,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -250,6 +252,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -409,6 +412,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
2 changes: 2 additions & 0 deletions test/testdata/runner/default_result.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
},
"environment": {
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -246,6 +247,7 @@
},
"environment": {
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
1 change: 1 addition & 0 deletions test/testdata/runner/empty.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"environment": {
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
8 changes: 8 additions & 0 deletions test/testdata/runner/enter_flow_loop.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -124,6 +125,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -272,6 +274,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -507,6 +510,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -649,6 +653,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -1031,6 +1036,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -1093,6 +1099,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down Expand Up @@ -1505,6 +1512,7 @@
"eng"
],
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
1 change: 1 addition & 0 deletions test/testdata/runner/enter_flow_terminal.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"environment": {
"date_format": "YYYY-MM-DD",
"input_collation": "default",
"number_format": {
"decimal_symbol": ".",
"digit_grouping_symbol": ","
Expand Down
Loading

0 comments on commit dba3fc1

Please sign in to comment.