public function testDeleteDeletesProductAndRelationsAndProductRequestReturnsTrue() { $index_repo = Mockery::mock('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface'); $index_repo->shouldReceive('deleteProductAndAdds')->with(1, true)->once()->andReturn(true); $this->app->instance('Giftertipster\\Repository\\ProductsIndex\\Product\\ProductsIndexProductRepositoryInterface', $index_repo); $data_repo = $this->dataRepoSetup(); $this->getDataRepoData(); //connect product to product request Factory::create('Giftertipster\\Entity\\Eloquent\\User', ['permissions' => []]); $prod_request = $this->app->make('Giftertipster\\Entity\\Eloquent\\ProductRequest'); $prod_request->fill(['vendor' => 'test', 'vendor_id' => 100, 'user_id' => 1, 'product_id' => null]); $this->product->productRequest()->save($prod_request); $prod_request_check = $prod_request->where('product_id', '=', 1)->get(); assertThat($prod_request_check, not(nullValue())); //add "add" to product $add_type = Factory::create('Giftertipster\\Entity\\Eloquent\\AddType'); $add = Factory::create('Giftertipster\\Entity\\Eloquent\\Add', ['product_id' => 1, 'add_type_id' => 1]); assertThat($add->exists, identicalTo(true)); $add->occasionCategories()->attach($this->occasion); assertThat($add->occasionCategories()->get()->count(), atLeast(1)); //ACTION $response = $data_repo->delete(1); assertThat($response, identicalTo(true)); //get product check data $product = $this->app->make('Giftertipster\\Entity\\Eloquent\\Product'); $product_check = $product->find(1); //get product request check data $prod_request_check = $prod_request->where('product_id', '=', 1)->get()->toArray(); //get keyword profile check data $keyword_profile = $this->app->make('Giftertipster\\Entity\\Eloquent\\KeywordProfile'); $keyword_profile_check = $keyword_profile->get()->toArray(); $occasion_category = $this->app->make('Giftertipster\\Entity\\Eloquent\\Category\\OccasionCategory'); $occasion_category_count = $occasion_category->get()->count(); //get "add" check data $add_check = $add->newInstance()->get()->toArray(); $add_category_pivot_check = \DB::table('add_categories')->get(); assertThat($product_check, nullValue()); assertThat($prod_request_check, emptyArray()); assertThat($keyword_profile_check, emptyArray()); assertThat($occasion_category_count, greaterThan(0)); assertThat($add_check, emptyArray()); assertThat($add_category_pivot_check, emptyArray()); assertThat(Product::get()->toArray(), emptyArray()); assertThat(Image::get()->toArray(), emptyArray()); assertThat(Description::get()->toArray(), emptyArray()); assertThat(Feature::get()->toArray(), emptyArray()); assertThat(SubProduct::get()->toArray(), emptyArray()); assertThat(Variation::get()->toArray(), emptyArray()); }
public function testAddPopularitySearchReturnsResultOnSuccess() { //product $this->client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 100, 'body' => ['title' => 'test product', 'min_price' => 20000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup1', 'soft_delete_status' => 0], 'refresh' => true]); //product $this->client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 200, 'body' => ['title' => 'test product2', 'min_price' => 30000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup2', 'soft_delete_status' => 0], 'refresh' => true]); //add $this->client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 1, 'parent' => 100, 'body' => ['gender_ids' => 1, 'interest_ids' => [1, 2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]); //add $this->client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 2, 'parent' => 100, 'body' => ['gender_ids' => 2, 'interest_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]); //add $this->client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 3, 'parent' => 200, 'body' => ['gender_ids' => 1, 'interests\\_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]); $result = $this->repo->AddPopularitySearch(0, 100); assertThat($result, hasKey('results')); assertThat($result['results'], not(emptyArray())); assertThat($result['results'][0], not(hasKey('_source'))); assertThat($result['meta']['total_hits'], atLeast(1)); assertThat($result, hasKey('facets')); assertThat($result['facets'], hasKey('price')); assertThat($result['facets']['price'], not(emptyArray())); assertThat($result['facets'], hasKey('group')); }
public function testGetFlattenedCategoryMap() { $category_map = $this->repo->getFlattenedCategoryMap(); assertThat($category_map, arrayWithSize(atLeast(1))); assertThat($category_map['sub_interest_categories']['_parent_type'], equalTo('interest')); }
public function testAddPopularitySearchReturnsResultOnSuccess() { //product $this->es_client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 100, 'body' => ['title' => 'test product', 'min_price' => 20000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup1', 'soft_delete_status' => 0], 'refresh' => true]); //product $this->es_client->index(['index' => $this->product_index, 'type' => $this->product_type, 'id' => 200, 'body' => ['title' => 'test product2', 'min_price' => 30000, 'max_price' => 20000, 'datetime' => '2014-02-14 00:01:01', 'group' => 'testgroup2', 'soft_delete_status' => 0], 'refresh' => true]); //add $this->es_client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 1, 'parent' => 100, 'body' => ['gender_ids' => 1, 'interest_ids' => [1, 2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]); //add $this->es_client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 2, 'parent' => 100, 'body' => ['gender_ids' => 2, 'interest_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]); //add $this->es_client->index(['index' => $this->add_index, 'type' => $this->add_type, 'id' => 3, 'parent' => 200, 'body' => ['gender_ids' => 1, 'interests\\_ids' => [2], 'datetime' => '2014-02-14 00:01:01'], 'refresh' => true]); \Config::shouldReceive('get')->with('laravel-elasticsearch-repository::index.index_models.product_add.setup.type')->andReturn('add'); $result = $this->repo->model('product')->search('add_count', null, 0, 100); assertThat($result, hasKey('results')); assertThat($result['results'], not(emptyArray())); assertThat($result['results'][0], not(hasKey('_source'))); assertThat($result['meta']['total_hits'], atLeast(1)); assertThat($result, hasKey('facets')); assertThat($result['facets'], hasKey('price')); assertThat($result['facets']['price'], not(emptyArray())); assertThat($result['facets'], hasKey('group')); }