Skip to content

Commit b988acf

Browse files
add test core and attribute
1 parent de10335 commit b988acf

File tree

6 files changed

+340
-4
lines changed

6 files changed

+340
-4
lines changed

resources/js/pages/cms/core/currency-rate/Index.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import { CurrencyRateDataItem } from '@/types/cms/core';
1515
import { Head, router, usePage } from '@inertiajs/vue3';
1616
import { ModalLink } from '@inertiaui/modal-vue';
1717
import dayjs from 'dayjs';
18-
import { Pencil, Plus, Trash2 } from 'lucide-vue-next';
18+
import { Badge } from '@/components/ui/badge';
19+
1920
2021
defineProps<{
2122
data: PaginationItem<CurrencyRateDataItem>;
@@ -77,11 +78,13 @@ const breadcrumbItems: BreadcrumbItem[] = [
7778
</Button>
7879
</ModalLink>
7980
</div>
80-
<div class="space-y-1">
81-
<p class="text-lg font-semibold tracking-tight">
81+
<div class="flex items-center gap-2">
82+
<span class="text-sm font-medium text-muted-foreground">
8283
Default Currency:
84+
</span>
85+
<Badge variant="secondary" class="text-sm">
8386
{{ page.props.defaultCurrency.code }}
84-
</p>
87+
</Badge>
8588
</div>
8689
<ResourceTable
8790
:data="data"
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
3+
use App\Actions\Cms\Attribute\Attribute\DeleteAttributeAction;
4+
use App\Actions\Cms\Attribute\Attribute\StoreAttributeAction;
5+
use App\Actions\Cms\Attribute\Attribute\UpdateAttributeAction;
6+
use App\Models\Attribute\Attribute;
7+
use App\Models\Attribute\AttributeFamily;
8+
use Illuminate\Foundation\Testing\RefreshDatabase;
9+
use Tests\TestCase;
10+
11+
uses(TestCase::class, RefreshDatabase::class);
12+
13+
test('store attribute action creates an attribute with translations and options', function () {
14+
$family = AttributeFamily::create(['code' => 'fam', 'name' => 'Fam', 'status' => true]);
15+
$action = new StoreAttributeAction;
16+
$data = [
17+
'attribute_family_id' => $family->id,
18+
'code' => 'color',
19+
'name' => 'Color', // Added name
20+
'type' => 'select',
21+
'is_required' => true,
22+
'is_unique' => false,
23+
'validation' => 'required',
24+
'translations' => [
25+
'en' => ['name' => 'Color'],
26+
'id' => ['name' => 'Warna'],
27+
],
28+
'options' => [
29+
[
30+
'name' => 'Red',
31+
'order' => 1,
32+
'status' => true,
33+
'translations' => [
34+
'en' => ['name' => 'Red'],
35+
'id' => ['name' => 'Merah'],
36+
]
37+
]
38+
]
39+
];
40+
41+
$attribute = $action->handle($data);
42+
43+
expect($attribute)->toBeInstanceOf(Attribute::class);
44+
$this->assertDatabaseHas('attributes', ['code' => 'color']);
45+
$this->assertDatabaseHas('attribute_translations', ['attribute_id' => $attribute->id, 'locale' => 'en', 'name' => 'Color']);
46+
$this->assertDatabaseHas('attribute_options', ['attribute_id' => $attribute->id, 'name' => 'Red']);
47+
});
48+
49+
50+
test('update attribute action updates an attribute with translations', function () {
51+
$family = AttributeFamily::create(['code' => 'fam', 'name' => 'Fam', 'status' => true]);
52+
$actionStore = new StoreAttributeAction;
53+
$dataStore = [
54+
'attribute_family_id' => $family->id,
55+
'code' => 'color',
56+
'name' => 'Color', // Added name
57+
'type' => 'select',
58+
'is_required' => true,
59+
'is_unique' => false,
60+
'validation' => 'required',
61+
'translations' => [
62+
'en' => ['name' => 'Color'],
63+
],
64+
'options' => []
65+
];
66+
$attribute = $actionStore->handle($dataStore);
67+
68+
$action = new UpdateAttributeAction;
69+
$data = [
70+
'attribute_family_id' => $family->id,
71+
'code' => 'colour',
72+
'name' => 'Colour', // Added name
73+
'type' => 'select',
74+
'is_required' => false, // changed
75+
'translations' => [
76+
'en' => ['name' => 'Colour'], // changed
77+
],
78+
'options' => []
79+
];
80+
81+
$result = $action->handle($attribute, $data);
82+
83+
expect($result)->toBeTrue();
84+
$this->assertDatabaseHas('attributes', ['id' => $attribute->id, 'code' => 'colour']);
85+
$this->assertDatabaseHas('attribute_translations', ['attribute_id' => $attribute->id, 'locale' => 'en', 'name' => 'Colour']);
86+
});
87+
88+
test('delete attribute action deletes an attribute', function () {
89+
$family = AttributeFamily::create(['code' => 'fam', 'name' => 'Fam', 'status' => true]);
90+
$attribute = Attribute::create([
91+
'attribute_family_id' => $family->id,
92+
'code' => 'del',
93+
'name' => 'Delete Me',
94+
// 'order' and 'status' might have defaults or be nullable, but good to set if not sure.
95+
// Assuming strict types, let's provide basic fields if needed,
96+
// but factory would have handled this. Looking at model: code, name, order, status.
97+
'order' => 1,
98+
'status' => true,
99+
]);
100+
$action = new DeleteAttributeAction;
101+
102+
$result = $action->handle($attribute);
103+
104+
expect($result)->toBeTrue();
105+
$this->assertDatabaseMissing('attributes', ['id' => $attribute->id]);
106+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use App\Actions\Cms\Attribute\AttributeFamily\DeleteAttributeFamilyAction;
4+
use App\Actions\Cms\Attribute\AttributeFamily\StoreAttributeFamilyAction;
5+
use App\Actions\Cms\Attribute\AttributeFamily\UpdateAttributeFamilyAction;
6+
use App\Models\Attribute\AttributeFamily;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Tests\TestCase;
9+
10+
uses(TestCase::class, RefreshDatabase::class);
11+
12+
test('store attribute family action creates an attribute family', function () {
13+
$action = new StoreAttributeFamilyAction;
14+
$data = [
15+
'code' => 'clothing',
16+
'name' => 'Clothing',
17+
];
18+
19+
$family = $action->handle($data);
20+
21+
expect($family)->toBeInstanceOf(AttributeFamily::class);
22+
$this->assertDatabaseHas('attribute_families', $data);
23+
});
24+
25+
test('update attribute family action updates an attribute family', function () {
26+
$family = AttributeFamily::create([
27+
'code' => 'old',
28+
'name' => 'Old Name',
29+
'status' => true,
30+
]);
31+
$action = new UpdateAttributeFamilyAction;
32+
$data = [
33+
'code' => 'new',
34+
'name' => 'New Name',
35+
];
36+
37+
$result = $action->handle($family, $data);
38+
39+
expect($result)->toBeTrue();
40+
$this->assertDatabaseHas('attribute_families', ['id' => $family->id, 'code' => 'new']);
41+
});
42+
43+
test('delete attribute family action deletes an attribute family', function () {
44+
$family = AttributeFamily::create([
45+
'code' => 'del',
46+
'name' => 'Delete Me',
47+
'status' => true,
48+
]);
49+
$action = new DeleteAttributeFamilyAction;
50+
51+
$result = $action->handle($family);
52+
53+
expect($result)->toBeTrue();
54+
$this->assertDatabaseMissing('attribute_families', ['id' => $family->id]);
55+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
use App\Actions\Cms\Core\Currency\DeleteCurrencyAction;
4+
use App\Actions\Cms\Core\Currency\StoreCurrencyAction;
5+
use App\Actions\Cms\Core\Currency\UpdateCurrencyAction;
6+
use App\Models\Core\Currency;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Tests\TestCase;
9+
10+
uses(TestCase::class, RefreshDatabase::class);
11+
12+
test('store currency action creates a currency', function () {
13+
$action = new StoreCurrencyAction;
14+
$data = [
15+
'code' => 'USD',
16+
'name' => 'US Dollar',
17+
];
18+
19+
$currency = $action->handle($data);
20+
21+
expect($currency)->toBeInstanceOf(Currency::class);
22+
$this->assertDatabaseHas('currencies', $data);
23+
});
24+
25+
test('update currency action updates a currency', function () {
26+
$currency = Currency::create([
27+
'code' => 'OLD',
28+
'name' => 'Old Name',
29+
'is_default' => false,
30+
]);
31+
$action = new UpdateCurrencyAction;
32+
$data = [
33+
'code' => 'NEW',
34+
'name' => 'New Name',
35+
];
36+
37+
$result = $action->handle($currency, $data);
38+
39+
expect($result)->toBeTrue();
40+
$this->assertDatabaseHas('currencies', ['id' => $currency->id, 'code' => 'NEW']);
41+
});
42+
43+
test('delete currency action deletes a currency', function () {
44+
$currency = Currency::create([
45+
'code' => 'DEL',
46+
'name' => 'Delete Me',
47+
'is_default' => false,
48+
]);
49+
$action = new DeleteCurrencyAction;
50+
51+
$result = $action->handle($currency);
52+
53+
expect($result)->toBeTrue();
54+
$this->assertDatabaseMissing('currencies', ['id' => $currency->id]);
55+
});
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
use App\Actions\Cms\Core\CurrencyRate\DeleteCurrencyRateAction;
4+
use App\Actions\Cms\Core\CurrencyRate\StoreCurrencyRateAction;
5+
use App\Actions\Cms\Core\CurrencyRate\UpdateCurrencyRateAction;
6+
use App\Models\Core\Currency;
7+
use App\Models\Core\CurrencyRate;
8+
use Illuminate\Foundation\Testing\RefreshDatabase;
9+
use Tests\TestCase;
10+
11+
uses(TestCase::class, RefreshDatabase::class);
12+
13+
test('store currency rate action creates a currency rate', function () {
14+
$targetCurrency = Currency::create(['code' => 'USD', 'name' => 'US Dollar', 'is_default' => false]);
15+
$action = new StoreCurrencyRateAction;
16+
$data = [
17+
'target_currency_id' => $targetCurrency->id,
18+
'rate' => 1.5,
19+
];
20+
21+
$currencyRate = $action->handle($data);
22+
23+
expect($currencyRate)->toBeInstanceOf(CurrencyRate::class);
24+
$this->assertDatabaseHas('currency_rates', $data);
25+
});
26+
27+
test('update currency rate action updates a currency rate', function () {
28+
$targetCurrency = Currency::create(['code' => 'USD', 'name' => 'US Dollar', 'is_default' => false]);
29+
$currencyRate = CurrencyRate::create([
30+
'target_currency_id' => $targetCurrency->id,
31+
'rate' => 1.0,
32+
]);
33+
34+
$action = new UpdateCurrencyRateAction;
35+
$data = [
36+
'target_currency_id' => $targetCurrency->id,
37+
'rate' => 2.0,
38+
];
39+
40+
$result = $action->handle($currencyRate, $data);
41+
42+
expect($result)->toBeTrue();
43+
$this->assertDatabaseHas('currency_rates', ['id' => $currencyRate->id, 'rate' => 2.0]);
44+
});
45+
46+
test('delete currency rate action deletes a currency rate', function () {
47+
$targetCurrency = Currency::create(['code' => 'USD', 'name' => 'US Dollar', 'is_default' => false]);
48+
$currencyRate = CurrencyRate::create([
49+
'target_currency_id' => $targetCurrency->id,
50+
'rate' => 1.0,
51+
]);
52+
$action = new DeleteCurrencyRateAction;
53+
54+
$result = $action->handle($currencyRate);
55+
56+
expect($result)->toBeTrue();
57+
$this->assertDatabaseMissing('currency_rates', ['id' => $currencyRate->id]);
58+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
use App\Actions\Cms\Core\Locale\DeleteLocaleAction;
4+
use App\Actions\Cms\Core\Locale\StoreLocaleAction;
5+
use App\Actions\Cms\Core\Locale\UpdateLocaleAction;
6+
use App\Models\Core\Locale;
7+
use Illuminate\Foundation\Testing\RefreshDatabase;
8+
use Tests\TestCase;
9+
10+
uses(TestCase::class, RefreshDatabase::class);
11+
12+
test('store locale action creates a locale', function () {
13+
$action = new StoreLocaleAction;
14+
$data = [
15+
'code' => 'en',
16+
'name' => 'English',
17+
'direction' => 'ltr',
18+
];
19+
20+
$locale = $action->handle($data);
21+
22+
expect($locale)->toBeInstanceOf(Locale::class);
23+
$this->assertDatabaseHas('locales', $data);
24+
});
25+
26+
test('update locale action updates a locale', function () {
27+
$locale = Locale::create([
28+
'code' => 'old',
29+
'name' => 'Old Name',
30+
'direction' => 'ltr',
31+
'is_default' => false,
32+
]);
33+
$action = new UpdateLocaleAction;
34+
$data = [
35+
'code' => 'new',
36+
'name' => 'New Name',
37+
'direction' => 'rtl',
38+
];
39+
40+
$result = $action->handle($locale, $data);
41+
42+
expect($result)->toBeTrue();
43+
$this->assertDatabaseHas('locales', ['id' => $locale->id, 'code' => 'new', 'direction' => 'rtl']);
44+
});
45+
46+
test('delete locale action deletes a locale', function () {
47+
$locale = Locale::create([
48+
'code' => 'del',
49+
'name' => 'Delete Me',
50+
'direction' => 'ltr',
51+
'is_default' => false,
52+
]);
53+
$action = new DeleteLocaleAction;
54+
55+
$result = $action->handle($locale);
56+
57+
expect($result)->toBeTrue();
58+
$this->assertDatabaseMissing('locales', ['id' => $locale->id]);
59+
});

0 commit comments

Comments
 (0)