Skip to content

Commit

Permalink
🧹 add json marshal for scoring system (#4345)
Browse files Browse the repository at this point in the history
  • Loading branch information
arlimus authored Jul 16, 2024
1 parent 86ef7eb commit 696a674
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
17 changes: 17 additions & 0 deletions explorer/impact.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,23 @@ func (s *ScoringSystem) UnmarshalYAML(node *yaml.Node) error {
return nil
}

func (s *ScoringSystem) MarshalJSON() ([]byte, error) {
switch *s {
case ScoringSystem_WORST:
return []byte("highest impact"), nil
case ScoringSystem_WEIGHTED:
return []byte("weighted"), nil
case ScoringSystem_AVERAGE:
return []byte("average"), nil
case ScoringSystem_BANDED:
return []byte("banded"), nil
case ScoringSystem_DECAYED:
return []byte("decayed"), nil
default:
return []byte("unknown"), nil
}
}

func (s *ScoringSystem) MarshalYAML() (interface{}, error) {
switch *s {
case ScoringSystem_WORST:
Expand Down
14 changes: 12 additions & 2 deletions explorer/impact_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestParsing(t *testing.T) {
func TestImpactParsing(t *testing.T) {
tests := []struct {
title string
data string
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestParsing(t *testing.T) {
}
}

func TestMerging(t *testing.T) {
func TestImpactMerging(t *testing.T) {
tests := []struct {
title string
base *Impact
Expand Down Expand Up @@ -131,3 +131,13 @@ func TestMerging(t *testing.T) {
})
}
}

func TestScoringSystemParsing(t *testing.T) {
s := ScoringSystem_DECAYED
raw, err := json.Marshal(s)
require.NoError(t, err)

err = json.Unmarshal(raw, &s)
require.NoError(t, err)
assert.Equal(t, ScoringSystem_DECAYED, s)
}

0 comments on commit 696a674

Please sign in to comment.