/** * @test */ public function it_creates_a_coupon() { $createCoupon = new CreateCoupon(uniqid(), new \DateTime()); $createCoupon->setSuspended(true); $createCoupon->addPackageDiscount(new PackageDiscount('book', 100)); $createCoupon->setNote('Coupon created by unit test'); $this->assertSame(true, $this->leanpubApi->createCoupon($this->bookSlug, $createCoupon)); }
/** * @test */ public function it_serializes_a_coupon_to_the_expected_json_format() { $start = new \DateTime('2014-02-16'); $end = null; $coupon = new CreateCoupon('1234', $start); $coupon->setMaxUses(10); $coupon->setNote('Sample coupon'); $coupon->setSuspended(true); $packageDiscount = new PackageDiscount('a-year-with-symfony', 10); $coupon->addPackageDiscount($packageDiscount); $this->assertSame('{"coupon_code":"1234","package_discounts_attributes":[{"package_slug":"a-year-with-symfony","discounted_price":10}],"start_date":"2014-02-16","end_date":null,"max_uses":10,"note":"Sample coupon","suspended":true}', $this->serializer->serialize($coupon, 'json')); }
/** * @test */ public function it_does_nothing_when_coupon_is_valid() { $createCoupon = new CreateCoupon('coupon-code', new \DateTime()); $createCoupon->addPackageDiscount(new PackageDiscount('package', 10)); $this->createCouponValidator->validate($createCoupon); }