Skip to content

Commit

Permalink
CAS-6994
Browse files Browse the repository at this point in the history
  • Loading branch information
dawlib committed May 25, 2021
1 parent 55fa26b commit 7f7c529
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 0 deletions.
37 changes: 37 additions & 0 deletions lib/Castle/Castle.php
Expand Up @@ -161,4 +161,41 @@ public static function track(Array $attributes)
$request = new Castle_Request();
$request->send('post', '/track', $attributes);
}


/**
* Filter an action
* @param Array $attributes An array of attributes to filter. The 'name' key
* is required
* @return None
*/
public static function filter(Array $attributes)
{
$request = new Castle_Request();
$request->send('post', '/filter', $attributes);
}

/**
* Log events
* @param Array $attributes An array of attributes to track. The 'name' key
* is required
* @return None
*/
public static function log(Array $attributes)
{
$request = new Castle_Request();
$request->send('post', '/log', $attributes);
}

/**
* Risk
* @param Array $attributes An array of attributes to track. The 'name' key
* is required
* @return None
*/
public static function risk(Array $attributes)
{
$request = new Castle_Request();
$request->send('post', '/risk', $attributes);
}
}
6 changes: 6 additions & 0 deletions lib/Castle/Models/Filter.php
@@ -0,0 +1,6 @@
<?php

class Castle_Filter extends RestModel
{
protected $isSingular = true;
}
6 changes: 6 additions & 0 deletions lib/Castle/Models/Log.php
@@ -0,0 +1,6 @@
<?php

class Castle_Log extends RestModel
{
protected $isSingular = true;
}
6 changes: 6 additions & 0 deletions lib/Castle/Models/Risk.php
@@ -0,0 +1,6 @@
<?php

class Castle_Risk extends RestModel
{
protected $isSingular = true;
}
3 changes: 3 additions & 0 deletions test/Castle.php
Expand Up @@ -28,6 +28,9 @@ public function assertRequest($method, $url, $headers=null)
require(dirname(__FILE__) . '/../lib/RestModel/Resource.php');
require(dirname(__FILE__) . '/../lib/RestModel/Model.php');
require(dirname(__FILE__) . '/../lib/Castle/Models/Authenticate.php');
require(dirname(__FILE__) . '/../lib/Castle/Models/Filter.php');
require(dirname(__FILE__) . '/../lib/Castle/Models/Log.php');
require(dirname(__FILE__) . '/../lib/Castle/Models/Risk.php');
require(dirname(__FILE__) . '/../lib/Castle/Models/Review.php');
require(dirname(__FILE__) . '/../lib/Castle/Models/Context.php');
require(dirname(__FILE__) . '/TestTransport.php');
Expand Down
32 changes: 32 additions & 0 deletions test/CastleTest.php
Expand Up @@ -26,6 +26,38 @@ public function testTrack()
$this->assertRequest('post', '/track');
}

public function testFilter()
{
Castle_RequestTransport::setResponse(204, '');
Castle::filter(Array(
'name' => '$registration',
'user' => Array('id' => 'abc', 'email' => 'user@foobar.io')
));
$this->assertRequest('post', '/filter');
}

public function testLog()
{
Castle_RequestTransport::setResponse(204, '');
Castle::log(Array(
'name' => '$login',
'status' => '$failed',
'user' => Array('id' => 'abc', 'email' => 'user@foobar.io')
));
$this->assertRequest('post', '/log');
}

public function testRisk()
{
Castle_RequestTransport::setResponse(204, '');
Castle::risk(Array(
'name' => '$login',
'status' => '$succeeded',
'user' => Array('id' => 'abc', 'email' => 'user@foobar.io')
));
$this->assertRequest('post', '/risk');
}

public function testAuthenticate()
{
Castle_RequestTransport::setResponse(201, '{ "status": "approve" }');
Expand Down
17 changes: 17 additions & 0 deletions test/FilterTest.php
@@ -0,0 +1,17 @@
<?php

class CastleFilterTest extends Castle_TestCase
{
public function tearDown(): void
{
Castle_RequestTransport::reset();
Castle_RequestTransport::setResponse(200, '');
}

public function testApprove()
{
$auth = new Castle_Filter();
$auth->save();
$this->assertRequest('post', '/filter');
}
}
17 changes: 17 additions & 0 deletions test/LogTest.php
@@ -0,0 +1,17 @@
<?php

class CastleLogTest extends Castle_TestCase
{
public function tearDown(): void
{
Castle_RequestTransport::reset();
Castle_RequestTransport::setResponse(200, '');
}

public function testApprove()
{
$auth = new CastleLog();
$auth->save();
$this->assertRequest('post', 'log');
}
}
17 changes: 17 additions & 0 deletions test/RiskTest.php
@@ -0,0 +1,17 @@
<?php

class CastleRiskTest extends Castle_TestCase
{
public function tearDown(): void
{
Castle_RequestTransport::reset();
Castle_RequestTransport::setResponse(200, '');
}

public function testApprove()
{
$auth = new Castle_Risk();
$auth->save();
$this->assertRequest('post', '/risk');
}
}

0 comments on commit 7f7c529

Please sign in to comment.