Vishal Kukreja
07/29/2022, 12:53 PM@HiltAndroidTest
@Config(sdk = [Build.VERSION_CODES.Q])
@PactTestFor(
providerName = "our_provider"
)
@PactFolder("target/pacts")
@ExtendWith(
PactConsumerTestExt::class)
class VerificationEstimationPactTest {
private var HEADERS: MutableMap<String, String> = HashMap()
private var JSON: String? = null
@get:Rule
var rule: TestRule = InstantTaskExecutorRule()
@get:Rule
var hiltRule = HiltAndroidRule(this)
@Inject
lateinit var viewModel: MutualFundVerificationViewModel
init
{
HEADERS["Content-Type"] = "application/json"
JSON="{\n" +
" \"estimationDate\": \"2022-07-26T10:59:29.935Z\",\n"+
" \"oEstimationDate\": \"2022-07-27T10:59:56.342Z\",\n"+
" \"estimationDate\": \"2022-07-27T11:12:26.640Z\",\n"+
" \"gstimationDate\": \null \n"+
" }"
}
@Before
fun setUp() {
hiltRule.inject()
}
@Throws(
UnsupportedEncodingException::class
)
@Pact(provider = "our_provider", consumer = "our_consumer")
fun createFragment(builder: PactDslWithProvider): RequestResponsePact {
return builder
.given("data count is > 0")
.uponReceiving("a request for json data")
.path("/provider.json")
.method("GET")
.willRespondWith()
.status(200)
.headers(HEADERS)
.body(JSON)
.toPact()
}
@Test
@PactTestFor(pactMethod = "createFragment")
fun should_process_the_json_payload_from_provider() {
// val observer: TestObserver<VerificationTimeResponse> = viewModel.flowUseCase.getVerificationTime().test()
// observer.assertNoErrors()
/*observer.assertValue(
VerificationTimeResponse(
Timestamp("2022-07-26T10:59:29.935Z".toLong()),
Timestamp("2022-07-27T10:59:56.342Z".toLong()),
Timestamp("2022-07-27T11:12:26.640Z".toLong()),
null
)
)*/
}
still unable to generate the contract file.
Kindly help for same.Matt (pactflow.io / pact-js / pact-go)
Boris
08/01/2022, 1:13 AM