Skip to content

Commit

Permalink
fix verify email proc
Browse files Browse the repository at this point in the history
  • Loading branch information
aradwann committed Mar 11, 2024
1 parent f9262b4 commit 84cf1b2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 3 deletions.
4 changes: 1 addition & 3 deletions db/migrations/procs/user/update_verify_email.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ RETURNS TABLE (
secret_code VARCHAR,
is_used BOOLEAN,
created_at TIMESTAMP WITH TIME ZONE,
expires_at_at TIMESTAMP WITH TIME ZONE,
role VARCHAR
expired_at TIMESTAMP WITH TIME ZONE
) AS $$
BEGIN
RETURN QUERY
Expand All @@ -30,6 +29,5 @@ BEGIN
verify_emails.is_used,
verify_emails.created_at,
verify_emails.expired_at;

END;
$$ LANGUAGE plpgsql;
49 changes: 49 additions & 0 deletions db/store/tx_create_user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package db

import (
"context"
"testing"

"github.com/aradwann/eenergy/util"
"github.com/stretchr/testify/require"
)

func TestCreateUserTx(t *testing.T) {

n := 5

errs := make(chan error)
results := make(chan CreateUserTxResult)

// run n concurrent transfer transaction
for i := 0; i < n; i++ {
go func() {
result, err := testStore.CreateUserTx(context.Background(), CreateUserTxParams{
CreateUserParams: CreateUserParams{
Username: util.RandomOwner(),
HashedPassword: util.RandomString(12),
FullName: util.RandomString(8),
Email: util.RandomEmail(),
},

AfterCreate: func(user User) error {

return nil
},
})

errs <- err
results <- result
}()
}

for i := 0; i < n; i++ {
err := <-errs
require.NoError(t, err)

result := <-results
require.NotEmpty(t, result)

}

}
42 changes: 42 additions & 0 deletions db/store/tx_verify_email_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package db

import (
"context"
"testing"

"github.com/aradwann/eenergy/util"
)

func TestVerifyEmailTx(t *testing.T) {

n := 5

errs := make(chan error)
results := make(chan VerifyEmailTxResult)

// run n concurrent transfer transaction
for i := 0; i < n; i++ {
go func() {

result, err := testStore.VerifyEmailTx(context.Background(), VerifyEmailTxParams{
EmailId: util.RandomInt(1, 29),
SecretCode: util.RandomString(16),
})

errs <- err
results <- result
}()
}

for i := 0; i < n; i++ {
// TODO: mock and verify

// err := <-errs
// require.NoError(t, err)

// result := <-results
// require.NotEmpty(t, result)

}

}

0 comments on commit 84cf1b2

Please sign in to comment.