/**
  * Test grabbing Valid Product by alertId
  **/
 public function testGetValidProductByAlertId()
 {
     // create a new AlertLevel
     $newAlertLevel = new AlertLevel(null, $this->VALID_alertCode, $this->VALID_alertFrequency, $this->VALID_alertPoint, $this->VALID_alertOperator);
     $newAlertLevel->insert($this->getPDO());
     // create a new ProductAlert
     $newProductAlert = new ProductAlert($newAlertLevel->getAlertId(), $this->product->getProductId(), true);
     $newProductAlert->insert($this->getPDO());
     // grab the data from guzzle
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/alert-level/?alertId=' . $newAlertLevel->getAlertId() . "&getProducts=true");
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $alertLevel = json_decode($body);
     $this->assertSame(200, $alertLevel->status);
 }
 /**
  * Test grabbing Valid Notifications by productId
  **/
 public function testGetValidNotificationByProductId()
 {
     // create a new Product
     $newProduct = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $newProduct->insert($this->getPDO());
     // create a new ProductAlert and insert to into mySQL
     $productAlert = new ProductAlert($this->alertLevel->getAlertId(), $newProduct->getProductId(), true);
     $productAlert->insert($this->getPDO());
     // grab the data from guzzle
     $response = $this->guzzle->get('https://bootcamp-coders.cnm.edu/~invtext/backend/php/api/product/?productId=' . $newProduct->getProductId() . "&getNotifications=true");
     $this->assertSame($response->getStatusCode(), 200);
     $body = $response->getBody();
     $product = json_decode($body);
     $this->assertSame(200, $product->status);
 }
Esempio n. 3
0
 /**
  * test grabbing product by notification
  **/
 public function testGetValidNotificationByProductId()
 {
     // create a new product and insert to into mySQL
     $product = new Product(null, $this->vendor->getVendorId(), $this->VALID_description, $this->VALID_leadTime, $this->VALID_sku, $this->VALID_title);
     $product->insert($this->getPDO());
     // create a new product and insert to into mySQL
     $productAlert = new ProductAlert($this->alertLevel->getAlertId(), $product->getProductId(), true);
     $productAlert->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoNotificationArray = Product::getNotificationByProductId($this->getPDO(), $product->getProductId());
     for ($i = 0; $i < count($pdoNotificationArray); $i++) {
         if ($i === 0) {
             $this->assertSame($pdoNotificationArray[$i]->getVendorId(), $this->vendor->getVendorId());
             $this->assertSame($pdoNotificationArray[$i]->getDescription(), $this->VALID_description);
             $this->assertSame($pdoNotificationArray[$i]->getLeadTime(), $this->VALID_leadTime);
             $this->assertSame($pdoNotificationArray[$i]->getSku(), $this->VALID_sku);
             $this->assertSame($pdoNotificationArray[$i]->getTitle(), $this->VALID_title);
         } else {
             $this->assertSame($pdoNotificationArray[$i]->getNotificationId(), $this->notification->getNotificationId());
             $this->assertSame($pdoNotificationArray[$i]->getAlertId(), $this->notification->getAlertId());
             $this->assertSame($pdoNotificationArray[$i]->getEmailStatus(), $this->notification->getEmailStatus());
             $this->assertEquals($pdoNotificationArray[$i]->getNotificationDateTime(), $this->notification->getNotificationDateTime());
             $this->assertSame($pdoNotificationArray[$i]->getNotificationHandle(), $this->notification->getNotificationHandle());
             $this->assertSame($pdoNotificationArray[$i]->getNotificationContent(), $this->notification->getNotificationContent());
         }
     }
 }
 public function setUp()
 {
     parent::setUp();
     $vendorId = null;
     $contactName = "Trevor Rigler";
     $vendorEmail = "*****@*****.**";
     $vendorName = "TruFork";
     $vendorPhoneNumber = "5053594687";
     $vendor = new Vendor($vendorId, $contactName, $vendorEmail, $vendorName, $vendorPhoneNumber);
     $vendor->insert($this->getPDO());
     $productId = null;
     $vendorId = $vendor->getVendorId();
     $description = "A glorius bead to use";
     $leadTime = 10;
     $sku = "TGT354";
     $title = "Bead-Green-Blue-Circular";
     $this->product = new Product($productId, $vendorId, $description, $leadTime, $sku, $title);
     $this->product->insert($this->getPDO());
     $alertId = null;
     $alertCode = "33";
     $alertFrequency = "11";
     $alertLevel = "100.01";
     $alertOperator = "1";
     $this->alertLevel = new AlertLevel($alertId, $alertCode, $alertFrequency, $alertLevel, $alertOperator);
     $this->alertLevel->insert($this->getPDO());
     $productEnabled = true;
     $this->productAlert = new ProductAlert($this->alertLevel->getAlertId(), $this->product->getProductId(), $productEnabled);
     $this->productAlert->insert($this->getPDO());
     $this->VALID_notificationDateTime = DateTime::createFromFormat("Y-m-d H:i:s", "1985-06-28 04:26:03");
 }
 /**
  * test grabbing a ProductAlert by alertEnabled
  **/
 public function testGetValidProductAlertByAlertEnabled()
 {
     // count the number of rows and save it for later
     $numRows = $this->getConnection()->getRowCount("productAlert");
     // create a new ProductAlert and insert to into mySQL
     $productAlert = new ProductAlert($this->alertLevel->getAlertId(), $this->product->getProductId(), $this->VALID_alertEnabled);
     $productAlert->insert($this->getPDO());
     // grab the data from mySQL and enforce the fields match our expectations
     $pdoProductAlert = ProductAlert::getProductAlertByAlertEnabled($this->getPDO(), $productAlert->isAlertEnabled());
     foreach ($pdoProductAlert as $pdoPA) {
         $this->assertSame($numRows + 1, $this->getConnection()->getRowCount("productAlert"));
         $this->assertSame($pdoPA->getAlertId(), $this->alertLevel->getAlertId());
         $this->assertSame($pdoPA->getProductId(), $this->product->getProductId());
         $this->assertSame($pdoPA->isAlertEnabled(), $this->VALID_alertEnabled);
     }
 }