Skip to content

Commit

Permalink
Merge branch 'master' into issue66
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycpoon committed Nov 10, 2021
2 parents 0520fa2 + ee8c658 commit 73659b5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
4 changes: 2 additions & 2 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (d *DB) StoreUser(ctx context.Context, u User) error {
return nil
}

func (d *DB) DeleteUser(ctx context.Context, u User) error {
if _, err := d.Collection(usersPath).Doc(u.UID).Delete(ctx); err != nil {
func (d *DB) DeleteUser(ctx context.Context, uid string) error {
if _, err := d.Collection(usersPath).Doc(uid).Delete(ctx); err != nil {
return err
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions db/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func (d *MockDB) StoreUser(_ context.Context, u User) error {
return nil
}

func (d *MockDB) DeleteUser(_ context.Context, u User) error {
delete(d.db[usersPath], u.UID)
func (d *MockDB) DeleteUser(_ context.Context, uid string) error {
delete(d.db[usersPath], uid)
return nil
}

Expand Down
63 changes: 63 additions & 0 deletions db/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,67 @@ func TestMockUser(t *testing.T) {
_, err := d.LoadUser(context.Background(), "test")
assert.NoError(t, err)
})
t.Run("invalidLoad", func(t *testing.T) {
d := db.OpenMock()
require.NoError(t, d.StoreUser(context.Background(), db.User{
UID: "test",
}))
_, err := d.LoadUser(context.Background(), "invalid")
assert.Error(t, err)
})
t.Run("delete", func(t *testing.T) {
d := db.OpenMock()
require.NoError(t, d.StoreUser(context.Background(), db.User{
UID: "test",
}))
assert.NoError(t, d.DeleteUser(context.Background(), "test"))
})
}

func TestMockProgram(t *testing.T) {
t.Run("store", func(t *testing.T) {
d := db.OpenMock()
assert.NoError(t, d.StoreProgram(context.Background(), db.Program{}))
})
t.Run("load", func(t *testing.T) {
d := db.OpenMock()
require.NoError(t, d.StoreProgram(context.Background(), db.Program{
UID: "test",
}))
_, err := d.LoadProgram(context.Background(), "test")
assert.NoError(t, err)
})
t.Run("invalidLoad", func(t *testing.T) {
d := db.OpenMock()
require.NoError(t, d.StoreProgram(context.Background(), db.Program{
UID: "test",
}))
_, err := d.LoadProgram(context.Background(), "invalid")
assert.Error(t, err)
})
// Add tests if there is a DeleteProgram
}

func TestMockClass(t *testing.T) {
t.Run("store", func(t *testing.T) {
d := db.OpenMock()
assert.NoError(t, d.StoreClass(context.Background(), db.Class{}))
})
t.Run("load", func(t *testing.T) {
d := db.OpenMock()
require.NoError(t, d.StoreClass(context.Background(), db.Class{
CID: "test",
}))
_, err := d.LoadClass(context.Background(), "test")
assert.NoError(t, err)
})
t.Run("invalidLoad", func(t *testing.T) {
d := db.OpenMock()
require.NoError(t, d.StoreClass(context.Background(), db.Class{
CID: "test",
}))
_, err := d.LoadClass(context.Background(), "invalid")
assert.Error(t, err)
})
// Add tests if there is a DeleteClass
}
2 changes: 1 addition & 1 deletion db/tladb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ type TLADB interface {

LoadUser(context.Context, string) (User, error)
StoreUser(context.Context, User) error
DeleteUser(context.Context, User) error
DeleteUser(context.Context, string) error
}
2 changes: 1 addition & 1 deletion handler/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func DeleteUser(cc echo.Context) error {
}
}

if err := c.DeleteUser(c.Request().Context(), user); err != nil {
if err := c.DeleteUser(c.Request().Context(), uid); err != nil {
return c.String(http.StatusInternalServerError, "failed to delete user.")
}

Expand Down

0 comments on commit 73659b5

Please sign in to comment.