PageRenderTime 128ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/api/api/endpoints/service_integration_test.go

https://gitlab.com/epicglue/api
Go | 111 lines | 49 code | 17 blank | 45 comment | 2 complexity | 7346673107c75c2aad20c0a527f53ae1 MD5 | raw file
  1. // +build integration
  2. package endpoints_test
  3. import (
  4. "bitbucket.org/epicglue/api/connection/database/postgres"
  5. "bitbucket.org/epicglue/api/helpers"
  6. "bitbucket.org/epicglue/api/model"
  7. "fmt"
  8. "github.com/stretchr/testify/assert"
  9. "net/http"
  10. "testing"
  11. )
  12. func getTestRequest() map[string]string {
  13. return map[string]string{
  14. "service": "twitter",
  15. "service_user_id": fmt.Sprintf("%d", helpers.RandomNumber(16)),
  16. "token": helpers.RandomString(32),
  17. "username": "John Doe",
  18. }
  19. }
  20. func lastConnectedServiceForUser(userId int64) *model.UserSubscription {
  21. query := `
  22. SELECT
  23. id
  24. FROM
  25. user_subscription
  26. WHERE
  27. user_id = $1
  28. ORDER BY
  29. created_at DESC
  30. `
  31. var lastSubId int64
  32. row := postgres.NewPostgres().DB().QueryRow(query, userId)
  33. row.Scan(&lastSubId)
  34. return model.LoadUserSubscription(lastSubId)
  35. }
  36. func TestConnectServiceUnauthorized(t *testing.T) {
  37. client := http.Client{}
  38. req := MakePutRequest("/v1/me/service", getTestRequest())
  39. res, err := client.Do(req)
  40. if err != nil {
  41. t.Error(err)
  42. }
  43. assert.Equal(t, http.StatusUnauthorized, res.StatusCode)
  44. }
  45. //func TestConnectServiceInvalidRequest(t *testing.T) {
  46. // client := http.Client{}
  47. //
  48. // req := MakePutRequestWithUserId("/v1/me/service", map[string]string{}, USER_ID)
  49. // res, err := client.Do(req)
  50. //
  51. // if err != nil {
  52. // t.Error(err)
  53. // }
  54. //
  55. // assert.Equal(t, http.StatusBadRequest, res.StatusCode)
  56. //}
  57. //
  58. //func TestConnectServiceEmptyToken(t *testing.T) {
  59. // testRequest := getTestRequest()
  60. // testRequest["token"] = ""
  61. //
  62. // client := http.Client{}
  63. //
  64. // req := MakePutRequestWithUserId("/v1/me/service", testRequest, USER_ID)
  65. // res, err := client.Do(req)
  66. //
  67. // if err != nil {
  68. // t.Error(err)
  69. // }
  70. //
  71. // assert.Equal(t, http.StatusBadRequest, res.StatusCode)
  72. //}
  73. //
  74. //func TestConnectServiceInvalidService(t *testing.T) {
  75. // testRequest := getTestRequest()
  76. // testRequest["token"] = ""
  77. //
  78. // client := http.Client{}
  79. //
  80. // req := MakePutRequestWithUserId("/v1/me/service", testRequest, USER_ID)
  81. // res, err := client.Do(req)
  82. //
  83. // if err != nil {
  84. // t.Error(err)
  85. // }
  86. //
  87. // assert.Equal(t, http.StatusBadRequest, res.StatusCode)
  88. //}
  89. func TestConnectServiceDuplicateToken(t *testing.T) {
  90. }
  91. func TestConnectService(t *testing.T) {
  92. }
  93. func TestDisconnectService(t *testing.T) {
  94. }