PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/user/store/db/postgres/create_user_integration_test.go

https://gitlab.com/epicglue/api
Go | 43 lines | 33 code | 9 blank | 1 comment | 0 complexity | 745ba273222b12348883fc84473447fc MD5 | raw file
  1. // +build integration
  2. package user_store_postgres_test
  3. import (
  4. "bitbucket.org/epicglue/api/helpers"
  5. "bitbucket.org/epicglue/api/helpers/test"
  6. "bitbucket.org/epicglue/api/model"
  7. "bitbucket.org/epicglue/api/user/store/db/postgres"
  8. "fmt"
  9. "github.com/stretchr/testify/assert"
  10. "github.com/yezooz/null"
  11. "testing"
  12. )
  13. func TestNewUserValidation(t *testing.T) {
  14. userStore := user_store_postgres.NewUserStorePostgres()
  15. assert.NotNil(t, userStore.CreateUser(nil))
  16. assert.NotNil(t, userStore.CreateUser(&model.User{
  17. Email: "random",
  18. }))
  19. assert.NotNil(t, userStore.CreateUser(&model.User{
  20. Email: helpers.RandomEmail(),
  21. Password: null.StringFrom("short"),
  22. }))
  23. }
  24. func TestNewUser(t *testing.T) {
  25. userStore := user_store_postgres.NewUserStorePostgres()
  26. newUser := &model.User{
  27. Email: helpers.RandomEmail(),
  28. Password: null.StringFrom(helpers.RandomString(8)),
  29. }
  30. assert.Nil(t, userStore.CreateUser(newUser))
  31. assert.NotNil(t, model.LoadUserByUsername(newUser.Email))
  32. assert.True(t, test_helper.HasRecordsInTableWithCondition("auth_user", fmt.Sprintf(`email = '%s'`, newUser.Email)))
  33. assert.True(t, test_helper.HasRecordsInTableWithCondition("user", fmt.Sprintf(`username = '%s'`, newUser.Email)))
  34. }