-
Notifications
You must be signed in to change notification settings - Fork 332
[WPB-8881] Add unit tests for new effect actions #4331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
581eb08
4ff3734
d46de01
1f09351
1bf84d2
d153bbf
e590bdd
184c598
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| Move email update and remove operations to effects | ||
| Move email update and remove operations to effects (#4316, ##) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| module Wire.ActivationCodeStore.InterpreterSpec (spec) where | ||
|
|
||
| import Data.Default | ||
| import Data.Map qualified as Map | ||
| import Imports | ||
| import Test.Hspec | ||
| import Test.Hspec.QuickCheck | ||
| import Test.QuickCheck | ||
| import Wire.API.User.Activation | ||
| import Wire.ActivationCodeStore | ||
| import Wire.MiniBackend | ||
| import Wire.MockInterpreters.ActivationCodeStore | ||
|
|
||
| spec :: Spec | ||
| spec = do | ||
| describe "ActivationCodeStore effect" $ do | ||
| prop "a code can be looked up" $ \emailKey config -> | ||
| let c = code emailKey | ||
| localBackend = | ||
| def {activationCodes = Map.singleton emailKey (Nothing, c)} | ||
| result = | ||
| runNoFederationStack localBackend Nothing config $ | ||
| lookupActivationCode emailKey | ||
| in result === Just (Nothing, c) | ||
| prop "a code not found in the store" $ \emailKey config -> | ||
| let localBackend = def | ||
| result = | ||
| runNoFederationStack localBackend Nothing config $ | ||
| lookupActivationCode emailKey | ||
| in result === Nothing | ||
| prop "newly added code can be looked up" $ \emailKey mUid config -> | ||
| let c = code emailKey | ||
| localBackend = def | ||
| (actCode, lookupRes) = | ||
| runNoFederationStack localBackend Nothing config $ do | ||
| ac <- | ||
| (.activationCode) | ||
| <$> newActivationCode emailKey undefined mUid | ||
| (ac,) <$> lookupActivationCode emailKey | ||
| in actCode === c .&&. lookupRes === Just (mUid, c) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| module Wire.UserStoreSpec (spec) where | ||
|
|
||
| import Data.Default | ||
| import Imports | ||
| import Polysemy.State | ||
| import Test.Hspec | ||
| import Test.Hspec.QuickCheck | ||
| import Test.QuickCheck | ||
| import Wire.API.User | ||
| import Wire.MiniBackend | ||
| import Wire.StoredUser | ||
| import Wire.UserStore | ||
|
|
||
| spec :: Spec | ||
| spec = do | ||
|
|
@@ -33,3 +37,21 @@ spec = do | |
| in if (isJust storedUser.language) | ||
| then user.userLocale === Locale (fromJust storedUser.language) storedUser.country | ||
| else user.userLocale === defaultLocale | ||
|
|
||
| describe "UserStore effect" $ do | ||
|
||
| prop "user self email deleted" $ \user1 user2' email2 config -> | ||
| let user2 = user2' {email = Just email2} | ||
| localBackend = def {users = [user1, user2]} | ||
| result = | ||
| runNoFederationStack localBackend Nothing config $ do | ||
| deleteEmail (user1.id) | ||
| gets users | ||
| in result === [user1 {email = Nothing}, user2] | ||
| prop "update unvalidated email" $ \user1 user2 email1 config -> | ||
| let updatedUser1 = user1 {emailUnvalidated = Just email1} | ||
| localBackend = def {users = [user1, user2]} | ||
| result = | ||
| runNoFederationStack localBackend Nothing config $ do | ||
| updateEmailUnvalidated (user1.id) email1 | ||
| gets users | ||
| in result === [updatedUser1, user2] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered to add a test where the lookup fails? E.g. there is a code, but the key does not match?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added it! I've rebased and pushed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks! (The more test code coverage we can add, the better - as long as the task doesn't grow out of bounds, of course 😄 )