Skip to content

Commit

Permalink
Merge pull request #822 from bavix/819-need-this-for-multi-tenancy-teams
Browse files Browse the repository at this point in the history
[10.x] add getDynamicDefaultSlug
  • Loading branch information
rez1dent3 authored Dec 28, 2023
2 parents de6d893 + ed81f3f commit a8d79a3
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 13 deletions.
68 changes: 56 additions & 12 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [10.1.0] - 2023-12-28
### Bump
* build(deps-dev): update laravel/cashier requirement from ^14.12 to ^15.0 by @dependabot in https://github.com/bavix/laravel-wallet/pull/817
* build(deps): bump axios from 1.6.2 to 1.6.3 by @dependabot in https://github.com/bavix/laravel-wallet/pull/821

### Added
* add wallet getDynamicDefaultSlug by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/822

## [10.0.2] - 2023-12-14
### Bump
* Bump bavix/.github from 0.0.5 to 0.0.7 by @dependabot in https://github.com/bavix/laravel-wallet/pull/784
* docs: accessing float amount by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/786
* docs: changing wallet decimal_places by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/785
* remove driftingly/rector-laravel by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/787
* Bump postcss from 8.4.19 to 8.4.31 by @dependabot in https://github.com/bavix/laravel-wallet/pull/788
* Bump webpack from 5.88.2 to 5.89.0 by @dependabot in https://github.com/bavix/laravel-wallet/pull/790
* Bump size-limit from 9.0.0 to 10.0.1 by @dependabot in https://github.com/bavix/laravel-wallet/pull/792
* Bump bavix/.github from 0.0.7 to 0.0.8 by @dependabot in https://github.com/bavix/laravel-wallet/pull/793
* Bump axios from 1.5.1 to 1.6.0 by @dependabot in https://github.com/bavix/laravel-wallet/pull/795
* Bump size-limit from 10.0.1 to 10.0.2 by @dependabot in https://github.com/bavix/laravel-wallet/pull/797
* build(deps): bump actions/checkout from 3 to 4 by @dependabot in https://github.com/bavix/laravel-wallet/pull/799
* build(deps): bump axios from 1.6.0 to 1.6.1 by @dependabot in https://github.com/bavix/laravel-wallet/pull/801
* build(deps): bump size-limit from 10.0.2 to 11.0.0 by @dependabot in https://github.com/bavix/laravel-wallet/pull/802
* build(deps): bump axios from 1.6.1 to 1.6.2 by @dependabot in https://github.com/bavix/laravel-wallet/pull/803
* build(deps): bump bavix/.github from 0.0.8 to 0.0.9 by @dependabot in https://github.com/bavix/laravel-wallet/pull/808
* build(deps): bump size-limit from 11.0.0 to 11.0.1 by @dependabot in https://github.com/bavix/laravel-wallet/pull/810
* build(deps): bump actions/stale from 8 to 9 by @dependabot in https://github.com/bavix/laravel-wallet/pull/811
* build(deps): bump bavix/.github from 0.0.9 to 0.1.0 by @dependabot in https://github.com/bavix/laravel-wallet/pull/812
* build(deps): bump JetBrains/qodana-action from 2023.2 to 2023.3 by @dependabot in https://github.com/bavix/laravel-wallet/pull/813

### Removed
* remove cozyhouse by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/794

### Added
* add support database cache by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/815
* Qodana by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/798
* add support php 8.3 by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/796

## [10.0.1] - 2023-09-30
### Bump
* Bump semver from 7.3.8 to 7.5.4 by @dependabot in https://github.com/bavix/laravel-wallet/pull/726
Expand All @@ -15,11 +53,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Updated laravel rector set by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/733
* Update driftingly/rector-laravel requirement from ^0.21 to ^0.22 by @dependabot in https://github.com/bavix/laravel-wallet/pull/735
* Create npm workflow by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/736
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/737
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/739
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/740
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/741
* Lumen documentation update by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/743
* [Snyk] Upgrade webpack-cli from 5.0.0 to 5.1.4 by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/747
* [Snyk] Upgrade axios from 1.3.4 to 1.4.0 by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/748
* [Snyk] Upgrade size-limit from 8.2.4 to 8.2.6 by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/750
Expand All @@ -31,18 +64,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Bump size-limit from 8.2.6 to 9.0.0 by @dependabot in https://github.com/bavix/laravel-wallet/pull/762
* Bump actions/stale from 6 to 8 by @dependabot in https://github.com/bavix/laravel-wallet/pull/761
* Bump actions/checkout from 3 to 4 by @dependabot in https://github.com/bavix/laravel-wallet/pull/760
* docs: update wording to sound grammatically correct by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/766
* docs: customize name and slug of default wallet by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/765
* docs: fixed grammatical error by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/764
* Bump uuid from 9.0.0 to 9.0.1 by @dependabot in https://github.com/bavix/laravel-wallet/pull/768
* checking the Wallet class extensibility by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/769
* Update driftingly/rector-laravel requirement from ^0.24 to ^0.25 by @dependabot in https://github.com/bavix/laravel-wallet/pull/779
* Update driftingly/rector-laravel requirement from ^0.25 to ^0.26 by @dependabot in https://github.com/bavix/laravel-wallet/pull/780
* Bump axios from 1.5.0 to 1.5.1 by @dependabot in https://github.com/bavix/laravel-wallet/pull/781

### Docs
* docs: Create configuration.md by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/771
* docs: add configuration file to sidebar by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/772
* docs: move configuration details to separate file by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/773
* docs: update for clarity by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/774
* Update driftingly/rector-laravel requirement from ^0.24 to ^0.25 by @dependabot in https://github.com/bavix/laravel-wallet/pull/779
* Update driftingly/rector-laravel requirement from ^0.25 to ^0.26 by @dependabot in https://github.com/bavix/laravel-wallet/pull/780
* Bump axios from 1.5.0 to 1.5.1 by @dependabot in https://github.com/bavix/laravel-wallet/pull/781
* docs: update wording to sound grammatically correct by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/766
* docs: customize name and slug of default wallet by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/765
* docs: fixed grammatical error by @justinkekeocha in https://github.com/bavix/laravel-wallet/pull/764
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/737
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/739
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/740
* Update docs.yaml by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/741
* Lumen documentation update by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/743

### Added
* Add semgrep by @rez1dent3 in https://github.com/bavix/laravel-wallet/pull/783

## [10.0.0] - 2023-07-08
Expand Down Expand Up @@ -1047,7 +1089,9 @@ The operation is now executed in the transaction and updates the new `refund` fi
- Exceptions: AmountInvalid, BalanceIsEmpty.
- Models: Transfer, Transaction.

[Unreleased]: https://github.com/bavix/laravel-wallet/compare/10.0.1...develop
[Unreleased]: https://github.com/bavix/laravel-wallet/compare/10.1.0...develop
[10.1.0]: https://github.com/bavix/laravel-wallet/compare/10.0.2...10.1.0
[10.0.2]: https://github.com/bavix/laravel-wallet/compare/10.0.1...10.0.2
[10.0.1]: https://github.com/bavix/laravel-wallet/compare/10.0.0...10.0.1
[10.0.0]: https://github.com/bavix/laravel-wallet/compare/9.6.2...10.0.0
[9.6.2]: https://github.com/bavix/laravel-wallet/compare/9.6.1...9.6.2
Expand Down
7 changes: 6 additions & 1 deletion src/Traits/MorphOneWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ public function wallet(): MorphOne
->where('slug', config('wallet.wallet.default.slug', 'default'))

Check warning on line 34 in src/Traits/MorphOneWallet.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'config'
->withDefault(static function (WalletModel $wallet, object $holder) use ($castService) {
$model = $castService->getModel($holder);

$slug = method_exists($model, 'getDynamicDefaultSlug')
? $model->getDynamicDefaultSlug()
: config('wallet.wallet.default.slug', 'default');

Check warning on line 40 in src/Traits/MorphOneWallet.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'config'

$wallet->forceFill(array_merge(config('wallet.wallet.creating', []), [

Check warning on line 42 in src/Traits/MorphOneWallet.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'config'

Check warning on line 42 in src/Traits/MorphOneWallet.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined method

Method 'forceFill' is undefined
'name' => config('wallet.wallet.default.name', 'Default Wallet'),

Check warning on line 43 in src/Traits/MorphOneWallet.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'config'
'slug' => config('wallet.wallet.default.slug', 'default'),
'slug' => $slug,
'meta' => config('wallet.wallet.default.meta', []),

Check warning on line 45 in src/Traits/MorphOneWallet.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Undefined function

Undefined function 'config'
'balance' => 0,
]));
Expand Down
27 changes: 27 additions & 0 deletions tests/Infra/Factories/UserDynamicFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\Test\Infra\Factories;

use Bavix\Wallet\Test\Infra\Models\UserDynamic;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends Factory<UserDynamic>
*/
final class UserDynamicFactory extends Factory
{
protected $model = UserDynamic::class;

public function definition(): array
{
return [
'name' => fake()
->name,
'email' => fake()
->unique()
->safeEmail,
];
}
}
35 changes: 35 additions & 0 deletions tests/Infra/Models/UserDynamic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Bavix\Wallet\Test\Infra\Models;

use Bavix\Wallet\Interfaces\Wallet;
use Bavix\Wallet\Traits\HasWallet;
use Illuminate\Database\Eloquent\Model;

/**
* @property string $name
* @property string $email
*
* @method int getKey()
*/
final class UserDynamic extends Model implements Wallet
{
use HasWallet;

/**
* @var string[]
*/
protected $fillable = ['name', 'email'];

public function getTable(): string
{
return 'users';
}

public function getDynamicDefaultSlug(): string
{
return 'default-' . $this->email;
}
}
34 changes: 34 additions & 0 deletions tests/Units/Domain/WalletTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
use Bavix\Wallet\Internal\Service\DatabaseServiceInterface;
use Bavix\Wallet\Models\Transaction;
use Bavix\Wallet\Services\RegulatorServiceInterface;
use Bavix\Wallet\Test\Infra\Factories\UserDynamicFactory;
use Bavix\Wallet\Test\Infra\Factories\UserFactory;
use Bavix\Wallet\Test\Infra\Models\User;
use Bavix\Wallet\Test\Infra\Models\UserDynamic;
use Bavix\Wallet\Test\Infra\PackageModels\Wallet;
use Bavix\Wallet\Test\Infra\TestCase;
use Illuminate\Database\Eloquent\Collection;
use RuntimeException;
Expand Down Expand Up @@ -280,6 +283,37 @@ public function testRecalculate(): void
self::assertSame(0, $user->balanceInt);
}

public function testDefaultWalletCustomize(): void
{
/** @var User $user */
$user = UserFactory::new()->create();

self::assertFalse($user->wallet->exists);

$user->wallet->meta = [
'internal' => 1,
];

self::assertNotNull($user->deposit(100));
self::assertSame(100, $user->balanceInt);

$wallet = Wallet::query()->find($user->wallet->getKey());

self::assertNotNull($wallet);
self::assertSame(1, $wallet->meta['internal'] ?? 0);
}

public function testgetDynamicDefaultSlug(): void
{
/** @var UserDynamic $user */
$user = UserDynamicFactory::new()->create();

self::assertNotNull($user->deposit(100));
self::assertSame(100, $user->balanceInt);

self::assertSame('default-' . $user->email, $user->wallet->slug);
}

public function testCrash(): void
{
/** @var User $user */
Expand Down

0 comments on commit a8d79a3

Please sign in to comment.