-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kyc/social: change primary key (#108)
- Loading branch information
1 parent
deb1407
commit 697d389
Showing
4 changed files
with
80 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# SPDX-License-Identifier: ice License 1.0 | ||
|
||
development: true | ||
logger: | ||
encoder: console | ||
level: debug | ||
|
||
users: &users | ||
wintr/connectors/storage/v2: | ||
runDDL: true | ||
primaryURL: postgresql://root:pass@localhost:5432/ice | ||
credentials: | ||
user: root | ||
password: pass | ||
replicaURLs: | ||
- postgresql://root:pass@localhost:5432/ice | ||
|
||
kyc/social: | ||
<<: *users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// SPDX-License-Identifier: ice License 1.0 | ||
|
||
package social | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ice-blockchain/eskimo/users" | ||
"github.com/ice-blockchain/wintr/connectors/storage/v2" | ||
"github.com/ice-blockchain/wintr/terror" | ||
) | ||
|
||
func helperRemoveSocials(t *testing.T, db storage.Execer, userID string) { | ||
t.Helper() | ||
|
||
_, err := storage.Exec(context.TODO(), db, "DELETE FROM socials where user_id = $1", userID) | ||
require.NoError(t, err) | ||
} | ||
|
||
func TestSocialSave(t *testing.T) { | ||
const userName = `icenetwork` | ||
|
||
ctx := context.Background() | ||
usersRepo := users.New(ctx, nil) | ||
require.NotNil(t, usersRepo) | ||
|
||
db := storage.MustConnect(ctx, ddl, applicationYamlKey) | ||
repo := &repository{db: db} | ||
|
||
helperRemoveSocials(t, db, userName) | ||
|
||
t.Run("OK", func(t *testing.T) { | ||
err := repo.saveSocial(ctx, TwitterType, userName, "foo") | ||
require.NoError(t, err) | ||
|
||
err = repo.saveSocial(ctx, TwitterType, userName, "bar") | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("Duplicate", func(t *testing.T) { | ||
err := repo.saveSocial(ctx, TwitterType, userName, "foo") | ||
require.ErrorIs(t, err, storage.ErrDuplicate) | ||
|
||
reason := detectReason(terror.New(err, map[string]any{"user_handle": "foo"})) | ||
require.Equal(t, `duplicate userhandle 'foo'`, reason) | ||
}) | ||
|
||
require.NoError(t, db.Close()) | ||
} |