@@ -62,3 +62,53 @@ func TestUserQueries(t *testing.T) {
6262 _ , err = q .GetUserByID (ctx , newUser .Uid )
6363 assert .Error (t , err )
6464}
65+
66+ var testUserParams = database.CreateUserParams {
67+ FirstName : "Test" ,
68+ LastName : "User" ,
69+ PersonalEmail : pgtype.Text {String : "testuser@gmail.com" , Valid : true },
70+ SchoolEmail : pgtype.Text {String : "testuser@rpi.edu" , Valid : true },
71+ Phone : pgtype.Text {String : "555-555-5555" , Valid : true },
72+ GradYear : pgtype.Int4 {Int32 : 2027 , Valid : true },
73+ Role : database.NullUserRole {UserRole : database .UserRoleStudent , Valid : true },
74+ }
75+
76+ func TestAddUser (t * testing.T ) {
77+ // Spin up container
78+ pool := testutils .SetupTestDB (t )
79+ defer pool .Close ()
80+
81+ q := database .New (pool )
82+ ctx := context .Background ()
83+
84+ q .CreateUser (ctx , testUserParams )
85+ user , err := q .GetUserByEmail (ctx , pgtype.Text {String : "testuser@gmail.com" , Valid : true })
86+ require .NoError (t , err )
87+ assert .Equal (t , user .FirstName , "Test" )
88+ assert .Equal (t , user .LastName , "User" )
89+ assert .Equal (t , user .Phone .String , "555-555-5555" )
90+ assert .Equal (t , user .GradYear .Int32 , int32 (2027 ))
91+ assert .Equal (t , user .Role .UserRole , database .UserRoleStudent )
92+ }
93+
94+ func TestAddDuplicateUser (t * testing.T ) {
95+ // Spin up container
96+ pool := testutils .SetupTestDB (t )
97+ defer pool .Close ()
98+ q := database .New (pool )
99+ ctx := context .Background ()
100+
101+ addedUser , err := q .CreateUser (ctx , testUserParams )
102+ require .NoError (t , err )
103+
104+ personalUser , err := q .GetUserByEmail (ctx , pgtype.Text {String : "testuser@gmail.com" , Valid : true })
105+ require .NoError (t , err )
106+
107+ assert .Equal (t , addedUser .Uid , personalUser .Uid )
108+
109+ _ , err = q .CreateUser (ctx , testUserParams )
110+ require .Error (t , err )
111+
112+ schoolUser , err := q .GetUserByEmail (ctx , pgtype.Text {String : "testuser@rpi.edu" , Valid : true })
113+ assert .Equal (t , addedUser .Uid , schoolUser .Uid )
114+ }
0 commit comments