<commit_before><?php

require_once("bread-basket.php");
require_once dirname(__DIR__) . "/vendor/autoload.php";
require_once dirname(__DIR__) . "/public_html/php/classes/autoloader.php";

/**
 * Class ListingTypeApiTest
 *
 * This is a test of the listing type class.
 *
 * @see ListingType
 */
class ListingTypeApiTest extends BreadBasketTest {

	//Todo do I really not need a listingID to test?
	/**
	 * valid listing type to use
	 * @var String $VALID_TYPE
	 */
	protected $VALID_TYPE = "Perishable";

	/**
	 * valid listing type to use
	 * @var String $VALID_TYPE
	 */
	protected $VALID_TYPE_2 = "Refrigerated";

	/**
	 * Guzzle client used to perform the tests
	 * @var GuzzleHttp/Client $guzzle
	 */
	protected $guzzle = null;
	/**
	 * XSRF token retrieved from the server
	 * @var String $token
	 */
	protected $token;
	/**
	 * valid admin user to test with
	 * @var volunteer object $admin
	 */
	protected $admin = null;
	/**
	 * valid volunteer user to test with
	 * @var volunteer object $volunteer
	 */
	protected $volunteer = null;

	/**
	 * set up for dependents before running each test
	 */
	public final function setUp() {
		//run default set-up method
		parent::setUp();

//		//create a new listingType for the test
		$listingType = new ListingType(null, 'Perishable');
		$listingType->insert($this->getPDO());


		//create the guzzle client
		$this->guzzle = new \GuzzleHttp\Client(["cookies" => true]);

		//visit ourselves to get the xsrf-token Todo needs to change based on where this is run
		$this->guzzle->get('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype');
		$cookies = $this->guzzle->getConfig()["cookies"];
		$this->token = $cookies->getCookieByName("XSRF-TOKEN")->getValue();

		//send a request to the sign-in method

		$adminLogin = new stdClass();
		$adminLogin->email = "<EMAIL>";
		$adminLogin->password = "<PASSWORD>";
		$login = $this->guzzle->post('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype', [
				'json' => $adminLogin,
				'headers' => ['X-XSRF-TOKEN' => $this->token]
		]);

	}


	public function testValidGet() {
		//test getting by parameter new listing type
		//create a new listing type, and insert into the database
		$listingType = new ListingType(null, $this->VALID_TYPE);
		$listingType->insert($this->getPDO());

		//send the get request to the API
		$response = $this->guzzle->delete('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype/' . $listingType->getListingTypeId(),
				['headers' => ['X-XSRF-TOKEN' => $this->token]
				]);

		//ensure the response was sent, and the api returned a positive status
		$this->assertSame($response->getStatusCode(), 200);
		$body = $response->getBody();
		$retrievedOrg = json_decode($body);
		$this->assertSame(200, $retrievedOrg->status);

		//ensure the returned values meet expectations (just checking enough to make sure the right thing was obtained)
		$this->assertSame($retrievedOrg->data->listingTypeId, $listingType->getListingTypeById());
		$this->assertSame($retrievedOrg->data->listingTypeInfo, $this->VALID_TYPE);

	}

	public function testValidGetAll() {
			//test getting all new listing type
			//create a new listing type, and insert into the database
			$listingType = new ListingType(null, $this->VALID_TYPE_2);
			$listingType->insert($this->getPDO());

			//send the get request to the API
			$response = $this->guzzle->delete('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype/' . $listingType->getListingTypeId(),
					['headers' => ['X-XSRF-TOKEN' => $this->token]
					]);

			//ensure the response was sent, and the api returned a positive status
			$this->assertSame($response->getStatusCode(), 200);
			$body = $response->getBody();
			$retrievedOrg = json_decode($body);
			$this->assertSame(200, $retrievedOrg->status);

			//ensure the returned values meet expectations (just checking enough to make sure the right thing was obtained)
			$this->assertSame($retrievedOrg->data->listingTypeId, $listingType->getAllListingTypes());
			$this->assertSame($retrievedOrg->data->listingTypeInfo, $this->VALID_TYPE);
		}
	}<commit_msg>Minor changes to - Changed ListingType API tests to just GETs for listingTypeById and ByAll. https://app.asana.com/0/60990639151493/65845329304710<commit_after><?php

require_once("bread-basket.php");
require_once dirname(__DIR__) . "/vendor/autoload.php";
require_once dirname(__DIR__) . "/public_html/php/classes/autoloader.php";

/**
 * Class ListingTypeApiTest
 *
 * This is a test of the listing type class.
 *
 * @see ListingType
 */
class ListingTypeApiTest extends BreadBasketTest {

	//Todo do I really not need a listingID to test?
	/**
	 * valid listing type to use
	 * @var String $VALID_TYPE
	 */
	protected $VALID_TYPE = "Perishable";

	/**
	 * valid listing type to use
	 * @var String $VALID_TYPE
	 */
	protected $VALID_TYPE_2 = "Refrigerated";

	/**
	 * Guzzle client used to perform the tests
	 * @var GuzzleHttp/Client $guzzle
	 */
	protected $guzzle = null;
	/**
	 * XSRF token retrieved from the server
	 * @var String $token
	 */
	protected $token;
	/**
	 * valid admin user to test with
	 * @var volunteer object $admin
	 */
	protected $admin = null;
	/**
	 * valid volunteer user to test with
	 * @var volunteer object $volunteer
	 */
	protected $volunteer = null;

	/**
	 * set up for dependents before running each test
	 */
	public final function setUp() {
		//run default set-up method
		parent::setUp();

//		//create a new listingType for the test
		$listingType = new ListingType(null, 'Perishable');
		$listingType->insert($this->getPDO());


		//create the guzzle client
		$this->guzzle = new \GuzzleHttp\Client(["cookies" => true]);

		//visit ourselves to get the xsrf-token
		$this->guzzle->get('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype');
		$cookies = $this->guzzle->getConfig()["cookies"];
		$this->token = $cookies->getCookieByName("XSRF-TOKEN")->getValue();

		//send a request to the sign-in method

		$adminLogin = new stdClass();
		$adminLogin->email = "<EMAIL>";
		$adminLogin->password = "<PASSWORD>";
		$login = $this->guzzle->post('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype', [
				'json' => $adminLogin,
				'headers' => ['X-XSRF-TOKEN' => $this->token]
		]);

	}


	public function testValidGet() {
		//test getting by parameter new listing type
		//create a new listing type, and insert into the database
		$listingType = new ListingType(null, $this->VALID_TYPE);
		$listingType->insert($this->getPDO());

		//send the get request to the API
		$response = $this->guzzle->delete('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype/' . $listingType->getListingTypeId(),
				['headers' => ['X-XSRF-TOKEN' => $this->token]
				]);

		//ensure the response was sent, and the api returned a positive status
		$this->assertSame($response->getStatusCode(), 200);
		$body = $response->getBody();
		$retrievedListingType = json_decode($body);
		$this->assertSame(200, $retrievedListingType->status);

		//ensure the returned values meet expectations (just checking enough to make sure the right thing was obtained)
		$this->assertSame($retrievedListingType->data->listingTypeId, $listingType->getListingTypeById());
		$this->assertSame($retrievedListingType->data->listingTypeInfo, $this->VALID_TYPE);

	}

	public function testValidGetAll() {
			//test getting all new listing type
			//create a new listing type, and insert into the database
			$listingType = new ListingType(null, $this->VALID_TYPE_2);
			$listingType->insert($this->getPDO());

			//send the get request to the API
			$response = $this->guzzle->delete('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/listingtype/' . $listingType->getListingTypeId(),
					['headers' => ['X-XSRF-TOKEN' => $this->token]
					]);

			//ensure the response was sent, and the api returned a positive status
			$this->assertSame($response->getStatusCode(), 200);
			$body = $response->getBody();
			$retrievedListingType = json_decode($body);
			$this->assertSame(200, $retrievedListingType->status);

			//ensure the returned values meet expectations (just checking enough to make sure the right thing was obtained)
			$this->assertSame($retrievedListingType->data->listingTypeId, $listingType->getAllListingTypes());
			$this->assertSame($retrievedListingType[0]->data->listingTypeInfo, $this->VALID_TYPE);
		}
	}

{'fraction_non_alphanumeric': 0.14801905425816198, 'fraction_numerical': 0.006738701057278959, 'mean_word_length': 4.1668667466986795, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 133, 'https://': 9, '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': '4799238', 'n_tokens_mistral': 3054, 'n_tokens_neox': 2705, 'n_words': 690}