aboutsummaryrefslogtreecommitdiff
path: root/internal/db/orgs_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/db/orgs_test.go')
-rw-r--r--internal/db/orgs_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/db/orgs_test.go b/internal/db/orgs_test.go
index 9989394d..89550d81 100644
--- a/internal/db/orgs_test.go
+++ b/internal/db/orgs_test.go
@@ -32,6 +32,7 @@ func TestOrgs(t *testing.T) {
}{
{"List", orgsList},
{"SearchByName", orgsSearchByName},
+ {"CountByUser", orgsCountByUser},
} {
t.Run(tc.name, func(t *testing.T) {
t.Cleanup(func() {
@@ -164,3 +165,21 @@ func orgsSearchByName(t *testing.T, db *orgs) {
assert.Equal(t, org2.ID, orgs[0].ID)
})
}
+
+func orgsCountByUser(t *testing.T, db *orgs) {
+ ctx := context.Background()
+
+ // TODO: Use Orgs.Join to replace SQL hack when the method is available.
+ err := db.Exec(`INSERT INTO org_user (uid, org_id) VALUES (?, ?)`, 1, 1).Error
+ require.NoError(t, err)
+ err = db.Exec(`INSERT INTO org_user (uid, org_id) VALUES (?, ?)`, 2, 1).Error
+ require.NoError(t, err)
+
+ got, err := db.CountByUser(ctx, 1)
+ require.NoError(t, err)
+ assert.Equal(t, int64(1), got)
+
+ got, err = db.CountByUser(ctx, 404)
+ require.NoError(t, err)
+ assert.Equal(t, int64(0), got)
+}