PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/ad-proxy/admin/ad_proxy_admin_test.go

https://bitbucket.org/matchmove/go-commons
Go | 122 lines | 95 code | 27 blank | 0 comment | 0 complexity | 7497609793ac7ec2e6d3947edc1b8d2b MD5 | raw file
  1. package admin_test
  2. import (
  3. "math/rand"
  4. "strconv"
  5. "testing"
  6. "time"
  7. "github.com/stretchr/testify/assert"
  8. adProxy "bitbucket.org/matchmove/go-commons/ad-proxy/admin"
  9. "bitbucket.org/matchmove/go-tools/secure"
  10. )
  11. var (
  12. headers = make(map[string]interface{})
  13. AD_URL = "https://cp-alpha-ad-api-uat.mmvpay.com"
  14. PostStoreResponse = adProxy.PostAdminStoreResponse{}
  15. userHash string
  16. )
  17. func Test_PostActivityNoRequestError(t *testing.T) {
  18. req := adProxy.PostAdminActivitiesRequest{
  19. Details: "{'resource:create-role,payload:[]'}",
  20. }
  21. res := adProxy.PostAdminActivitiesResponse{}
  22. headers["X-MM-Tenant-Code"] = "mss"
  23. headers["X-MM-Tenant-HashId"] = "fsfsdf334"
  24. res, err := adProxy.PostAdminActivity(AD_URL, headers, req)
  25. assert.NotEqual(t, 200, res.Status)
  26. assert.NotEqual(t, nil, err)
  27. }
  28. func Test_PostActivityNoRequestSuccess(t *testing.T) {
  29. req := adProxy.PostAdminActivitiesRequest{
  30. Details: "{'resource:create-role,payload:[]'}",
  31. }
  32. res := adProxy.PostAdminActivitiesResponse{}
  33. headers["X-MM-Admin-Email"] = "test+1@test.com"
  34. headers["X-MM-Tenant-Code"] = "mss"
  35. headers["X-MM-Tenant-HashId"] = "fsfsdf334"
  36. res, err := adProxy.PostAdminActivity(AD_URL, headers, req)
  37. assert.Equal(t, 200, res.Status)
  38. assert.Equal(t, nil, err)
  39. }
  40. func Test_PostStoreSuccess(t *testing.T) {
  41. rand.Seed(time.Now().UnixNano())
  42. req := adProxy.PostAdminStoreRequest{
  43. FirstName: "TestFname",
  44. LastName: "TestLname",
  45. Email: "anant+1" + strconv.Itoa(rand.Intn(100000000)) + "@matchmove.com",
  46. Password: "Password@123",
  47. UserVerifyLink: "http://google.com/test.php",
  48. Mobile: strconv.Itoa(rand.Intn(100000000)),
  49. UserHashID: "userms_hashid_new1" + secure.RandomString(5, []rune(secure.RuneAlpha)),
  50. }
  51. res := adProxy.PostAdminStoreResponse{}
  52. headers["X-MM-Admin-Email"] = "test+1@test.com"
  53. headers["X-MM-Tenant-Code"] = "mss"
  54. headers["X-MM-Tenant-HashId"] = "fsfsdf334"
  55. headers["X-MM-Device-Details"] = `"ip":"10.232.21.103","device":"Desktop","browser":"Firefox"`
  56. res, err := adProxy.PostAdminStore(AD_URL, headers, req)
  57. assert.Equal(t, 200, res.Status)
  58. assert.Equal(t, nil, err)
  59. userHash = req.UserHashID
  60. }
  61. func Test_PutUpdateSuccess(t *testing.T) {
  62. req := adProxy.PutAdminUpdateRequest{
  63. UserHashID: userHash,
  64. }
  65. res := adProxy.PutAdminUpdateResponse{}
  66. headers["X-MM-Admin-Email"] = "test+1@test.com"
  67. headers["X-MM-Tenant-Code"] = "mss"
  68. headers["Content-Type"] = "application/x-www-form-urlencoded"
  69. res, err := adProxy.PutAdminUpdate(AD_URL, headers, req)
  70. assert.Equal(t, 200, res.Status)
  71. assert.Equal(t, nil, err)
  72. }
  73. func Test_DeleteSuccess(t *testing.T) {
  74. req := adProxy.DeleteAdminRequest{
  75. UserHashID: userHash,
  76. }
  77. res := adProxy.DeleteAdminResponse{}
  78. headers["X-MM-Admin-Email"] = "test+1@test.com"
  79. headers["X-MM-Tenant-Code"] = "mss"
  80. res, err := adProxy.DeleteAdmin(AD_URL, headers, req)
  81. assert.Equal(t, 200, res.Status)
  82. assert.Equal(t, nil, err)
  83. }
  84. func Test_EditSuccess(t *testing.T) {
  85. req := adProxy.EditAdminRequest{
  86. UserHashID: userHash,
  87. Mobile: strconv.Itoa(rand.Intn(100000000)),
  88. }
  89. res := adProxy.EditAdminResponse{}
  90. headers["X-MM-Admin-Email"] = "test+1@test.com"
  91. headers["X-MM-Tenant-Code"] = "mss"
  92. res, _, err := adProxy.EditAdminDetails(AD_URL, headers, req)
  93. assert.Equal(t, 200, res.Status)
  94. assert.Equal(t, nil, err)
  95. }