Commit 21b1151b authored by Ben Anderson's avatar Ben Anderson

Added unit test for cc/authorize route that tests for successful authorization

parent 7d7f9d1f
......@@ -27,6 +27,7 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok'
implementation "io.springfox:springfox-boot-starter:3.0.0"
compileOnly "io.springfox:springfox-swagger-ui:3.0.0"
testImplementation 'org.mockito:mockito-core:3.12.4'
}
test {
......
package com.nisum.paymentvendorsimulator.creditcard.controllers;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
@AutoConfigureMockMvc
class CreditCardControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
void authorize() throws Exception {
mockMvc.perform(post("/api/cc/authorize")
.contentType(MediaType.APPLICATION_JSON)
.content("{ \"card\": { \"number\": \"4111111111111111\", \"expiryMonth\": \"03\", \"expiryYear\": \"2030\", \"cvc\": \"737\", \"holderName\": \"John Smith\" }, \"amount\": { \"value\": 1500, \"currency\": \"EUR\" }, \"reference\": \"YOUR_REFERENCE\", \"merchantAccount\": \"YOUR_MERCHANT_ACCOUNT\" }")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().is2xxSuccessful())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.cardNumber").value("4111111111111111"))
.andExpect(jsonPath("$.cvv").value("737"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment