Skip to content

Commit e61f1d6

Browse files
Alibaghaeealifreekmurze
authored
Fix: emit backFields for StoreCard and Coupon passes (#20)
* Fix: emit backFields for StoreCard and Coupon passes * Also emit backFields for Generic passes and add tests GenericPassBuilder had the same bug as StoreCard and Coupon. Added focused regression tests for all three builders. --------- Co-authored-by: ali <you@example.com> Co-authored-by: Freek Van der Herten <freek@spatie.be>
1 parent cdfb8d1 commit e61f1d6

6 files changed

Lines changed: 78 additions & 0 deletions

File tree

src/Builders/Apple/CouponPassBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected function compileData(): array
2525
'secondaryFields' => $this->secondaryFields?->values()->toArray(),
2626
'headerFields' => $this->headerFields?->values()->toArray(),
2727
'auxiliaryFields' => $this->auxiliaryFields?->values()->toArray(),
28+
'backFields' => $this->backFields?->values()->toArray(),
2829
]),
2930
],
3031
);

src/Builders/Apple/GenericPassBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected function compileData(): array
2525
'secondaryFields' => $this->secondaryFields?->values()->toArray(),
2626
'headerFields' => $this->headerFields?->values()->toArray(),
2727
'auxiliaryFields' => $this->auxiliaryFields?->values()->toArray(),
28+
'backFields' => $this->backFields?->values()->toArray(),
2829
]),
2930
],
3031
);

src/Builders/Apple/StoreCardPassBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ protected function compileData(): array
2525
'secondaryFields' => $this->secondaryFields?->values()->toArray(),
2626
'headerFields' => $this->headerFields?->values()->toArray(),
2727
'auxiliaryFields' => $this->auxiliaryFields?->values()->toArray(),
28+
'backFields' => $this->backFields?->values()->toArray(),
2829
]),
2930
],
3031
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Spatie\LaravelMobilePass\Builders\Apple\CouponPassBuilder;
4+
5+
it('compiles back fields into the coupon payload', function () {
6+
$compiledData = CouponPassBuilder::make()
7+
->setOrganizationName('My organization')
8+
->setSerialNumber(123456)
9+
->setDescription('Hello!')
10+
->addBackField('terms', 'Terms and conditions apply.')
11+
->setIconImage(getTestSupportPath('images/spatie-thumbnail.png'))
12+
->data();
13+
14+
expect($compiledData)->toHaveKey('coupon');
15+
expect($compiledData['coupon'])->toHaveKey('backFields');
16+
expect($compiledData['coupon']['backFields'])->toHaveCount(1);
17+
expect($compiledData['coupon']['backFields'][0])->toMatchArray([
18+
'key' => 'terms',
19+
'value' => 'Terms and conditions apply.',
20+
]);
21+
});
22+
23+
it('has a name', function () {
24+
expect(CouponPassBuilder::name())->toBe('coupon');
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Spatie\LaravelMobilePass\Builders\Apple\GenericPassBuilder;
4+
5+
it('compiles back fields into the generic payload', function () {
6+
$compiledData = GenericPassBuilder::make()
7+
->setOrganizationName('My organization')
8+
->setSerialNumber(123456)
9+
->setDescription('Hello!')
10+
->addBackField('terms', 'Terms and conditions apply.')
11+
->setIconImage(getTestSupportPath('images/spatie-thumbnail.png'))
12+
->data();
13+
14+
expect($compiledData)->toHaveKey('generic');
15+
expect($compiledData['generic'])->toHaveKey('backFields');
16+
expect($compiledData['generic']['backFields'])->toHaveCount(1);
17+
expect($compiledData['generic']['backFields'][0])->toMatchArray([
18+
'key' => 'terms',
19+
'value' => 'Terms and conditions apply.',
20+
]);
21+
});
22+
23+
it('has a name', function () {
24+
expect(GenericPassBuilder::name())->toBe('generic');
25+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Spatie\LaravelMobilePass\Builders\Apple\StoreCardPassBuilder;
4+
5+
it('compiles back fields into the store card payload', function () {
6+
$compiledData = StoreCardPassBuilder::make()
7+
->setOrganizationName('My organization')
8+
->setSerialNumber(123456)
9+
->setDescription('Hello!')
10+
->addBackField('terms', 'Terms and conditions apply.')
11+
->setIconImage(getTestSupportPath('images/spatie-thumbnail.png'))
12+
->data();
13+
14+
expect($compiledData)->toHaveKey('storeCard');
15+
expect($compiledData['storeCard'])->toHaveKey('backFields');
16+
expect($compiledData['storeCard']['backFields'])->toHaveCount(1);
17+
expect($compiledData['storeCard']['backFields'][0])->toMatchArray([
18+
'key' => 'terms',
19+
'value' => 'Terms and conditions apply.',
20+
]);
21+
});
22+
23+
it('has a name', function () {
24+
expect(StoreCardPassBuilder::name())->toBe('store_card');
25+
});

0 commit comments

Comments
 (0)