<commit_before>package ee.tuleva.onboarding.notification.payment

import ee.tuleva.onboarding.BaseControllerSpec
import ee.tuleva.onboarding.notification.email.EmailService
import ee.tuleva.onboarding.user.UserService
import org.springframework.http.MediaType
import org.springframework.validation.SmartValidator

import static ee.tuleva.onboarding.auth.UserFixture.sampleUser
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

class PaymentControllerSpec extends BaseControllerSpec {

  def userService = Mock(UserService)
  def validator = Mock(SmartValidator)
  def emailService = Mock(EmailService)
  def controller = new PaymentController(mapper, userService, validator, emailService)

  def mvc = mockMvc(controller)

  String membershipSuccessUrl = 'a_URL';

  def setup() {
    controller.membershipSuccessUrl = membershipSuccessUrl
  }

  def "incoming payment is correctly mapped to DTO, mac is validated and a member is created in the database with the correct name"() {
    given:
    def json = [
      "amount": "100.0",
      "currency": "EUR",
      "customer_name": "T\u00f5\u00f5ger Le\u00f5p\u00e4\u00f6ld",
      "merchant_data": null,
      "message_time": "2017-04-25T12:42:37+0000",
      "message_type": "payment_return",
      "reference": "1",
      "shop": "322a5e5e-37ee-45b1-8961-ebd00e84e209",
      "signature": "EDB6E91FD890EF86EBD6A820BBAE1E99068596776667E35F823C4CE57F79D948F68F76EAEA2E8417F0E4442BCD758EEB747102CCCE70122D3C05F50C7A596339",
      "status": "COMPLETED",
      "transaction": "235e8a24-c510-4c8d-9fa8-2a322ba80bb2"
    ]
    def sampleUser = sampleUser().build()
    
    when:
    def perform = mvc.perform(post("/notifications/payments")
            .contentType(MediaType.APPLICATION_JSON)
            .param("json", mapper.writeValueAsString(json))
            .param("mac", "e9b1867c40e2a2ac3fd654ab4f26dedcbe320c48c0aec5058c8a442fc941429c8bcafa22c52240a1a645fb0abf6a05692f7b79b6cb83a41637aef0756cdb3dda"))

    then:
    perform
        .andExpect(status().isFound())
        .andExpect(redirectedUrl(membershipSuccessUrl))<commit_msg>Update amounts in tests<commit_after>package ee.tuleva.onboarding.notification.payment

import ee.tuleva.onboarding.BaseControllerSpec
import ee.tuleva.onboarding.notification.email.EmailService
import ee.tuleva.onboarding.user.UserService
import org.springframework.http.MediaType
import org.springframework.validation.SmartValidator

import static ee.tuleva.onboarding.auth.UserFixture.sampleUser
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status

class PaymentControllerSpec extends BaseControllerSpec {

  def userService = Mock(UserService)
  def validator = Mock(SmartValidator)
  def emailService = Mock(EmailService)
  def controller = new PaymentController(mapper, userService, validator, emailService)

  def mvc = mockMvc(controller)

  String membershipSuccessUrl = 'a_URL';

  def setup() {
    controller.membershipSuccessUrl = membershipSuccessUrl
  }

  def "incoming payment is correctly mapped to DTO, mac is validated and a member is created in the database with the correct name"() {
    given:
    def json = [
      "amount": "125.0",
      "currency": "EUR",
      "customer_name": "T\u00f5\u00f5<NAME>\u00f5p\u00e4\u00f6ld",
      "merchant_data": null,
      "message_time": "2017-04-25T12:42:37+0000",
      "message_type": "payment_return",
      "reference": "1",
      "shop": "322a5e5e-37ee-45b1-8961-ebd00e84e209",
      "signature": "EDB6E91FD890EF86EBD6A820BBAE1E99068596776667E35F823C4CE57F79D948F68F76EAEA2E8417F0E4442BCD758EEB747102CCCE70122D3C05F50C7A596339",
      "status": "COMPLETED",
      "transaction": "235e8a24-c510-4c8d-9fa8-2a322ba80bb2"
    ]
    def sampleUser = sampleUser().build()
    
    when:
    def perform = mvc.perform(post("/notifications/payments")
            .contentType(MediaType.APPLICATION_JSON)
            .param("json", mapper.writeValueAsString(json))
            .param("mac", "c9bd73b2eaac5f73b15c24f4a0d06ec5d3bb14bbbc3ce2e3c709d1587f44e574a690a632190b3b8cb831da82d0a706daed7d011878cabaedf54236c3c45f6fbf"))

    then:
    perform
        .andExpect(status().isFound())
        .andExpect(redirectedUrl(membershipSuccessUrl))
{'fraction_non_alphanumeric': 0.09727626459143969, 'fraction_numerical': 0.09922178988326848, 'mean_word_length': 4.8055207026348805, 'pattern_counts': {'":': 22, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4048971', 'n_tokens_mistral': 1832, 'n_tokens_neox': 1600, 'n_words': 239}