@@ -20,16 +20,18 @@ func TestProfileFromProtobufMissingModInfo(t *testing.T) {
20
20
}
21
21
22
22
func TestNormalizeProfileProtobuf (t * testing.T ) {
23
- var exampleFee = & pb.Moderator_Price {
24
- BigAmount : "10" ,
25
- AmountCurrency : & pb.CurrencyDefinition {
26
- Code : "BTC" ,
27
- Divisibility : 8 ,
28
- },
29
- }
23
+ var (
24
+ exampleFee = & pb.Moderator_Price {
25
+ BigAmount : "10" ,
26
+ AmountCurrency : & pb.CurrencyDefinition {
27
+ Code : "BTC" ,
28
+ Divisibility : 8 ,
29
+ },
30
+ }
31
+ )
30
32
var examples = []struct {
31
33
example func () * pb.Profile
32
- validate func (* pb.Profile , * testing. T )
34
+ validate func (* pb.Profile )
33
35
}{
34
36
{ // profile with percent fee should remove non-percent fee values
35
37
example : func () * pb.Profile {
@@ -39,7 +41,7 @@ func TestNormalizeProfileProtobuf(t *testing.T) {
39
41
p .ModeratorInfo .Fee .Percentage = 1.1
40
42
return p
41
43
},
42
- validate : func (p * pb.Profile , t * testing. T ) {
44
+ validate : func (p * pb.Profile ) {
43
45
if p .ModeratorInfo .Fee .FixedFee != nil {
44
46
t .Errorf ("expected fixed fee to be removed, but was not" )
45
47
}
@@ -53,7 +55,7 @@ func TestNormalizeProfileProtobuf(t *testing.T) {
53
55
p .ModeratorInfo .Fee .Percentage = 1.1
54
56
return p
55
57
},
56
- validate : func (p * pb.Profile , t * testing. T ) {
58
+ validate : func (p * pb.Profile ) {
57
59
if p .ModeratorInfo .Fee .Percentage != 0 {
58
60
t .Errorf ("expected percentage to be zero, but was not" )
59
61
}
@@ -66,7 +68,7 @@ func TestNormalizeProfileProtobuf(t *testing.T) {
66
68
p .ModeratorInfo .Fee .FixedFee = exampleFee
67
69
return p
68
70
},
69
- validate : func (p * pb.Profile , t * testing. T ) {
71
+ validate : func (p * pb.Profile ) {
70
72
if actual := p .ModeratorInfo .Fee .FixedFee .CurrencyCode ; actual != exampleFee .AmountCurrency .Code {
71
73
t .Errorf ("expected legacy code to be (%s), but was (%s)" , exampleFee .AmountCurrency .Code , actual )
72
74
}
@@ -80,6 +82,27 @@ func TestNormalizeProfileProtobuf(t *testing.T) {
80
82
}
81
83
},
82
84
},
85
+ { // legacy v4 profile with fixed fee should populate current schema
86
+ example : func () * pb.Profile {
87
+ pb := factory .MustLoadProfileFixture ("v4-profile-moderator-fixed-fee" )
88
+ rp , err := repo .UnmarshalJSONProfile (pb )
89
+ if err != nil {
90
+ t .Fatal (err )
91
+ }
92
+ p := rp .GetProtobuf ()
93
+ p .ModeratorInfo .Fee .FixedFee .CurrencyCode = "BTC"
94
+ p .ModeratorInfo .Fee .FixedFee .Amount = 10
95
+ return p
96
+ },
97
+ validate : func (p * pb.Profile ) {
98
+ if actual := p .ModeratorInfo .Fee .FixedFee .AmountCurrency .Code ; actual != "BTC" {
99
+ t .Errorf ("expected fee amount currency code to be (%s), but was (%s)" , "BTC" , actual )
100
+ }
101
+ if actualAmt := p .ModeratorInfo .Fee .FixedFee .BigAmount ; actualAmt != "10" {
102
+ t .Errorf ("expected fee amount to be (%s), but was (%s)" , "10" , actualAmt )
103
+ }
104
+ },
105
+ },
83
106
}
84
107
85
108
for i , e := range examples {
@@ -91,7 +114,7 @@ func TestNormalizeProfileProtobuf(t *testing.T) {
91
114
t .Errorf ("failed normalization on example (%d): %s" , i , err )
92
115
continue
93
116
}
94
- e .validate (p .GetProtobuf (), t )
117
+ e .validate (p .GetProtobuf ())
95
118
}
96
119
}
97
120
0 commit comments