Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: Filter correct products for store in ListProductsCommand #99

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Console/ListProductsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected function handleProducts(array $store): int
'products',
[
'include' => 'variants',
'filter[store_id]' => config('lemon-squeezy.store_id'),
'filter[store_id]' => config('lemon-squeezy.store'),
'page[size]' => 100,
]
),
Expand Down
42 changes: 42 additions & 0 deletions tests/Feature/Commands/ListProductsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@
],
],
]),
LemonSqueezy::API.'/stores/other' => Http::response([
'data' => [
'id' => 'other',
'attributes' => [
'name' => 'Other Fake Store',
'currency' => 'EUR',
],
],
]),
LemonSqueezy::API.'/products/fake?*' => Http::response([
'data' => [
'id' => 'fake',
Expand Down Expand Up @@ -44,6 +53,7 @@
[
'id' => '1',
'attributes' => [
'store_id' => 'fake',
'name' => 'Pro',
],
'relationships' => [
Expand All @@ -57,6 +67,7 @@
[
'id' => '2',
'attributes' => [
'store_id' => 'fake',
'name' => 'Test',
],
'relationships' => [
Expand All @@ -68,6 +79,20 @@
],
],
],
[
'id' => '3',
'attributes' => [
'store_id' => 'other',
'name' => 'Pro From Other',
],
'relationships' => [
'variants' => [
'data' => [
['id' => '789'],
],
],
],
],
],
'included' => [
[
Expand All @@ -94,6 +119,14 @@
'price' => 939,
],
],
[
'id' => '789',
'type' => 'variants',
'attributes' => [
'name' => 'Default',
'price' => 999,
],
],
],
]),
]);
Expand Down Expand Up @@ -134,3 +167,12 @@
$this->artisan('lmsqueezy:products')
->expectsOutputToContain('Lemon Squeezy store ID not set. You can add it to your .env file as LEMON_SQUEEZY_STORE.');
});

it('returns correct products based on the store id', function () {
config()->set('lemon-squeezy.store', 'other');

$this->artisan('lmsqueezy:products')
->doesntExpectOutput('Pro')
->expectsOutputToContain('Pro From Other');
// ->expectsOutputToContain('Lemon Squeezy store ID not set. You can add it to your .env file as LEMON_SQUEEZY_STORE.');
});
Loading