|
8 | 8 | package com.salesforce.revoman.internal.postman |
9 | 9 |
|
10 | 10 | import io.github.serpro69.kfaker.faker |
| 11 | +import kotlinx.datetime.Clock |
| 12 | +import org.apache.commons.lang3.RandomStringUtils |
11 | 13 | import java.time.LocalDate |
12 | 14 | import java.util.* |
| 15 | +import kotlin.random.Random.Default.nextBoolean |
13 | 16 | import kotlin.random.Random.Default.nextInt |
14 | 17 | import kotlin.random.Random.Default.nextLong |
15 | 18 |
|
16 | 19 | private val faker = faker {} |
17 | 20 |
|
| 21 | +/** |
| 22 | + * https://learning.postman.com/docs/writing-scripts/script-references/variables-list/ |
| 23 | + */ |
18 | 24 | private val dynamicVariableGenerators: Map<String, () -> String> = |
19 | 25 | mapOf( |
| 26 | + // Common |
| 27 | + "\$guid" to { UUID.randomUUID().toString() }, |
| 28 | + "\$timestamp" to { Clock.System.now().epochSeconds.toString() }, |
| 29 | + "\$isoTimestamp" to { Clock.System.now().toString() }, |
| 30 | + "\$randomUUID" to { UUID.randomUUID().toString() }, |
| 31 | + // Text, numbers, and colors |
| 32 | + "\$randomAlphaNumeric" to { RandomStringUtils.randomAlphanumeric(1) }, |
| 33 | + "\$randomBoolean" to { nextBoolean().toString() }, |
| 34 | + "\$randomInt" to { nextInt(0, Int.MAX_VALUE).toString() }, |
| 35 | + "\$randomColor" to faker.color::name, |
| 36 | + // Names |
20 | 37 | "\$randomFirstName" to faker.name::firstName, |
21 | 38 | "\$randomLastName" to faker.name::lastName, |
22 | 39 | "\$randomUserName" to { faker.name.firstName() + faker.name.lastName() }, |
| 40 | + // Phone, address, and location |
23 | 41 | "\$randomCity" to faker.address::city, |
| 42 | + // Grammar |
24 | 43 | "\$randomWord" to faker.lorem::words, |
25 | 44 | "\$randomCompanyName" to faker.company::name, |
26 | | - "\$randomColor" to faker.color::name, |
27 | 45 | "\$randomWord" to faker.lorem::words, |
28 | | - "\$randomInt" to { nextInt(0, Int.MAX_VALUE).toString() }, |
29 | 46 | "\$randomAdjective" to faker.adjective::positive, |
30 | | - "\$guid" to { UUID.randomUUID().toString() }, |
31 | | - "\$randomUUID" to { UUID.randomUUID().toString() }, |
32 | 47 | "\$randomEmail" to { faker.internet.email() }, |
33 | 48 | "\$currentDate" to { LocalDate.now().toString() }, |
34 | 49 | "\$randomFutureDate" to |
35 | 50 | { |
36 | 51 | LocalDate.now().let { it.plusDays(nextLong(1, it.lengthOfYear().toLong())).toString() } |
37 | 52 | }, |
38 | | - "\$timestamp" to { System.currentTimeMillis().toString() }, |
39 | 53 | ) |
40 | 54 |
|
41 | 55 | private val dynamicVariableGeneratorsWithPM: Map<String, (PostmanSDK) -> String> = |
|
0 commit comments