Skip to content

Commit

Permalink
Add phone tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asloobq committed Jun 3, 2024
1 parent 7989701 commit 1b209bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/test/java/suite/optout/OptoutTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void testV2LogoutWithV2TokenGenerateOldParticipant(String label, Operator

@ParameterizedTest(name = "/v2/token/logout with /v2/identity/map - {0} - {2}")
@MethodSource({
"suite.optout.TestData#identityMapEmailArgs"
"suite.optout.TestData#identityMapEmailArgs",
"suite.optout.TestData#identityMapPhoneArgs"
})
@Order(5)
public void testV2LogoutWithV2IdentityMap(String label, Operator operator, String operatorName, String type, String emailOrPhone, boolean toOptOut) throws Exception {
Expand Down
38 changes: 29 additions & 9 deletions src/test/java/suite/optout/TestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,7 @@ public static Set<Arguments> tokenPhoneArgs() {

public static Set<Arguments> optoutTokenPhoneArgs() {
Set<Operator> operators = getPublicOperators();
Random random = new Random();
StringBuilder phone = new StringBuilder(String.valueOf(random.nextLong((10000000000L - 1000000000L) +1) + 1000000000L));
while (phone.length() < 10) {
phone.insert(0, "0");
}
phone.insert(0, "+0");
Set<List<String>> inputs = Set.of(
List.of("good phone", "phone", phone.toString())
);
Set<List<String>> inputs = generatePhoneSet(1);

Set<Arguments> args = new HashSet<>();
if (PHONE_SUPPORT) {
Expand All @@ -101,6 +93,19 @@ public static Set<Arguments> identityMapEmailArgs() {
return args;
}

public static Set<Arguments> identityMapPhoneArgs() {
Set<Operator> operators = getPublicOperators();
Set<List<String>> inputs = generatePhoneSet(4);

Set<Arguments> args = new HashSet<>();
for (Operator operator : operators) {
for (List<String> input : inputs) {
args.add(Arguments.of(input.get(0), operator, operator.getName(), input.get(1), input.get(2), Boolean.parseBoolean(input.get(3))));
}
}
return args;
}

private static Set<List<String>> generateEmailSet(int count) {
Random random = new Random();
Set<List<String>> inputs = new HashSet<>(count);
Expand All @@ -113,6 +118,21 @@ private static Set<List<String>> generateEmailSet(int count) {
return inputs;
}

private static Set<List<String>> generatePhoneSet(int count) {
Random random = new Random();
Set<List<String>> inputs = new HashSet<>();
final long bound = (10000000000L - 1000000000L) + 1;
for (int i = 0; i < count; ++i) {
StringBuilder phone = new StringBuilder(String.valueOf(random.nextLong(bound) + 1000000000L));
while (phone.length() < 10) {
phone.insert(0, "0");
}
phone.insert(0, "+0");
inputs.add(List.of("good phone " + (i + 1), "phone", phone.toString(), i % 2 == 0 ? "true" : "false"));
}
return inputs;
}

private static String getRandomString(int minLength, int maxLength) {
String alphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
StringBuilder s = new StringBuilder();
Expand Down

0 comments on commit 1b209bc

Please sign in to comment.