Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Aug 29, 2023
1 parent 97eca33 commit 5a01102
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/test/java/io/supertokens/test/AuthRecipeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,11 @@ public void randomPaginationTest() throws Exception {
return;
}

Map<String, Function<Object, ? extends AuthRecipeUserInfo>> signUpMap = getSignUpMap(process);
Map<String, Function<Object, AuthRecipeUserInfo>> signUpMap = getSignUpMap(process);

List<String> classes = getUserInfoClassNameList();
List<String> authRecipes = getAuthRecipes();

for (String className : classes) {
for (String className : authRecipes) {
if (!signUpMap.containsKey(className)) {
fail();
}
Expand All @@ -456,7 +456,7 @@ public void randomPaginationTest() throws Exception {
for (int i = 0; i < numberOfUsers; i++) {
if (Math.random() > 0.5) {
while (true) {
String currUserType = classes.get((int) (Math.random() * classes.size()));
String currUserType = authRecipes.get((int) (Math.random() * authRecipes.size()));
AuthRecipeUserInfo user = signUpMap.get(currUserType).apply(null);
if (user != null) {
synchronized (usersCreated) {
Expand All @@ -468,7 +468,7 @@ public void randomPaginationTest() throws Exception {
} else {
es.execute(() -> {
while (true) {
String currUserType = classes.get((int) (Math.random() * classes.size()));
String currUserType = authRecipes.get((int) (Math.random() * authRecipes.size()));
AuthRecipeUserInfo user = signUpMap.get(currUserType).apply(null);
if (user != null) {
synchronized (usersCreated) {
Expand Down Expand Up @@ -584,17 +584,17 @@ public void deleteUserTest() throws Exception {
return;
}

Map<String, Function<Object, ? extends AuthRecipeUserInfo>> signUpMap = getSignUpMap(process);
Map<String, Function<Object, AuthRecipeUserInfo>> signUpMap = getSignUpMap(process);

List<String> classes = getUserInfoClassNameList();
List<String> authRecipes = getAuthRecipes();

for (String className : classes) {
for (String className : authRecipes) {
if (!signUpMap.containsKey(className)) {
fail();
}
}

for (String userType : classes) {
for (String userType : authRecipes) {
AuthRecipeUserInfo user1 = signUpMap.get(userType).apply(null);
JsonObject testMetadata = new JsonObject();
testMetadata.addProperty("test", "test");
Expand Down Expand Up @@ -635,27 +635,24 @@ public void deleteUserTest() throws Exception {
assertNotNull(process.checkOrWaitForEvent(ProcessState.PROCESS_STATE.STOPPED));
}

private static List<String> getUserInfoClassNameList() {
Reflections reflections = new Reflections("io.supertokens");
Set<Class<? extends AuthRecipeUserInfo>> classes = reflections.getSubTypesOf(AuthRecipeUserInfo.class);

return classes.stream().map(Class::getCanonicalName).collect(Collectors.toList());
private static List<String> getAuthRecipes() {
return Arrays.asList("emailpassword", "thirdparty", "passwordless");
}

private static Map<String, Function<Object, ? extends AuthRecipeUserInfo>> getSignUpMap(
private static Map<String, Function<Object, AuthRecipeUserInfo>> getSignUpMap(
TestingProcessManager.TestingProcess process) {
AtomicInteger count = new AtomicInteger();

Map<String, Function<Object, ? extends AuthRecipeUserInfo>> signUpMap = new HashMap<>();
signUpMap.put("io.supertokens.pluginInterface.emailpassword.AuthRecipeUserInfo", o -> {
Map<String, Function<Object, AuthRecipeUserInfo>> signUpMap = new HashMap<>();
signUpMap.put("emailpassword", o -> {
try {
return EmailPassword.signUp(process.getProcess(), "test" + count.getAndIncrement() + "@example.com",
"password0");
} catch (Exception ignored) {
}
return null;
});
signUpMap.put("io.supertokens.pluginInterface.thirdparty.AuthRecipeUserInfo", o -> {
signUpMap.put("thirdparty", o -> {
try {
String thirdPartyId = "testThirdParty";
String thirdPartyUserId = "thirdPartyUserId" + count.getAndIncrement();
Expand All @@ -666,7 +663,7 @@ private static List<String> getUserInfoClassNameList() {
}
return null;
});
signUpMap.put("io.supertokens.pluginInterface.passwordless.AuthRecipeUserInfo", o -> {
signUpMap.put("passwordless", o -> {
try {
String email = "test" + count.getAndIncrement() + "@example.com";
CreateCodeResponse createCode = Passwordless.createCode(process.getProcess(), email, null, null, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void testActiveUserIsRemovedAfterLinkingAccounts() throws Exception {
{
JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand Down Expand Up @@ -173,6 +174,7 @@ public void testActiveUserIsRemovedAfterLinkingAccounts() throws Exception {
{
JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public void testThirdPartySignInUp() throws Exception {
{
JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand All @@ -255,6 +256,7 @@ public void testThirdPartySignInUp() throws Exception {
// Without account linking
JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand All @@ -279,6 +281,7 @@ public void testThirdPartySignInUp() throws Exception {
// After account linking
JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand All @@ -300,6 +303,7 @@ public void testThirdPartySignInUp() throws Exception {
// After account linking
JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand All @@ -317,6 +321,7 @@ public void testThirdPartySignInUp() throws Exception {
// After account linking
JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "facebook");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void testGoodInput() throws Exception {

JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand Down Expand Up @@ -142,6 +143,7 @@ public void testNotAllowedUpdateOfEmail() throws Exception {

JsonObject emailObject = new JsonObject();
emailObject.addProperty("id", "[email protected]");
emailObject.addProperty("isVerified", false);

JsonObject signUpRequestBody = new JsonObject();
signUpRequestBody.addProperty("thirdPartyId", "google");
Expand Down

0 comments on commit 5a01102

Please sign in to comment.