<commit_before>require "rack/test"
require "test/unit"
require_relative "../test_case"
require_relative "../../routes/api_routes"

class ApiRoutesTest < HikeAppTestCase

	def setup
		header "Accept", "application/json" 
	end

	def test_get_hikes_ok
		get "/api/v1/hikes"
		assert last_response.ok?
	end

	def test_get_hikes_returns_multiple_hikes
		get "/api/v1/hikes"
		json = JSON.parse(last_response.body)
		assert json.length > 0
	end

	def test_get_hike_by_id
		get "/api/v1/hikes/1"
		json = JSON.parse(last_response.body)
		assert_equal json["id"], 1
	end

	def test_get_hike_by_string_id
		get "/api/v1/hikes/scotchman-peak"
		json = JSON.parse(last_response.body)
		assert_equal json["string_id"], "scotchman-peak"
	end

	def test_put_hike_name
		newName = "New name"
		data = {:name => newName}
		put "/api/v1/hikes/scotchman-peak", data.to_json
		json = JSON.parse(last_response.body)
		assert_equal json["string_id"], "scotchman-peak"
		assert_equal json["name"], newName
	end
end<commit_msg>Validate PUTs get persisted.<commit_after>require "rack/test"
require "test/unit"
require_relative "../test_case"
require_relative "../../routes/api_routes"

class ApiRoutesTest < HikeAppTestCase

	def setup
		header "Accept", "application/json" 
	end

	def test_get_hikes_ok
		get "/api/v1/hikes"
		assert last_response.ok?
	end

	def test_get_hikes_returns_multiple_hikes
		get "/api/v1/hikes"
		json = JSON.parse(last_response.body)
		assert json.length > 0
	end

	def test_get_hike_by_id
		get "/api/v1/hikes/1"
		json = JSON.parse(last_response.body)
		assert_equal json["id"], 1
	end

	def test_get_hike_by_string_id
		get "/api/v1/hikes/scotchman-peak"
		json = JSON.parse(last_response.body)
		assert_equal json["string_id"], "scotchman-peak"
	end

	def test_put_hike_name
		newName = "<NAME>"
		data = {:name => newName}
		put "/api/v1/hikes/scotchman-peak", data.to_json

		json = JSON.parse(last_response.body)
		assert_equal json["string_id"], "scotchman-peak"
		assert_equal json["name"], newName

		get "/api/v1/hikes/scotchman-peak"
		json = JSON.parse(last_response.body)
		assert_equal json["string_id"], "scotchman-peak"
		assert_equal json["name"], newName
	end
end
{'fraction_non_alphanumeric': 0.12340036563071298, 'fraction_numerical': 0.007769652650822669, 'mean_word_length': 4.431761786600497, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '1994224', 'n_tokens_mistral': 915, 'n_tokens_neox': 848, 'n_words': 161}