<commit_before>package io.coderate.accurest.builder

import io.coderate.accurest.dsl.GroovyDsl
import spock.lang.Specification

/**
 * @author <NAME>
 */
class SpockMethodBuilderSpec extends Specification {

	def "should generate assertions for simple response body"() {
		given:
			GroovyDsl contractDsl = GroovyDsl.make {
				request {
					method "GET"
					url "test"
				}
				response {
					status 200
					body """{
    "property1": "a",
    "property2": "b"
}"""
				}
			}
			SpockMethodBodyBuilder builder = new SpockMethodBodyBuilder(contractDsl)
			BlockBuilder blockBuilder = new BlockBuilder(" ")
		when:
			builder.appendTo(blockBuilder)
		then:
			blockBuilder.toString().contains("responseBody.property1 == \"a\"")
			blockBuilder.toString().contains("responseBody.property2 == \"b\"")
	}

	def "should generate assertions for array in response body"() {
		given:
			GroovyDsl contractDsl = GroovyDsl.make {
				request {
					method "GET"
					url "test"
				}
				response {
					status 200
					body """[
{
    "property1": "a"
},
{
    "property2": "b"
}]"""
				}
			}
			SpockMethodBodyBuilder builder = new SpockMethodBodyBuilder(contractDsl)
			BlockBuilder blockBuilder = new BlockBuilder(" ")
		when:
			builder.appendTo(blockBuilder)
		then:
			blockBuilder.toString().contains("responseBody[0].property1 == \"a\"")
			blockBuilder.toString().contains("responseBody[1].property2 == \"b\"")
	}

	def "should generate assertions for array inside response body element"() {
		given:
			GroovyDsl contractDsl = GroovyDsl.make {
				request {
					method "GET"
					url "test"
				}
				response {
					status 200
					body """{
    "property1": [
    { "property2": "test1"},
    { "property3": "test2"}
    ]
}"""
				}
			}
			SpockMethodBodyBuilder builder = new SpockMethodBodyBuilder(contractDsl)
			BlockBuilder blockBuilder = new BlockBuilder(" ")
		when:
			builder.appendTo(blockBuilder)
		then:
			blockBuilder.toString().contains("responseBody.property1[0].property2 == \"test1\"")
			blockBuilder.toString().contains("responseBody.property1[1].property3 == \"test2\"")
	}
}<commit_msg>Fix #46 - Added test for nested objects in response body<commit_after>package io.coderate.accurest.builder

import io.coderate.accurest.dsl.GroovyDsl
import spock.lang.Specification

/**
 * @author <NAME>
 */
class SpockMethodBuilderSpec extends Specification {

	def "should generate assertions for simple response body"() {
		given:
			GroovyDsl contractDsl = GroovyDsl.make {
				request {
					method "GET"
					url "test"
				}
				response {
					status 200
					body """{
    "property1": "a",
    "property2": "b"
}"""
				}
			}
			SpockMethodBodyBuilder builder = new SpockMethodBodyBuilder(contractDsl)
			BlockBuilder blockBuilder = new BlockBuilder(" ")
		when:
			builder.appendTo(blockBuilder)
		then:
			blockBuilder.toString().contains("responseBody.property1 == \"a\"")
			blockBuilder.toString().contains("responseBody.property2 == \"b\"")
	}

	def "should generate assertions for array in response body"() {
		given:
			GroovyDsl contractDsl = GroovyDsl.make {
				request {
					method "GET"
					url "test"
				}
				response {
					status 200
					body """[
{
    "property1": "a"
},
{
    "property2": "b"
}]"""
				}
			}
			SpockMethodBodyBuilder builder = new SpockMethodBodyBuilder(contractDsl)
			BlockBuilder blockBuilder = new BlockBuilder(" ")
		when:
			builder.appendTo(blockBuilder)
		then:
			blockBuilder.toString().contains("responseBody[0].property1 == \"a\"")
			blockBuilder.toString().contains("responseBody[1].property2 == \"b\"")
	}

	def "should generate assertions for array inside response body element"() {
		given:
			GroovyDsl contractDsl = GroovyDsl.make {
				request {
					method "GET"
					url "test"
				}
				response {
					status 200
					body """{
    "property1": [
    { "property2": "test1"},
    { "property3": "test2"}
    ]
}"""
				}
			}
			SpockMethodBodyBuilder builder = new SpockMethodBodyBuilder(contractDsl)
			BlockBuilder blockBuilder = new BlockBuilder(" ")
		when:
			builder.appendTo(blockBuilder)
		then:
			blockBuilder.toString().contains("responseBody.property1[0].property2 == \"test1\"")
			blockBuilder.toString().contains("responseBody.property1[1].property3 == \"test2\"")
	}

	def "should generate assertions for nested objects in response body"() {
		given:
			GroovyDsl contractDsl = GroovyDsl.make {
				request {
					method "GET"
					url "test"
				}
				response {
					status 200
					body '''\
{
    "property1": "a",
    "property2": {"property3": "b"}
}
'''
				}
			}
			SpockMethodBodyBuilder builder = new SpockMethodBodyBuilder(contractDsl)
			BlockBuilder blockBuilder = new BlockBuilder(" ")
		when:
			builder.appendTo(blockBuilder)
		then:
			blockBuilder.toString().contains("responseBody.property1 == \"a\"")
			blockBuilder.toString().contains("responseBody.property2.property3 == \"b\"")
	}
}
{'fraction_non_alphanumeric': 0.13560698335363378, 'fraction_numerical': 0.015225334957369063, 'mean_word_length': 3.4109221128021487, 'pattern_counts': {'":': 17, '<': 5, '<?xml version=': 0, '>': 5, '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': '2774318', 'n_tokens_mistral': 1929, 'n_tokens_neox': 1541, 'n_words': 324}