|
| 1 | +package tv.codely.ecommerce.login_attempt.infrastructure; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.BeforeEach; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import tv.codely.ecommerce.login_attempt.domain.EmailLoginAttempt; |
| 6 | +import tv.codely.ecommerce.login_attempt.domain.LoginAttempt; |
| 7 | +import tv.codely.ecommerce.login_attempt.domain.TwitterLoginAttempt; |
| 8 | + |
| 9 | +import java.util.HashMap; |
| 10 | + |
| 11 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 12 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 13 | + |
| 14 | +final class SdkAuth0LoginAttemptRepositoryShould { |
| 15 | + private SdkAuth0LoginAttemptRepository repository; |
| 16 | + |
| 17 | + @BeforeEach |
| 18 | + protected void setUp() { |
| 19 | + repository = new SdkAuth0LoginAttemptRepository(); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + void add_an_email_login_attempt() throws Exception { |
| 24 | + EmailLoginAttempt loginAttempt = new EmailLoginAttempt( "192.168.1.1", "[email protected]"); |
| 25 | + HashMap<String, String> expected = new HashMap<>() {{ |
| 26 | + put("ip", "192.168.1.1"); |
| 27 | + put( "email", "[email protected]"); |
| 28 | + }}; |
| 29 | + |
| 30 | + assertEquals(expected, repository.save(loginAttempt)); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + void add_a_twitter_login_attempt() throws Exception { |
| 35 | + TwitterLoginAttempt loginAttempt = new TwitterLoginAttempt("192.168.1.2", "codelytv"); |
| 36 | + HashMap<String, String> expected = new HashMap<>() {{ |
| 37 | + put("ip", "192.168.1.2"); |
| 38 | + put("username", "codelytv"); |
| 39 | + }}; |
| 40 | + |
| 41 | + assertEquals(expected, repository.save(loginAttempt)); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void throw_an_exception_with_an_unknown_login_attempt() { |
| 46 | + LoginAttempt loginAttempt = new LoginAttempt("192.168.1.3") { |
| 47 | + public String name() { |
| 48 | + return "unknown"; |
| 49 | + } |
| 50 | + }; |
| 51 | + |
| 52 | + assertThrows(Exception.class, () -> repository.save(loginAttempt)); |
| 53 | + } |
| 54 | +} |
0 commit comments