Guest User

Untitled

a guest
Jan 22nd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. package cloudlending
  2.  
  3. import (
  4. "reflect"
  5. "strings"
  6. "testing"
  7.  
  8. "github.com/nimajalali/go-force/forcejson"
  9. "github.com/stretchr/testify/assert"
  10. )
  11.  
  12. func TestAppFieldsMatchStructTags(t *testing.T) {
  13.  
  14. app := Application{}
  15. fType := reflect.TypeOf(app)
  16.  
  17. actualtags := []string{}
  18. for i := 0; i < fType.NumField(); i++ {
  19. f := fType.Field(i)
  20. if f.Tag != "" && f.Tag.Get("force") != "-" {
  21. actualtags = append(actualtags, strings.Replace(f.Tag.Get("force"), ",omitempty", "", -1))
  22. }
  23. }
  24.  
  25. assert.ElementsMatch(t, actualtags, app.Fields(write), "Expected Application.Fields(write) to match")
  26. }
  27.  
  28. func TestForceJSONMarshalPartialApp(t *testing.T) {
  29.  
  30. falsePtr := false
  31. truePtr := true
  32.  
  33. t.Run("marshals boolean pointers with set values", func(t *testing.T) {
  34. application := Application{
  35. InArrears: &truePtr,
  36. PerformAutoDecisioning: &falsePtr,
  37. }
  38.  
  39. b, err := forcejson.Marshal(application)
  40. if err != nil {
  41. t.Error(err)
  42. }
  43.  
  44. expectedJSON := `{"attributes":{},"genesis__Arrears__c":true,"genesis__Auto_Decisioning__c":false}`
  45. if string(b) != expectedJSON {
  46. t.Errorf("Expected Application to Marshal as :%s, but got %s", expectedJSON, string(b))
  47. }
  48. })
  49.  
  50. t.Run("doesn't marshal false non-pointer bools", func(t *testing.T) {
  51. application := Application{
  52. AuthorizedS1S: false,
  53. AcceptCreditGuideDisclosure: true,
  54. }
  55.  
  56. b, err := forcejson.Marshal(application)
  57. if err != nil {
  58. t.Error(err)
  59. }
  60.  
  61. expectedJSON := `{"attributes":{},"Terms_and_Conditions_pl__c":true}`
  62. if string(b) != expectedJSON {
  63. t.Errorf("Expected Application to Marshal as :%s, but got %s", expectedJSON, string(b))
  64. }
  65. })
  66. }
Add Comment
Please, Sign In to add comment