Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cloudlending
- import (
- "reflect"
- "strings"
- "testing"
- "github.com/nimajalali/go-force/forcejson"
- "github.com/stretchr/testify/assert"
- )
- func TestAppFieldsMatchStructTags(t *testing.T) {
- app := Application{}
- fType := reflect.TypeOf(app)
- actualtags := []string{}
- for i := 0; i < fType.NumField(); i++ {
- f := fType.Field(i)
- if f.Tag != "" && f.Tag.Get("force") != "-" {
- actualtags = append(actualtags, strings.Replace(f.Tag.Get("force"), ",omitempty", "", -1))
- }
- }
- assert.ElementsMatch(t, actualtags, app.Fields(write), "Expected Application.Fields(write) to match")
- }
- func TestForceJSONMarshalPartialApp(t *testing.T) {
- falsePtr := false
- truePtr := true
- t.Run("marshals boolean pointers with set values", func(t *testing.T) {
- application := Application{
- InArrears: &truePtr,
- PerformAutoDecisioning: &falsePtr,
- }
- b, err := forcejson.Marshal(application)
- if err != nil {
- t.Error(err)
- }
- expectedJSON := `{"attributes":{},"genesis__Arrears__c":true,"genesis__Auto_Decisioning__c":false}`
- if string(b) != expectedJSON {
- t.Errorf("Expected Application to Marshal as :%s, but got %s", expectedJSON, string(b))
- }
- })
- t.Run("doesn't marshal false non-pointer bools", func(t *testing.T) {
- application := Application{
- AuthorizedS1S: false,
- AcceptCreditGuideDisclosure: true,
- }
- b, err := forcejson.Marshal(application)
- if err != nil {
- t.Error(err)
- }
- expectedJSON := `{"attributes":{},"Terms_and_Conditions_pl__c":true}`
- if string(b) != expectedJSON {
- t.Errorf("Expected Application to Marshal as :%s, but got %s", expectedJSON, string(b))
- }
- })
- }
Add Comment
Please, Sign In to add comment