@@ -17,6 +17,7 @@ package res_test
1717import (
1818 "testing"
1919
20+ "github.com/bytedance/sonic"
2021 "github.com/stretchr/testify/require"
2122
2223 "github.com/bangumi/server/internal/model"
@@ -29,7 +30,7 @@ func TestToSubjectV0_TagTotalCount(t *testing.T) {
2930 subject := model.Subject {
3031 Tags : []model.Tag {{Name : "tag" , Count : 10 , TotalCount : 100 }},
3132 }
32- want := []res.SubjectTag {{Name : "tag" , Count : 10 , TotalCont : 100 }}
33+ want := []res.SubjectTag {{Name : "tag" , Count : 10 , TotalCount : 100 }}
3334
3435 require .Equal (t , want , res .ToSubjectV0 (subject , 0 , nil ).Tags )
3536}
@@ -40,7 +41,16 @@ func TestToSlimSubjectV0_TagTotalCount(t *testing.T) {
4041 subject := model.Subject {
4142 Tags : []model.Tag {{Name : "tag" , Count : 10 , TotalCount : 100 }},
4243 }
43- want := []res.SubjectTag {{Name : "tag" , Count : 10 , TotalCont : 100 }}
44+ want := []res.SubjectTag {{Name : "tag" , Count : 10 , TotalCount : 100 }}
4445
4546 require .Equal (t , want , res .ToSlimSubjectV0 (subject ).Tags )
4647}
48+
49+ func TestSubjectTag_JSON (t * testing.T ) {
50+ t .Parallel ()
51+
52+ data , err := sonic .Marshal (res.SubjectTag {Name : "tag" , Count : 10 , TotalCount : 100 })
53+ require .NoError (t , err )
54+ require .JSONEq (t , `{"name":"tag","count":10,"total_count":100}` , string (data ))
55+ require .NotContains (t , string (data ), "total_cont" )
56+ }
0 commit comments