Created
October 26, 2016 14:54
-
-
Save mgerasimchuk/a2f4b64ce14e2c0aff0aac114cc8988f to your computer and use it in GitHub Desktop.
Functional test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace tests\codeception\api\v1\affiliate; | |
use common\models\Campaign; | |
use common\models\UserAccount; | |
use tests\codeception\api\FunctionalTester; | |
use tests\codeception\common\fixtures\CampaignFixture; | |
use tests\codeception\common\fixtures\UserAccountFixture; | |
class AffiliateCampaignsCest | |
{ | |
public $jtwToken; | |
public function _before(FunctionalTester $I) | |
{ | |
$f = new UserAccountFixture(); | |
$I->loadFixtures([$f, new CampaignFixture()]); | |
/** @var UserAccount $model */ | |
$model = $f->getModel(25); | |
$this->jtwToken = $model->getJWT(); | |
} | |
public function _after(FunctionalTester $I) | |
{ | |
} | |
// tests | |
public function testList(FunctionalTester $I) | |
{ | |
$I->wantTo('get list of models'); | |
$I->haveHttpHeader('Content-Type', 'application/json'); | |
$I->haveHttpHeader('Authorization', 'Bearer ' . $this->jtwToken); | |
$I->sendGET('/v1/affiliate/affiliate-campaigns', [ | |
'start' => '1970-01-01T00:00:00+05:00', | |
'finish' => '2020-01-01T00:00:00+05:00' | |
]); | |
$I->seeResponseCodeIs(200); | |
$I->seeResponseIsJson(); | |
$I->seeResponseContainsJson(['success' => true]); | |
} | |
public function testCollectionOptions(FunctionalTester $I) | |
{ | |
$I->wantTo('get available http verbs of the collection'); | |
$I->haveHttpHeader('Content-Type', 'application/json'); | |
$I->sendOPTIONS('/v1/affiliate/affiliate-campaigns'); | |
$I->seeResponseCodeIs(200); | |
$I->seeResponseIsJson(); | |
$I->seeResponseContainsJson(['success' => true]); | |
$I->seeHttpHeader('Allow', 'GET, POST, HEAD, OPTIONS'); | |
} | |
// tests | |
public function testTotal(FunctionalTester $I) | |
{ | |
$I->wantTo('get total stats'); | |
$I->haveHttpHeader('Content-Type', 'application/json'); | |
$I->haveHttpHeader('Authorization', 'Bearer ' . $this->jtwToken); | |
$I->sendGET('/v1/affiliate/affiliate-campaigns/total', [ | |
'start' => '1970-01-01T00:00:00+05:00', | |
'finish' => '2020-01-01T00:00:00+05:00' | |
]); | |
$I->seeResponseCodeIs(200); | |
$I->seeResponseIsJson(); | |
$I->seeResponseContainsJson(['success' => true]); | |
} | |
public function testOptionsTotal(FunctionalTester $I) | |
{ | |
$I->wantTo('get available http verbs of the collection'); | |
$I->haveHttpHeader('Content-Type', 'application/json'); | |
$I->sendOPTIONS('/v1/affiliate/affiliate-campaigns/total'); | |
$I->seeResponseCodeIs(200); | |
$I->seeResponseIsJson(); | |
$I->seeResponseContainsJson(['success' => true]); | |
$I->seeHttpHeader('Allow', 'GET'); | |
} | |
public function testCreate(FunctionalTester $I) | |
{ | |
$I->wantTo('create new affiliate campaign'); | |
$I->haveHttpHeader('Content-Type', 'application/json'); | |
$I->haveHttpHeader('Authorization', 'Bearer ' . $this->jtwToken); | |
$I->sendPOST('/v1/campaigns', [ | |
'name' => 'Some unique name', | |
'description' => 'Some awesome description', | |
'owner_id' => 1, | |
'marketplace_category_id' => 1, | |
'visibility' => 5, | |
'commission_type_id' => 3, | |
'commission_price' => 0, | |
'offer_campaign_id' => 4, | |
'admin_campaign_id' => 1, | |
'affiliate_suffix' => 'suff', | |
'affiliate_notes' => 'some notes', | |
'language_id' => 1, | |
'status' => 1, | |
'type' => Campaign::TYPE_AFFILIATE_CAMPAIGN | |
]); | |
$I->seeResponseCodeIs(201); | |
$I->seeResponseIsJson(); | |
$I->seeResponseContainsJson(['success' => true]); | |
} | |
public function testUpdate(FunctionalTester $I) | |
{ | |
$I->wantTo('update affiliate campaign'); | |
$I->haveHttpHeader('Content-Type', 'application/json'); | |
$I->haveHttpHeader('Authorization', 'Bearer ' . $this->jtwToken); | |
$I->sendPUT('/v1/campaigns/8', [ | |
'name' => 'Some unique name', | |
'description' => 'Some awesome description', | |
'owner_id' => 1, | |
'marketplace_category_id' => 1, | |
'visibility' => 5, | |
'commission_type_id' => 3, | |
'commission_price' => 0, | |
'offer_campaign_id' => 4, | |
'admin_campaign_id' => 1, | |
'affiliate_suffix' => 'suff', | |
'affiliate_notes' => 'some notes', | |
'language_id' => 1, | |
'status' => 1, | |
'type' => Campaign::TYPE_AFFILIATE_CAMPAIGN | |
]); | |
$I->seeResponseCodeIs(200); | |
$I->seeResponseIsJson(); | |
$I->seeResponseContainsJson(['success' => true]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment