mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
bring http://localhost/state-balances/ajaxListTransactions to live
This commit is contained in:
parent
98b5a0817e
commit
4e6e627da7
@ -159,9 +159,9 @@ class AppController extends Controller
|
||||
if ($session_id != 0) {
|
||||
$userStored = $session->read('StateUser');
|
||||
|
||||
|
||||
$transactionPendings = $session->read('Transaction.pending');
|
||||
$transactionExecutings = $session->read('Transaction.executing');
|
||||
$transactionExecutings = $session->read('Transaction.executing');
|
||||
|
||||
if ($session->read('session_id') != $session_id ||
|
||||
( $userStored && (!isset($userStored['id']) || !$userStored['email_checked'])) ||
|
||||
intval($transactionPendings) > 0 ||
|
||||
@ -182,6 +182,8 @@ class AppController extends Controller
|
||||
$session->destroy();
|
||||
}
|
||||
foreach ($json['user'] as $key => $value) {
|
||||
// we don't need the id of user in login server db
|
||||
if($key == 'id') continue;
|
||||
$session->write('StateUser.' . $key, $value);
|
||||
}
|
||||
//var_dump($json);
|
||||
|
||||
@ -21,7 +21,7 @@ class StateBalancesController extends AppController
|
||||
{
|
||||
parent::initialize();
|
||||
//$this->Auth->allow(['add', 'edit']);
|
||||
$this->Auth->allow(['overview', 'overviewGdt', 'ajaxGetBalance']);
|
||||
$this->Auth->allow(['overview', 'overviewGdt', 'ajaxGetBalance', 'ajaxListTransactions']);
|
||||
$this->loadComponent('JsonRequestClient');
|
||||
}
|
||||
/**
|
||||
@ -215,34 +215,32 @@ class StateBalancesController extends AppController
|
||||
return $this->returnJson(['state' => 'success', 'balance' => $state_balances[0]->amount]);
|
||||
}
|
||||
|
||||
public function ajaxListTransactions($session_id, $page, $count)
|
||||
public function ajaxListTransactions($session_id = 0)
|
||||
{
|
||||
if(!isset($session_id) || !$session_id) {
|
||||
return $this->returnJson(['state' => 'error', 'msg' => 'invalid session']);
|
||||
if(!$session_id) {
|
||||
return $this->returnJson(['state' => 'error', 'msg' => 'invalid session id']);
|
||||
}
|
||||
|
||||
$startTime = microtime(true);
|
||||
$session = $this->getRequest()->getSession();
|
||||
$result = $this->requestLogin($session_id);
|
||||
if ($result !== true) {
|
||||
return $this->returnJson(['state' => 'error', 'msg' => 'session not found']);
|
||||
$login_result = $this->requestLogin($session_id, false);
|
||||
if($login_result !== true) {
|
||||
return $this->returnJson($login_result);
|
||||
}
|
||||
$session = $this->getRequest()->getSession();
|
||||
$user = $session->read('StateUser');
|
||||
|
||||
$gdtSum = 0;
|
||||
|
||||
|
||||
$gdtSum = 0;
|
||||
$gdtEntries = $this->JsonRequestClient->sendRequestGDT(['email' => $user['email']], 'GdtEntries' . DS . 'sumPerEmailApi');
|
||||
|
||||
if('success' == $gdtEntries['state'] && 'success' == $gdtEntries['data']['state']) {
|
||||
$gdtSum = intval($gdtEntries['data']['sum']);
|
||||
} else {
|
||||
if($user) {
|
||||
|
||||
if($user) {
|
||||
$this->addAdminError('StateBalancesController', 'overview', $gdtEntries, $user['id']);
|
||||
} else {
|
||||
$this->addAdminError('StateBalancesController', 'overview', $gdtEntries, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$creationsTable = TableRegistry::getTableLocator()->get('TransactionCreations');
|
||||
$creationTransactions = $creationsTable
|
||||
|
||||
@ -45,21 +45,21 @@ class TransactionCreationsFixture extends TestFixture
|
||||
[
|
||||
'id' => 1,
|
||||
'transaction_id' => 1,
|
||||
'state_user_id' => 2,
|
||||
'state_user_id' => 1,
|
||||
'amount' => 10000000,
|
||||
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'transaction_id' => 2,
|
||||
'state_user_id' => 2,
|
||||
'state_user_id' => 1,
|
||||
'amount' => 10000000,
|
||||
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'transaction_id' => 3,
|
||||
'state_user_id' => 2,
|
||||
'state_user_id' => 1,
|
||||
'amount' => 10000000,
|
||||
'ident_hash' => hex2bin('3235303332373635330000000000000000000000000000000000000000000000')
|
||||
],
|
||||
|
||||
@ -43,10 +43,10 @@ class TransactionSendCoinsFixture extends TestFixture
|
||||
[
|
||||
'id' => 1,
|
||||
'transaction_id' => 4,
|
||||
'state_user_id' => 2,
|
||||
'receiver_public_key' => '0x80183e03535d17a54ff1fd7dbaed86939d423a19a258c26b8e338ce601338355',
|
||||
'receiver_user_id' => 1,
|
||||
'amount' => 150000001,
|
||||
'state_user_id' => 1,
|
||||
'receiver_public_key' => '8190bda585ee5f1d9fbf7d06e81e69ec18e13376104cff54b7457eb7d3ef710d',
|
||||
'receiver_user_id' => 4,
|
||||
'amount' => 15000000,
|
||||
'sender_final_balance' => 15000000
|
||||
],
|
||||
];
|
||||
|
||||
@ -123,7 +123,38 @@ class StateBalancesControllerTest extends TestCase
|
||||
*/
|
||||
public function testAjaxListTransactions()
|
||||
{
|
||||
$this->markTestIncomplete('Not implemented yet.');
|
||||
//ajaxListTransactions
|
||||
$session_id = rand();
|
||||
$this->session([
|
||||
'session_id' => $session_id,
|
||||
'Transaction' => ['pending' => 0, 'executing' => 0],
|
||||
'StateUser' => [
|
||||
'id' => 1,
|
||||
'first_name' => 'Dario',
|
||||
'last_name' => 'Frodo',
|
||||
'email_checked' => 1,
|
||||
'email' => 'fördertest@gradido.org',
|
||||
'public_hex' => '94ae135b93cd9f33752b4e55c41903a3faa13a75bb90bfd411ea1d4a1a5e711f'
|
||||
]
|
||||
]);
|
||||
//echo "balance: $balance";
|
||||
$this->getAndParse('/state-balances/ajaxListTransactions/' . $session_id,
|
||||
[
|
||||
'state' => 'success', 'transactions' => [[
|
||||
'name' => 'Dario Frodo',
|
||||
'email'=> 'dariofrodo@gmx.de',
|
||||
'type'=> '',
|
||||
'transaction_id' => 4,
|
||||
'date' => '2021-02-19T13:27:14+00:00',
|
||||
'balance' => 150000001,
|
||||
'memo' => ''
|
||||
]],
|
||||
'transactionExecutingCount' => 0,
|
||||
'count' => 1,
|
||||
'gdtSum' => 0,
|
||||
'timeUsed' => 0.03168010711669922
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,10 +233,16 @@ class StateBalancesControllerTest extends TestCase
|
||||
$responseBodyString = (string)$this->_response->getBody();
|
||||
$json = json_decode($responseBodyString);
|
||||
$this->assertNotFalse($json);
|
||||
|
||||
|
||||
if(is_array($expected)) {
|
||||
// copy timeUsed because this value will be variy always
|
||||
if(isset($expected['timeUsed']) && isset($json->timeUsed)) {
|
||||
$expected['timeUsed'] = $json->timeUsed;
|
||||
}
|
||||
$expected = json_encode($expected);
|
||||
}
|
||||
|
||||
|
||||
$this->assertEquals($expected, $responseBodyString);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user