/** * @test */ public function it_creates_a_new_country() { $wps = new Sdk(); $wps->addMockResults([new Response(200, [], json_encode($wps->countryResponse(3)))]); $country = $wps->country(['name' => 'Country 3', 'code' => 'CD', 'unknown' => 'should not be on object']); $country->save(); $this->assertEquals(['/countries/'], $wps->getRequestUris()); $this->assertEquals(['{"name":"Country 3","code":"CD"}'], $wps->getRequestBodies()); $this->assertInstanceOf(Country::class, $country); $this->assertEquals([3, 'Country 3', null], [$country->id, $country->name, $country->unknown]); }
/** * @test */ public function it_updates_a_feature() { $wps = new Sdk(); $wps->addMockResults([new Response(200, [], json_encode($wps->featureResponse(1))), new Response(200, [], json_encode($wps->featureResponse(1)))]); $feature = $wps->feature()->find(1); $feature->name = "new feature name"; $success = $feature->save(); $this->assertEquals(['/features/1/', '/features/1/'], $wps->getRequestUris()); $this->assertEquals([null, '{"name":"new feature name"}'], $wps->getRequestBodies()); $this->assertInstanceOf(Feature::class, $feature); $this->assertEquals([true, 'new feature name'], [$success, $feature->name]); }
/** * @test */ public function it_updates_a_block() { $wps = new Sdk(); $wps->addMockResults([new Response(200, [], json_encode($wps->blockResponse(1))), new Response(200, [], json_encode($wps->blockResponse(1)))]); $block = $wps->block()->find(1); $block->data = "new block data"; $success = $block->save(); $this->assertEquals(['/blocks/1/', '/blocks/1/'], $wps->getRequestUris()); $this->assertEquals([null, '{"data":"new block data"}'], $wps->getRequestBodies()); $this->assertInstanceOf(Block::class, $block); $this->assertEquals([true, 'new block data'], [$success, $block->data]); }
/** * @test */ public function it_syncs_blocks_for_a_product_on_a_site() { $wps = new Sdk(); $response = $wps->blocksResponse(); $response['data'] = array_reverse($response['data']); $wps->addMockResults([new Response(200, [], json_encode($wps->siteResponse(1))), new Response(200, [], json_encode($wps->productResponse(1))), new Response(200, [], json_encode($response))]); $site = $wps->site()->find(1); $product = $site->products(1); $product->blocks()->sync([2, 1]); $keys = $product->blocks->map(function ($item, $key) { return $item->getKey(); }); $this->assertEquals(['/sites/1/', '/products/1/', '/sites/1/products/1/blocks/'], $wps->getRequestUris()); $this->assertEquals([null, null, '[{"id":2},{"id":1}]'], $wps->getRequestBodies()); $this->assertContainsOnlyInstancesOf(Wps\Models\Block::class, $product->blocks); $this->assertEquals([2, 1], $keys->toArray()); }