PageRenderTime 58ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/api/api/endpoints/subscription_integration_test.go

https://gitlab.com/epicglue/api
Go | 164 lines | 22 code | 13 blank | 129 comment | 2 complexity | c2b471407f5eed41234932968e27c187 MD5 | raw file
  1. // +build integration
  2. package endpoints_test
  3. import (
  4. "bitbucket.org/epicglue/api/helpers/test"
  5. "github.com/stretchr/testify/assert"
  6. "net/http"
  7. "testing"
  8. )
  9. const (
  10. USER_ID = 3
  11. PROFILE_ID = 1
  12. )
  13. // Subscriptions
  14. func TestSubscriptionsWithIncorrectInput(t *testing.T) {
  15. client := http.Client{}
  16. req := test_helper.MakeGetRequest("/v1/subscriptions", nil)
  17. res, err := client.Do(req)
  18. if err != nil {
  19. t.Error(err)
  20. }
  21. assert.Equal(t, http.StatusUnauthorized, res.StatusCode)
  22. }
  23. //func TestSubscriptions(t *testing.T) {
  24. // client := http.Client{}
  25. //
  26. // req := test_helper.MakeGetRequestWithUserId("/v1/subscriptions", nil, USER_ID)
  27. // res, err := client.Do(req)
  28. //
  29. // if err != nil {
  30. // t.Error(err)
  31. // }
  32. //
  33. // assert.Equal(t, http.StatusOK, res.StatusCode)
  34. //
  35. // response := test_helper.ReadResponse(res)
  36. //
  37. // assert.Contains(t, response, "data")
  38. //}
  39. //
  40. //// Subscribe
  41. //func subscribeWithPayload(t *testing.T, payload map[string]interface{}) {
  42. // client := http.Client{}
  43. // req := test_helper.MakePutRequestWithUserId("/v1/subscription", payload, USER_ID)
  44. // res, err := client.Do(req)
  45. //
  46. // if err != nil {
  47. // t.Error(err)
  48. // }
  49. //
  50. // assert.Equal(t, http.StatusOK, res.StatusCode)
  51. //
  52. // response := test_helper.ReadResponse(res)
  53. // assert.Empty(t, response)
  54. //}
  55. //
  56. //func TestSubscribePerUserWithValue(t *testing.T) {
  57. // numberOfSubs := howManySubscriptionsUserHas(USER_ID)
  58. //
  59. // payload := map[string]interface{}{
  60. // "source_id": findSourcePerUserWithValue(),
  61. // "profile_id": PROFILE_ID,
  62. // "value": helpers.RandomString(8),
  63. // }
  64. //
  65. // subscribeWithPayload(t, payload)
  66. //
  67. // assert.Equal(t, numberOfSubs+1, howManySubscriptionsUserHas(USER_ID))
  68. //
  69. // //addedSubscription := latestSubscriptionOfUser(USER_ID)
  70. // //assert.Equal(t, payload["source_id"].(int64), addedSubscription.GetSubscription().GetSource().Id)
  71. // //assert.Equal(t, int64(payload["profile_id"].(int)), addedSubscription.GetProfile().Id)
  72. // //assert.Equal(t, payload["value"].(string), addedSubscription.GetSubscription().Value.String)
  73. //}
  74. //
  75. //func TestSubscribePerUserWithoutValue(t *testing.T) {
  76. // numberOfSubs := howManySubscriptionsUserHas(USER_ID)
  77. //
  78. // payload := map[string]interface{}{
  79. // "source_id": findSourcePerUserWithoutValue(),
  80. // "profile_id": PROFILE_ID,
  81. // }
  82. //
  83. // subscribeWithPayload(t, payload)
  84. //
  85. // assert.Equal(t, numberOfSubs, howManySubscriptionsUserHas(USER_ID))
  86. //
  87. // //addedSubscription := latestSubscriptionOfUser(USER_ID)
  88. // //assert.Equal(t, payload["source_id"].(int64), addedSubscription.GetSubscription().GetSource().Id)
  89. // //assert.Equal(t, int64(payload["profile_id"].(int)), addedSubscription.GetProfile().Id)
  90. // //assert.True(t, addedSubscription.GetSubscription().Value.IsZero())
  91. //}
  92. //
  93. //func TestSubscribeWithValue(t *testing.T) {
  94. // numberOfSubs := howManySubscriptionsUserHas(USER_ID)
  95. //
  96. // payload := map[string]interface{}{
  97. // "source_id": findSourceWithValue(),
  98. // "value": helpers.RandomString(8),
  99. // }
  100. //
  101. // subscribeWithPayload(t, payload)
  102. //
  103. // assert.Equal(t, numberOfSubs+1, howManySubscriptionsUserHas(USER_ID))
  104. //
  105. // //addedSubscription := latestSubscriptionOfUser(USER_ID)
  106. // //assert.Equal(t, payload["source_id"].(int64), addedSubscription.GetSubscription().GetSource().Id)
  107. // //assert.True(t, addedSubscription.ProfileId.IsZero())
  108. // //assert.Equal(t, payload["value"].(string), addedSubscription.GetSubscription().Value.String)
  109. //}
  110. func TestSubscribeWithoutValue(t *testing.T) {
  111. //numberOfSubs := howManySubscriptionsUserHas(USER_ID)
  112. //
  113. //payload := map[string]interface{}{
  114. // "source_id": findSourceWithoutValue(),
  115. //}
  116. //
  117. //subscribeWithPayload(t, payload)
  118. //assert.Equal(t, numberOfSubs, howManySubscriptionsUserHas(USER_ID))
  119. //addedSubscription := latestSubscriptionOfUser(USER_ID)
  120. //assert.Equal(t, payload["source_id"].(int64), addedSubscription.GetSubscription().GetSource().Id)
  121. //assert.True(t, addedSubscription.ProfileId.IsZero())
  122. //assert.True(t, addedSubscription.GetSubscription().Value.IsZero())
  123. }
  124. //func TestUnsubscribe(t *testing.T) {
  125. // client := http.Client{}
  126. //
  127. // lastSubscription := latestSubscriptionOfUser(USER_ID)
  128. //
  129. // req := test_helper.MakeDeleteRequestWithUserId("/v1/subscription", map[string]interface{}{
  130. // "id": lastSubscription.Id,
  131. // }, USER_ID)
  132. // res, err := client.Do(req)
  133. //
  134. // if err != nil {
  135. // t.Error(err)
  136. // }
  137. //
  138. // assert.Equal(t, http.StatusOK, res.StatusCode)
  139. //
  140. // response := test_helper.ReadResponse(res)
  141. // assert.Empty(t, response)
  142. //
  143. // assert.Nil(t, model.LoadUserSubscription(lastSubscription.Id))
  144. //}
  145. //func TestCounters(t *testing.T) {
  146. //
  147. //}
  148. //
  149. //func TestGlueCounters(t *testing.T) {
  150. //
  151. //}