<commit_before>package mama.ng.scheduler

import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import grails.test.mixin.TestMixin
import grails.test.mixin.domain.DomainClassUnitTestMixin
import groovy.time.TimeCategory
import org.codehaus.groovy.runtime.typehandling.GroovyCastException
import spock.lang.Specification

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestMixin(DomainClassUnitTestMixin)
@TestFor(Message)
@Mock([Schedule, Message])
class MessageSpec extends Specification {

    Message message
    Schedule schedule

    def setup() {
        use (TimeCategory) {
            mockForConstraintsTests(Message)
            schedule = new Schedule(
                userId: "user-id",
                frequency: 5,
                cronDefinition: "0 9 * * 3",
                nextSend: new Date() + 2.days,
                endpoint: "http://test.endpoint.com"
            ).save(failOnError: true)
            message = new Message(
                schedule: schedule,
                nextSend: new Date() + 2.days
            )
        }
    }

    def cleanup() {
        message.delete()
        schedule.delete()
    }

    void "test null schedule"() {
        given:
            message.schedule = null
            message.save()
        expect:
            message.hasErrors()
            message.errors["schedule"]("nullable")
    }

    void "test incorrect type schedule"() {
        when:
            message.schedule = "schedule-id"
            message.save()
        then:<commit_msg>Fixed silly mistake in Message Tests<commit_after>package mama.ng.scheduler

import grails.test.mixin.Mock
import grails.test.mixin.TestFor
import grails.test.mixin.TestMixin
import grails.test.mixin.domain.DomainClassUnitTestMixin
import groovy.time.TimeCategory
import org.codehaus.groovy.runtime.typehandling.GroovyCastException
import spock.lang.Specification

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestMixin(DomainClassUnitTestMixin)
@TestFor(Message)
@Mock([Schedule, Message])
class MessageSpec extends Specification {

    Message message
    Schedule schedule

    def setup() {
        use (TimeCategory) {
            mockForConstraintsTests(Message)
            schedule = new Schedule(
                userId: "user-id",
                frequency: 5,
                cronDefinition: "0 9 * * 3",
                nextSend: new Date() + 2.days,
                endpoint: "http://test.endpoint.com"
            ).save(failOnError: true)
            message = new Message(
                schedule: schedule,
                nextSend: new Date() + 2.days
            )
        }
    }

    def cleanup() {
        message.delete()
        schedule.delete()
    }

    void "test null schedule"() {
        given:
            message.schedule = null
            message.save()
        expect:
            message.hasErrors()
            message.errors["schedule"].equals("nullable")
    }

    void "test incorrect type schedule"() {
        when:
            message.schedule = "schedule-id"
            message.save()
        then:
{'fraction_non_alphanumeric': 0.09862241703193488, 'fraction_numerical': 0.003757044458359424, 'mean_word_length': 2.07507218479307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4546974', 'n_tokens_mistral': 897, 'n_tokens_neox': 857, 'n_words': 194}