<commit_before>package br.leosilvadev.gchat.notifiers

import org.springframework.messaging.simp.SimpMessagingTemplate

import spock.lang.Specification
import br.leosilvadev.gchat.builder.MessageBuilder
import br.leosilvadev.gchat.model.domain.User
import br.leosilvadev.gchat.model.dto.ChatUser
import br.leosilvadev.gchat.utils.ChatConstants

class UserLoginNotifierSpec extends Specification {

	UserLoginNotifier notifier
	
	def builder
	def template
	
	def setup(){
		builder  = Mock(MessageBuilder)
		template = Mock(SimpMessagingTemplate)
		notifier = new UserLoginNotifier(builder: builder, template: template)
	}
	
	def "Should notify a User Login"(){
		def chatUser = new ChatUser(name: "Fake", email: "<EMAIL>")
		
		given: "A room code and a user"
			def roomCode = "1234"
			def user 	 = new User(name:"Fake", email:"<EMAIL>")
			
		when: ""
			notifier.to(roomCode).by(user).send()
			
		then: ""
			1 * builder.newUser('Let\'s welcome <b>Fake</b>', chatUser, ChatConstants.NEW_USER)
			
	}
	
}<commit_msg>User Login notifier specification fixed<commit_after>package br.leosilvadev.gchat.notifiers

import org.springframework.messaging.simp.SimpMessagingTemplate

import spock.lang.Specification
import br.leosilvadev.gchat.builder.MessageBuilder
import br.leosilvadev.gchat.model.domain.User
import br.leosilvadev.gchat.model.dto.ChatUser
import br.leosilvadev.gchat.utils.ChatConstants

class UserLoginNotifierSpec extends Specification {

	UserLoginNotifier notifier
	
	def builder
	def template
	
	def setup(){
		builder  = Mock(MessageBuilder)
		template = Mock(SimpMessagingTemplate)
		notifier = new UserLoginNotifier(builder: builder, template: template)
	}
	
	def "Should notify a User Login"(){
		def chatUser = new ChatUser(name: "Fake", email: "<EMAIL>")
		def newUserMessage
		
		given: "A room code and a user"
			def roomCode = "1234"
			def user 	 = new User(name:"Fake", email:"<EMAIL>")
			
		when: "The the notifier receives a room code, a user and send"
			notifier.to(roomCode).by(user).send()
			
		then: "A 'welcome' message must be sent to users in the room"
			1 * builder.newUser('Let\'s welcome <b>Fake</b>', chatUser, ChatConstants.SYSTEM_MESSAGE) >> newUserMessage
			1 * template.convertAndSend("/topic/rooms-1234", newUserMessage)
	}
	
}
{'fraction_non_alphanumeric': 0.10736196319018405, 'fraction_numerical': 0.006573181419807186, 'mean_word_length': 4.67910447761194, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '378234', 'n_tokens_mistral': 836, 'n_tokens_neox': 750, 'n_words': 178}