<commit_before>package br.leosilvadev.gchat.controller

import org.springframework.http.HttpStatus

import spock.lang.Specification
import br.leosilvadev.gchat.exceptions.AuthenticationException
import br.leosilvadev.gchat.mail.dto.Authentication
import br.leosilvadev.gchat.mail.dto.Authentication.Authenticated;
import br.leosilvadev.gchat.model.services.UserService

class AuthenticationControllerSpec extends Specification {

	AuthenticationController controller
	UserService userService
	def onSuccess
	def onFailure
	
	def setup(){
		userService = Mock(UserService)
		
		controller = new AuthenticationController(userService: userService)
		onSuccess = controller.authenticateOnSuccess
		onFailure = controller.authenticateOnFailure
	}
	
	def "Should respond an OK response when the user authenticates correctly"(){
		def authenticated = new Authentication("Leonardo", "123456").authenticated()
		def response
		
		given: "A valid authentication"
			def authentication = new Authentication("Leonardo", "123456")
		
		when: "The user try to authenticate"
			response = controller.authenticate(authentication)
		
		then: "When the user is authenticated"
			1 * userService.authenticate("Leonardo", "123456", onSuccess, onFailure) >> { onSuccess(authenticated) }<commit_msg>authentication controller unit testing<commit_after>package br.leosilvadev.gchat.controller

import org.springframework.http.HttpStatus

import spock.lang.Specification
import br.leosilvadev.gchat.mail.dto.Authentication
import br.leosilvadev.gchat.mail.dto.Authentication.Authenticated
import br.leosilvadev.gchat.model.services.UserService

class AuthenticationControllerSpec extends Specification {

	AuthenticationController controller
	UserService userService
	def onSuccess
	def onFailure
	
	def setup(){
		userService = Mock(UserService)
		
		controller = new AuthenticationController(userService: userService)
		onSuccess = controller.authenticateOnSuccess
		onFailure = controller.authenticateOnFailure
	}
	
	def "Should respond an OK response when the user authenticates correctly"(){
		def authenticated = new Authentication("Leonardo", "123456").authenticated()
		def response
		
		given: "A valid authentication"
			def authentication = new Authentication("Leonardo", "123456")
		
		when: "The user try to authenticate"
			response = controller.authenticate(authentication)
		
		then: "When the user is authenticated"
			1 * userService.authenticate("Leonardo", "123456", onSuccess, onFailure) >> { onSuccess(authenticated) }
{'fraction_non_alphanumeric': 0.07912524850894632, 'fraction_numerical': 0.015109343936381709, 'mean_word_length': 5.8743169398907105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5137271', 'n_tokens_mistral': 795, 'n_tokens_neox': 680, 'n_words': 171}