|
3 | 3 | namespace Grayloon\MagentoStorage\Tests\Jobs;
|
4 | 4 |
|
5 | 5 | use Grayloon\MagentoStorage\Database\Factories\MagentoCategoryFactory;
|
| 6 | +use Grayloon\MagentoStorage\Database\Factories\MagentoProductCategoryFactory; |
6 | 7 | use Grayloon\MagentoStorage\Database\Factories\MagentoProductFactory;
|
7 | 8 | use Grayloon\MagentoStorage\Jobs\SyncMagentoProductCategories;
|
8 | 9 | use Grayloon\MagentoStorage\Models\MagentoProductCategory;
|
@@ -45,4 +46,30 @@ public function test_can_sync_magento_product_categories_handles_empty_response(
|
45 | 46 |
|
46 | 47 | $this->assertEquals(0, MagentoProductCategory::count());
|
47 | 48 | }
|
| 49 | + |
| 50 | + /** @test */ |
| 51 | + public function it_removes_out_of_sync_categories() |
| 52 | + { |
| 53 | + config(['magento.store_code' => 'foo']); |
| 54 | + $category = MagentoCategoryFactory::new()->create(); |
| 55 | + $oldProductLink = MagentoProductCategoryFactory::new()->create([ |
| 56 | + 'magento_category_id' => $category->id, |
| 57 | + ]); |
| 58 | + $otherCategoryLink = MagentoProductCategoryFactory::new()->create(); |
| 59 | + $product = MagentoProductFactory::new()->create(); |
| 60 | + Http::fake([ |
| 61 | + '*rest/foo/V1/categories/'.$category->id.'/products' => Http::response([ |
| 62 | + [ |
| 63 | + 'sku' => $product->sku, |
| 64 | + 'category_id' => $category->id, |
| 65 | + 'position' => 1, |
| 66 | + ], |
| 67 | + ], 200), |
| 68 | + ]); |
| 69 | + |
| 70 | + (new SyncMagentoProductCategories($category->id))->handle(); |
| 71 | + |
| 72 | + $this->assertEquals(2, MagentoProductCategory::count()); |
| 73 | + $this->assertDeleted($oldProductLink); |
| 74 | + } |
48 | 75 | }
|
0 commit comments