public function testFinderCreateWorksWhenFinderIsAProductRequest() { Factory::create('Giftertipster\\Entity\\Eloquent\\ProductRequest', ['product_id' => null, 'user_id' => 1]); $suite_attributes = ['vendor' => 'amazon', 'vendor_id' => 'b000000', 'binding' => 'testbinding', 'brand' => 'testbrand', 'manufacturer' => 'test manufacturer', 'model' => 'test model', 'group' => 'test group', 'type' => 'test type', 'size' => 'testsize', 'clothing_size' => 'test clothing size', 'color' => 'testcolor', 'title' => 'test title', 'department' => 'test department', 'min_price_amount' => 4000, 'min_price_currency' => 'USD', 'min_price_formatted' => '$40.00', 'max_price_amount' => 4000, 'max_price_currency' => 'USD', 'max_price_formatted' => '$40.00', 'reviews_url' => 'reviewsurl.com', 'detail_url' => 'detailurl.com']; $suite_attributes['images'][] = ['category' => 'image1', 'swatch_url' => 'testurl.com', 'swatch_height' => '100', 'swatch_width' => '200', 'small_url' => 'testurl.com', 'small_height' => '100', 'small_width' => '200', 'thumb_url' => 'testurl.com', 'thumb_height' => '100', 'thumb_width' => '200', 'tiny_url' => 'testurl.com', 'tiny_height' => '100', 'tiny_width' => '200', 'medium_url' => 'testurl.com', 'medium_height' => '100', 'medium_width' => '200', 'large_url' => 'testurl.com', 'large_height' => '100', 'large_width' => '200']; $suite_attributes['images'][] = ['category' => 'image2', 'swatch_url' => 'testurl.com', 'swatch_height' => '100', 'swatch_width' => '200', 'small_url' => 'testurl.com', 'small_height' => '100', 'small_width' => '200', 'thumb_url' => 'testurl.com', 'thumb_height' => '100', 'thumb_width' => '200', 'tiny_url' => 'testurl.com', 'tiny_height' => '100', 'tiny_width' => '200', 'medium_url' => 'testurl.com', 'medium_height' => '100', 'medium_width' => '200', 'large_url' => 'testurl.com', 'large_height' => '100', 'large_width' => '200']; $suite_attributes['features'][] = ['description' => 'feature1']; $suite_attributes['features'][] = ['description' => 'feature2']; $suite_attributes['descriptions'][] = ['type' => 'description type', 'value' => 'description value 1']; $suite_attributes['descriptions'][] = ['type' => 'description type', 'value' => 'description value 2']; $suite_attributes['sub_products'][] = ['vendor' => 'amazon', 'vendor_id' => 'b000001', 'parent_vendor_id' => 'b000000', 'binding' => 'testbinding', 'brand' => 'testbrand', 'manufacturer' => 'test manufacturer', 'model' => 'test model', 'group' => 'test group', 'type' => 'test type', 'size' => 'testsize', 'clothing_size' => 'test clothing size', 'color' => 'testcolor', 'title' => 'test sub product', 'condition' => 'test condition', 'department' => 'test department', 'list_price_amount' => 4000, 'list_price_currency' => 'USD', 'list_price_formatted' => '$40.00', 'price_amount' => 4000, 'price_currency' => 'USD', 'price_formatted' => '$40.00', 'availability' => 'test avail', 'availability_type' => 'test avail type', 'availability_max_hours' => 'test avail max hours', 'availability_min_hours' => 'test avail min hours', 'availability_ship' => 'test avail ship', 'availability_ss_ship' => 1, 'offer_listing_id' => 'foo1']; $suite_attributes['sub_products'][0]['images'][] = ['category' => 'image1', 'swatch_url' => 'testurl.com', 'swatch_height' => '100', 'swatch_width' => '200', 'small_url' => 'testurl.com', 'small_height' => '100', 'small_width' => '200', 'thumb_url' => 'testurl.com', 'thumb_height' => '100', 'thumb_width' => '200', 'tiny_url' => 'testurl.com', 'tiny_height' => '100', 'tiny_width' => '200', 'medium_url' => 'testurl.com', 'medium_height' => '100', 'medium_width' => '200', 'large_url' => 'testurl.com', 'large_height' => '100', 'large_width' => '200']; $suite_attributes['sub_products'][0]['images'][] = ['category' => 'image2', 'swatch_url' => 'testurl.com', 'swatch_height' => '100', 'swatch_width' => '200', 'small_url' => 'testurl.com', 'small_height' => '100', 'small_width' => '200', 'thumb_url' => 'testurl.com', 'thumb_height' => '100', 'thumb_width' => '200', 'tiny_url' => 'testurl.com', 'tiny_height' => '100', 'tiny_width' => '200', 'medium_url' => 'testurl.com', 'medium_height' => '100', 'medium_width' => '200', 'large_url' => 'testurl.com', 'large_height' => '100', 'large_width' => '200']; $suite_attributes['sub_products'][0]['descriptions'][] = ['type' => 'type1', 'value' => 'value1']; $suite_attributes['sub_products'][0]['features'][] = ['description' => 'feature1']; $suite_attributes['sub_products'][0]['features'][] = ['description' => 'feature2']; $suite_attributes['sub_products'][0]['variations'][] = ['type' => 'variation type', 'value' => 'variation1']; $suite_attributes['sub_products'][0]['variations'][] = ['type' => 'variation type', 'value' => 'variation2']; $suite_attributes['keyword_profile']['profile'] = ['keyword1', 'keyword2']; $suite_attributes['category_keywords'] = ['category', 'keywords']; //mock prod suite validator (validates suite attributes keys) $suite_validator = \Mockery::mock('Giftertipster\\Service\\Validate\\ProductSuite\\ProductSuiteValidationInterface'); $suite_validator->shouldReceive('validateSuiteAttributesForCreate')->once()->with($suite_attributes)->andReturn(true); $this->app->instance('Giftertipster\\Service\\Validate\\ProductSuite\\ProductSuiteValidationInterface', $suite_validator); //mock prod suite images dup filter $filter = Mockery::mock('Giftertipster\\Service\\ProductSuite\\ProductSuiteImageDuplicationFilterInterface'); $filter->shouldReceive('filter')->once()->with($suite_attributes['images'])->andReturn($suite_attributes['images']); $filter->shouldReceive('filter')->once()->with($suite_attributes['sub_products'][0]['images'])->andReturn($suite_attributes['sub_products'][0]['images']); $this->app->instance('Giftertipster\\Service\\ProductSuite\\ProductSuiteImageDuplicationFilterInterface', $filter); //mock ProductSuiteIndexer $expected_product_suite = $suite_attributes; $expected_product_suite['is_refreshed'] = 1; $indexer = Mockery::mock('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface'); $indexer->shouldReceive('queueIndex')->with(Mockery::on(function ($product_suite) use($expected_product_suite) { if (!empty($this->arrayRecursiveDiff($expected_product_suite, $product_suite))) { return false; } return true; }), false, false)->once()->andReturn(true); $this->app->instance('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface', $indexer); $repo = $this->app->make('Giftertipster\\Repository\\ProductSuite\\EloquentProductSuiteRepository'); $response = $repo->finderCreate($suite_attributes, 'ProductRequest', 1, 2); assertThat($response, equalTo(true)); assertThat($response, anInstanceOf('Giftertipster\\Entity\\Eloquent\\Product')); $eloquent_product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product'); $eloquent_description = $this->app->make('Giftertipster\\Entity\\Eloquent\\Description'); $eloquent_sub_product = $this->app->make('Giftertipster\\Entity\\Eloquent\\SubProduct'); $eloquent_image = $this->app->make('Giftertipster\\Entity\\Eloquent\\Image'); $eloquent_feature = $this->app->make('Giftertipster\\Entity\\Eloquent\\Feature'); $eloquent_variation = $this->app->make('Giftertipster\\Entity\\Eloquent\\Variation'); $eloquent_keyword_profile = $this->app->make('Giftertipster\\Entity\\Eloquent\\KeywordProfile'); $product = $eloquent_product->with('productRequest')->find(1)->toArray(); $product_image = $eloquent_image->where('imageable_id', '=', 1)->where('imageable_type', '=', 'Giftertipster\\Entity\\Eloquent\\Product')->get()->toArray(); $product_feature = $eloquent_feature->where('featurable_id', '=', 1)->where('featurable_type', '=', 'Giftertipster\\Entity\\Eloquent\\Product')->get()->toArray(); $product_description = $eloquent_description->where('descriptionable_id', '=', 1)->where('descriptionable_type', '=', 'Giftertipster\\Entity\\Eloquent\\Product')->get()->toArray(); $sub_product = $eloquent_sub_product->get()->toArray(); $sub_product_image = $eloquent_image->where('imageable_id', '=', 1)->where('imageable_type', '=', 'Giftertipster\\Entity\\Eloquent\\SubProduct')->get()->toArray(); $sub_product_feature = $eloquent_feature->where('featurable_id', '=', 1)->where('featurable_type', '=', 'Giftertipster\\Entity\\Eloquent\\SubProduct')->get()->toArray(); $sub_product_description = $eloquent_description->where('descriptionable_id', '=', 1)->where('descriptionable_type', '=', 'Giftertipster\\Entity\\Eloquent\\SubProduct')->get()->toArray(); $sub_product_variation = $eloquent_variation->where('sub_product_id', '=', 1)->get()->toArray(); $product_keyword_profile = $eloquent_keyword_profile->where('product_id', '=', 1)->get()->toArray(); assertThat($product, notNullValue()); assertThat($product, hasKeyValuePair('id', 1)); assertThat($product_description, notNullValue()); assertThat($product_description, arrayWithSize(2)); assertThat($product_description[0], hasKeyValuePair('type', 'description type')); assertThat($product_description[1], hasKeyValuePair('type', 'description type')); assertThat($product_image, notNullValue()); assertThat($product_image, arrayWithSize(2)); assertThat($product_image[0], hasKeyValuePair('category', 'image1')); assertThat($product_image[1], hasKeyValuePair('category', 'image2')); assertThat($product_feature, notNullValue()); assertThat($product_feature, arrayWithSize(2)); assertThat($product_feature[0], hasKeyValuePair('description', 'feature1')); assertThat($product_feature[1], hasKeyValuePair('description', 'feature2')); assertThat($product['product_request']['id'], equalTo(1)); assertThat($product_keyword_profile, notNullValue()); assertThat($product_keyword_profile, arrayWithSize(1)); assertThat($product_keyword_profile[0], hasKeyValuePair('profile', ['keyword1', 'keyword2'])); assertthat($sub_product, notNullValue()); assertThat($sub_product, arrayWithSize(1)); assertThat($sub_product[0], hasKeyValuePair('title', 'test sub product')); assertThat($sub_product_image, notNullValue()); assertThat($sub_product_image, arrayWithSize(2)); assertThat($sub_product_image[0], hasKeyValuePair('category', 'image1')); assertThat($sub_product_image[1], hasKeyValuePair('category', 'image2')); assertThat($sub_product_feature, notNullValue()); assertThat($sub_product_feature, arrayWithSize(2)); assertThat($sub_product_feature[0], hasKeyValuePair('description', 'feature1')); assertThat($sub_product_feature[1], hasKeyValuePair('description', 'feature2')); assertThat($sub_product_description, notNullValue()); assertThat($sub_product_description, arrayWithSize(1)); assertThat($sub_product_description[0], hasKeyValuePair('type', 'type1')); assertThat($sub_product_description[0], hasKeyValuePair('value', 'value1')); assertthat($sub_product_variation, notNullValue()); assertThat($sub_product_variation, arrayWithSize(2)); assertThat($sub_product_variation[0], hasKeyValuePair('value', 'variation1')); assertThat($sub_product_variation[1], hasKeyValuePair('value', 'variation2')); }
public function testUpdateUpdatesSuiteWhenThereAreNoExistingAttributesBesidesSubProductAndKeywordProfile() { $update_attributes = ['vendor' => 'amazon', 'vendor_id' => 'b000000', 'binding' => 'testbinding', 'brand' => 'testbrand', 'manufacturer' => 'test manufacturer', 'model' => 'test model', 'group' => 'test group', 'type' => 'test type', 'size' => 'testsize', 'clothing_size' => 'test clothing size', 'color' => 'testcolor', 'title' => 'updated test title', 'department' => 'test department', 'min_price_amount' => 4000, 'min_price_currency' => 'USD', 'min_price_formatted' => '$40.00', 'max_price_amount' => 4000, 'max_price_currency' => 'USD', 'max_price_formatted' => '$40.00', 'reviews_url' => 'reviewsurl.com', 'detail_url' => 'detailurl.com', 'images' => [['category' => 'image1', 'swatch_url' => 'testurl.com', 'swatch_height' => '100', 'swatch_width' => '200', 'small_url' => 'testurl.com', 'small_height' => '100', 'small_width' => '200', 'thumb_url' => 'testurl.com', 'thumb_height' => '100', 'thumb_width' => '200', 'tiny_url' => 'testurl.com', 'tiny_height' => '100', 'tiny_width' => '200', 'medium_url' => 'testurl.com', 'medium_height' => '100', 'medium_width' => '200', 'large_url' => 'testurl.com', 'large_height' => '100', 'large_width' => '200']], 'features' => [['description' => 'updated description']], 'descriptions' => [['type' => 'updated type', 'value' => 'updated value']], 'sub_products' => [['vendor' => 'amazon', 'vendor_id' => 'b000001', 'parent_vendor_id' => 'b000000', 'binding' => 'testbinding', 'brand' => 'testbrand', 'manufacturer' => 'test manufacturer', 'model' => 'test model', 'group' => 'test group', 'type' => 'test type', 'size' => 'testsize', 'clothing_size' => 'test clothing size', 'color' => 'testcolor', 'title' => 'updated sub product title', 'condition' => 'test condition', 'department' => 'test department', 'list_price_amount' => 4000, 'list_price_currency' => 'USD', 'list_price_formatted' => '$40.00', 'price_amount' => 4000, 'price_currency' => 'USD', 'price_formatted' => '$40.00', 'availability' => 'test avail', 'availability_type' => 'test avail type', 'availability_max_hours' => 'test avail max hours', 'availability_min_hours' => 'test avail min hours', 'availability_ship' => 'test avail ship', 'availability_ss_ship' => 1, 'offer_listing_id' => 'foo1', 'images' => [['category' => 'updated sub product image', 'swatch_url' => 'testurl.com', 'swatch_height' => '100', 'swatch_width' => '200', 'small_url' => 'testurl.com', 'small_height' => '100', 'small_width' => '200', 'thumb_url' => 'testurl.com', 'thumb_height' => '100', 'thumb_width' => '200', 'tiny_url' => 'testurl.com', 'tiny_height' => '100', 'tiny_width' => '200', 'medium_url' => 'testurl.com', 'medium_height' => '100', 'medium_width' => '200', 'large_url' => 'testurl.com', 'large_height' => '100', 'large_width' => '200']], 'features' => [['description' => 'updated sub product feature']], 'descriptions' => [['type' => 'updated sub product description type', 'value' => 'updated sub product description value']], 'variations' => [['type' => 'updated sub product variation type', 'value' => 'updated sub product variation value ']]]]]; $index_update_attributes = $update_attributes; $index_update_attributes['is_refreshed'] = 1; $index_update_attributes['images'] = $update_attributes['images']; $index_update_attributes['features'] = $update_attributes['features']; $index_update_attributes['descriptions'] = $update_attributes['descriptions']; $index_update_attributes['sub_products'] = $update_attributes['sub_products']; $index_update_attributes['keyword_profile']['profile'] = ['keyword1', 'keyword2']; $index_update_attributes['category_keywords'] = ['category', 'keywords']; $data_repo = $this->dataRepoSetup(['product', 'sub_products', 'sub_product_variations', 'keyword_profile']); $expected_product_suite = $index_update_attributes; $indexer_mock = Mockery::mock('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface'); $indexer_mock->shouldReceive('queueIndex')->with(Mockery::on(function ($product_suite) use($expected_product_suite) { if (!empty($this->arrayRecursiveDiff($expected_product_suite, $product_suite))) { return false; } return true; }), false, false)->once()->andReturn(true); $this->app->instance('Giftertipster\\Service\\ProductSuite\\ProductSuiteIndexerInterface', $indexer_mock); \DB::shouldReceive('beginTransaction')->twice(); \DB::shouldReceive('commit')->twice(); \DB::shouldReceive('rollback')->never(); $add_repo_mock = \Mockery::mock('Giftertipster\\Repository\\Add\\AddRepositoryInterface'); $add_repo_mock->shouldReceive('getAdminAddCategoryKeywords')->once()->with(1)->andReturn(['category', 'keywords']); $this->app->instance('Giftertipster\\Repository\\Add\\AddRepositoryInterface', $add_repo_mock); $repo = $this->app->make('Giftertipster\\Repository\\ProductSuite\\EloquentProductSuiteRepository'); $response = $repo->update(1, $update_attributes); $this->getDataRepoData(); //ensure updates where made assertThat($response, identicalTo(true)); assertThat($this->product->title, equalTo($update_attributes['title'])); assertThat($this->product_image_collection->first()->category, equalTo($update_attributes['images'][0]['category'])); assertThat($this->product_feature_collection->first()->description, equalTo($update_attributes['features'][0]['description'])); assertThat($this->product_description_collection->first()->value, equalTo($update_attributes['descriptions'][0]['value'])); assertThat($this->sub_product_collection->first()->title, equalTo($update_attributes['sub_products'][0]['title'])); assertThat($this->sub_product_image_collection->first()->category, equalTo($update_attributes['sub_products'][0]['images'][0]['category'])); assertThat($this->sub_product_feature_collection->first()->description, equalTo($update_attributes['sub_products'][0]['features'][0]['description'])); assertThat($this->sub_product_description_collection->first()->value, equalTo($update_attributes['sub_products'][0]['descriptions'][0]['value'])); assertThat($this->sub_product_variation_collection->first()->value, equalTo($update_attributes['sub_products'][0]['variations'][0]['value'])); //ensure old data was deleted where needed assertthat($this->product_image_count, equalTo(1)); assertthat($this->product_feature_count, equalTo(1)); assertthat($this->product_description_count, equalTo(1)); assertthat($this->product_keyword_profile_count, equalTo(1)); assertthat($this->sub_product_count, equalTo(1)); assertthat($this->sub_product_image_count, equalTo(1)); assertthat($this->sub_product_feature_count, equalTo(1)); assertthat($this->sub_product_description_count, equalTo(1)); assertthat($this->sub_product_variation_count, equalTo(1)); }