Skip to content

Commit 6ab5a8d

Browse files
committed
Add test
1 parent 73c05a2 commit 6ab5a8d

File tree

1 file changed

+119
-0
lines changed

1 file changed

+119
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
use DoubleThreeDigital\SimpleCommerce\UpdateScripts\v6_0\MigrateProductType;
4+
use Statamic\Facades\Blueprint;
5+
use Statamic\Facades\Collection;
6+
use Statamic\Facades\Entry;
7+
8+
it('updates product_type field for physical product', function () {
9+
$productEntry = Entry::make()
10+
->collection('products')
11+
->id('test')
12+
->data(['price' => 1234]);
13+
14+
$productEntry->save();
15+
16+
(new MigrateProductType('doublethreedigital/simple-commerce', '6.0.0'))->update();
17+
18+
$productEntry->fresh();
19+
20+
expect($productEntry->get('product_type'))->toBe('physical');
21+
});
22+
23+
it('updates product_type field for digital product', function () {
24+
$productEntry = Entry::make()
25+
->collection('products')
26+
->id('test')
27+
->data(['is_digital_product' => true, 'price' => 1234]);
28+
29+
$productEntry->save();
30+
31+
(new MigrateProductType('doublethreedigital/simple-commerce', '6.0.0'))->update();
32+
33+
$productEntry->fresh();
34+
35+
expect($productEntry->get('product_type'))->toBe('digital');
36+
});
37+
38+
it('updates product_type field for digital product with variants', function () {
39+
$productEntry = Entry::make()
40+
->collection('products')
41+
->id('test')
42+
->data([
43+
'product_variants' => [
44+
'variants' => [
45+
['name' => 'Colours', 'values' => ['Red']],
46+
['name' => 'Sizes', 'values' => ['Small']],
47+
],
48+
'options' => [
49+
['key' => 'Red_Small', 'variant' => 'Red Small', 'price' => 1200, 'is_digital_product' => true],
50+
],
51+
],
52+
]);
53+
54+
$productEntry->save();
55+
56+
(new MigrateProductType('doublethreedigital/simple-commerce', '6.0.0'))->update();
57+
58+
$productEntry->fresh();
59+
60+
expect($productEntry->get('product_type'))->toBe('digital');
61+
});
62+
63+
it('adds product type field and removes old digital product fields from product blueprints', function () {
64+
$collection = Collection::find('products');
65+
66+
$blueprint = $collection->entryBlueprint()->setContents([
67+
'fields' => [
68+
['handle' => 'is_digital_product', 'field' => ['type' => 'toggle']],
69+
['handle' => 'downloadable_asset', 'field' => ['type' => 'assets']],
70+
['handle' => 'download_limit', 'field' => ['type' => 'integer']],
71+
],
72+
]);
73+
74+
(new MigrateProductType('doublethreedigital/simple-commerce', '6.0.0'))->update();
75+
76+
$blueprint = $collection->entryBlueprint();
77+
78+
expect($blueprint->fields()->all()->map->handle()->toArray())
79+
->toHaveKey('product_type')
80+
->not->toHaveKey('is_digital_product')
81+
->toHaveKey('downloadable_asset')
82+
->toHaveKey('download_limit');
83+
});
84+
85+
it('adds product type field and removes old digital product fields from variant options field from product blueprints', function () {
86+
$collection = Collection::find('products');
87+
88+
$blueprint = $collection->entryBlueprint()->setContents([
89+
'fields' => [
90+
[
91+
'handle' => 'product_variants',
92+
'field' => [
93+
'type' => 'product_variants',
94+
'option_fields' => [
95+
['handle' => 'is_digital_product', 'field' => ['type' => 'toggle']],
96+
['handle' => 'downloadable_asset', 'field' => ['type' => 'assets']],
97+
['handle' => 'download_limit', 'field' => ['type' => 'integer']],
98+
],
99+
],
100+
],
101+
],
102+
]);
103+
104+
(new MigrateProductType('doublethreedigital/simple-commerce', '6.0.0'))->update();
105+
106+
$blueprint = $collection->entryBlueprint();
107+
108+
expect($blueprint->fields()->all()->map->handle()->toArray())
109+
->toHaveKey('product_type')
110+
->not->toHaveKey('is_digital_product')
111+
->not->toHaveKey('downloadable_asset')
112+
->not->toHaveKey('download_limit')
113+
->toHaveKey('product_variants');
114+
115+
expect($blueprint->field('product_variants')->config()['option_fields'])
116+
->not->toHaveKey('is_digital_product')
117+
->not->toHaveKey('downloadable_asset')
118+
->not->toHaveKey('download_limit');
119+
});

0 commit comments

Comments
 (0)