PageRenderTime 36ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/api/api/endpoints/user_integration_test.go

https://gitlab.com/epicglue/api
Go | 124 lines | 74 code | 29 blank | 21 comment | 10 complexity | 4abff52d70b886d8f6c6c96c6b9cc1a7 MD5 | raw file
  1. // +build integration
  2. package endpoints_test
  3. import (
  4. "bitbucket.org/epicglue/api/helpers"
  5. "bitbucket.org/epicglue/api/helpers/test"
  6. "github.com/stretchr/testify/assert"
  7. "net/http"
  8. "testing"
  9. )
  10. //func TestMe(t *testing.T) {
  11. // client := http.Client{}
  12. //
  13. // req := test_helper.MakeGetRequestWithUserId("/v1/me", nil, USER_ID)
  14. // res, err := client.Do(req)
  15. //
  16. // if err != nil {
  17. // t.Error(err)
  18. // }
  19. //
  20. // assert.Equal(t, http.StatusOK, res.StatusCode)
  21. //
  22. // response := test_helper.ReadResponse(res)
  23. //
  24. // assert.Contains(t, response, "data")
  25. // fmt.Println(response)
  26. // //assert.Contains(t, response["data"], "username")
  27. // //assert.Contains(t, response["data"], "email")
  28. // //assert.Contains(t, response["data"], "plan")
  29. //}
  30. func TestLoginByWrongEmail(t *testing.T) {
  31. client := http.Client{}
  32. req := test_helper.MakePostRequest("/v1/login", map[string]string{
  33. "email": helpers.RandomEmail(),
  34. "password": "dupadupa",
  35. })
  36. res, err := client.Do(req)
  37. if err != nil {
  38. t.Error(err)
  39. }
  40. assert.Equal(t, http.StatusBadRequest, res.StatusCode)
  41. }
  42. func TestLoginByEmail(t *testing.T) {
  43. client := http.Client{}
  44. req := test_helper.MakePostRequest("/v1/login", map[string]string{
  45. "email": "marek.mikuliszyn@gmail.com",
  46. "password": "dupadupa",
  47. })
  48. res, err := client.Do(req)
  49. if err != nil {
  50. t.Error(err)
  51. }
  52. assert.Equal(t, http.StatusOK, res.StatusCode)
  53. response := test_helper.ReadResponse(res)
  54. assert.Contains(t, response, "token")
  55. }
  56. func TestRegisterByExistingEmail(t *testing.T) {
  57. client := http.Client{}
  58. req := test_helper.MakePostRequest("/v1/register/email", map[string]string{
  59. "email": "marek.mikuliszyn@gmail.com",
  60. "password": "dupadupa",
  61. })
  62. res, err := client.Do(req)
  63. if err != nil {
  64. t.Error(err)
  65. }
  66. assert.Equal(t, http.StatusBadRequest, res.StatusCode)
  67. }
  68. func TestRegisterByWrongEmail(t *testing.T) {
  69. client := http.Client{}
  70. req := test_helper.MakePostRequest("/v1/register/email", map[string]string{
  71. "email": helpers.RandomString(8),
  72. "password": helpers.RandomString(8),
  73. })
  74. res, err := client.Do(req)
  75. if err != nil {
  76. t.Error(err)
  77. }
  78. assert.Equal(t, http.StatusBadRequest, res.StatusCode)
  79. }
  80. func TestRegisterByEmail(t *testing.T) {
  81. client := http.Client{}
  82. req := test_helper.MakePostRequest("/v1/register/email", map[string]string{
  83. "email": helpers.RandomEmail(),
  84. "password": helpers.RandomString(8),
  85. })
  86. res, err := client.Do(req)
  87. if err != nil {
  88. t.Error(err)
  89. }
  90. assert.Equal(t, http.StatusOK, res.StatusCode)
  91. response := test_helper.ReadResponse(res)
  92. assert.Contains(t, response, "token")
  93. }
  94. func TestRegisterByService(t *testing.T) {
  95. }