function AcquiaLiftTest::testSaveAgent in Acquia Lift Connector 7
File
- tests/AcquiaLiftAPI.test, line 1490
- Unit tests for Acquia Lift module.
Class
- AcquiaLiftTest
- @file
Unit tests for Acquia Lift module.
Code
function testSaveAgent() {
$lift_api = $this
->getAcquiaLiftAPI();
$agentName = 'some-test-agent';
$lift_api
->saveAgent($agentName, 'Some Test Agent', 'adaptive', 'enabled');
$requests = array(
array(
'type' => 'put',
'uri' => "http://api.lift.acquia.com/{$this->liftOwnerCode}/agent-api/{$agentName}?apikey={$this->liftAdminKey}",
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
'Accept' => 'application/json',
),
'options' => array(),
'body' => array(
'name' => 'Some Test Agent',
'selection-mode' => 'adaptive',
'status' => 'enabled',
'control-rate' => 0.1,
'explore-rate' => 0.2,
'decision-stickiness' => 'session',
),
),
);
$this
->assertAPIRequests($requests);
DummyAcquiaLiftHttpClient::clearLoggedRequests();
$logs = array(
array(
'level' => PersonalizeLogLevel::INFO,
'message' => "The campaign {$agentName} was pushed to Acquia Lift",
),
);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
$this
->assertAPIRequests(array());
$lift_api
->saveAgent($agentName, 'Some Test Agent', 'adaptive', PERSONALIZE_STATUS_RUNNING);
$this
->assertAPIRequests($requests);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
$this
->assertAPIRequests(array());
$lift_api
->saveAgent($agentName, 'Some Test Agent', 'adaptive', 'enabled', 0.1, 0.4);
$requests = array(
array(
'type' => 'put',
'uri' => "http://api.lift.acquia.com/{$this->liftOwnerCode}/agent-api/{$agentName}?apikey={$this->liftAdminKey}",
'headers' => array(
'Content-Type' => 'application/json; charset=utf-8',
'Accept' => 'application/json',
),
'options' => array(),
'body' => array(
'name' => 'Some Test Agent',
'selection-mode' => 'adaptive',
'status' => 'enabled',
'control-rate' => 0.1,
'explore-rate' => 0.4,
'decision-stickiness' => 'session',
),
),
);
$this
->assertAPIRequests($requests);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
$lift_api
->saveAgent($agentName, 'Some Test Agent', 'adaptive', 'enabled', 0.1, 0.4, 0);
$requests[0]['body']['decision-stickiness'] = 'none';
$this
->assertAPIRequests($requests);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
$lift_api
->saveAgent($agentName, 'Some Test Agent', 'narf', 'enabled', 0.1, 0.4, 0);
$this
->assertAPIRequests($requests);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
$lift_api = $this
->getAcquiaLiftAPI(TRUE);
try {
$lift_api
->saveAgent('some-test-agent', 'Some Test Agent', 'adaptive', 'enabled', 0.1, 0.4, 0);
} catch (Exception $e) {
$this
->assertTrue($e instanceof AcquiaLiftException);
}
$this
->assertAPIRequests($requests);
$logs = array(
array(
'level' => PersonalizeLogLevel::ERROR,
'message' => "The campaign {$agentName} could not be pushed to Acquia Lift",
),
);
$this
->assertLogs($logs);
$this->logger
->clearLogs();
}