Skip to content

Commit

Permalink
Allow to set charge date on creating (#138)
Browse files Browse the repository at this point in the history
Added `dateTime` as a create charge form to support setting charge date
on creating.
  • Loading branch information
vokomarov authored Oct 8, 2023
2 parents 73eb967 + ceac74c commit 507f38c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions app/src/Controller/Wallets/Charges/ChargesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public function create(string $walletId, CreateRequest $request): ResponseInterf
$charge->setWallet($wallet);
$charge->setUser($this->user);

if (($dateTime = $request->getDateTime()) !== null) {
$charge->createdAt = $dateTime;
}

$tags = $this->tagRepository->findAllByPKsAndUserPKs($request->tags, $wallet->getUserIDs());

foreach ($tags as $tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,16 +479,19 @@ public function createValidationFailsDataProvider(): array
'amount' => 'false',
'title' => false,
'description' => false,
], ['type', 'amount', 'title', 'description']],
'dateTime' => 123,
], ['type', 'amount', 'title', 'description', 'dateTime']],
[[
'type' => '+',
'amount' => 0,
'title' => 'Title',
], ['amount']],
'dateTime' => '123'
], ['amount', 'dateTime']],
[[
'type' => '+',
'amount' => -1,
'title' => 'Title',
'dateTime' => (new \DateTimeImmutable())->add(\DateInterval::createFromDateString('1 minute'))->format(CreateRequest::DATE_FORMAT),
], ['amount']],
];
}
Expand Down Expand Up @@ -531,6 +534,7 @@ public function testCreateStoreCharge(): void
'amount' => $charge->amount,
'title' => $charge->title,
'description' => $charge->description,
'dateTime' => $charge->createdAt->format(CreateRequest::DATE_FORMAT),
]);

$response->assertOk();
Expand All @@ -541,6 +545,7 @@ public function testCreateStoreCharge(): void
$this->assertArrayContains($charge->type, $body, 'data.operation');
$this->assertArrayContains($charge->amount, $body, 'data.amount');
$this->assertArrayContains($charge->description, $body, 'data.description');
$this->assertArrayContains($charge->createdAt->format(DATE_W3C), $body, 'data.dateTime');

$this->assertDatabaseHas('charges', [
'title' => $charge->title,
Expand Down

0 comments on commit 507f38c

Please sign in to comment.