PageRenderTime 33ms CodeModel.GetById 26ms app.highlight 6ms RepoModel.GetById 1ms 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
 3package user_store_postgres_test
 4
 5import (
 6	"bitbucket.org/epicglue/api/helpers"
 7	"bitbucket.org/epicglue/api/helpers/test"
 8	"bitbucket.org/epicglue/api/model"
 9	"bitbucket.org/epicglue/api/user/store/db/postgres"
10	"fmt"
11	"github.com/stretchr/testify/assert"
12	"github.com/yezooz/null"
13	"testing"
14)
15
16func TestNewUserValidation(t *testing.T) {
17	userStore := user_store_postgres.NewUserStorePostgres()
18
19	assert.NotNil(t, userStore.CreateUser(nil))
20	assert.NotNil(t, userStore.CreateUser(&model.User{
21		Email: "random",
22	}))
23	assert.NotNil(t, userStore.CreateUser(&model.User{
24		Email:    helpers.RandomEmail(),
25		Password: null.StringFrom("short"),
26	}))
27}
28
29func TestNewUser(t *testing.T) {
30	userStore := user_store_postgres.NewUserStorePostgres()
31
32	newUser := &model.User{
33		Email:    helpers.RandomEmail(),
34		Password: null.StringFrom(helpers.RandomString(8)),
35	}
36
37	assert.Nil(t, userStore.CreateUser(newUser))
38
39	assert.NotNil(t, model.LoadUserByUsername(newUser.Email))
40
41	assert.True(t, test_helper.HasRecordsInTableWithCondition("auth_user", fmt.Sprintf(`email = '%s'`, newUser.Email)))
42	assert.True(t, test_helper.HasRecordsInTableWithCondition("user", fmt.Sprintf(`username = '%s'`, newUser.Email)))
43}