Completed
Push — master ( b736eb...f06be5 )
by Laurens
03:50 queued 01:55
created

ProductClientTest::getLibrary()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Tests\Unit;
6
7
use LauLamanApps\IzettleApi\API\ImageCollection;
8
use LauLamanApps\IzettleApi\API\Product\Category;
9
use LauLamanApps\IzettleApi\API\Product\CategoryCollection;
10
use LauLamanApps\IzettleApi\API\Product\Discount;
11
use LauLamanApps\IzettleApi\API\Product\Library;
12
use LauLamanApps\IzettleApi\API\Product\Product;
13
use LauLamanApps\IzettleApi\API\Product\Variant;
14
use LauLamanApps\IzettleApi\API\Product\VariantCollection;
15
use LauLamanApps\IzettleApi\ProductClient;
16
use Money\Money;
17
use Ramsey\Uuid\Uuid;
18
19
/**
20
 * @small
21
 */
22
final class ProductClientTest extends AbstractClientTest
23
{
24
    /**
25
     * @test
26
     */
27 View Code Duplication
    public function getCategories()
28
    {
29
        $method = 'get';
30
        $url = sprintf(ProductClient::GET_CATEGORIES, self::DEFAULT_ORGANIZATION_UUID);
31
        $options = [
32
            'headers' => [
33
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN)
34
            ],
35
            'query' => null,
36
        ];
37
38
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options), $this->getAccessToken());
39
        $categories = $productClient->getCategories();
40
        self::assertTrue(is_array($categories));
41
    }
42
43
    /**
44
     * @test
45
     */
46 View Code Duplication
    public function createCategory()
47
    {
48
        $category = Category::new('name');
49
        $method = 'post';
50
        $url = sprintf(ProductClient::POST_CATEGORY, self::DEFAULT_ORGANIZATION_UUID);
51
        $options = [
52
            'headers' => [
53
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN),
54
                'content-type' => 'application/json',
55
                'Accept' => 'application/json',
56
            ],
57
            'body' => $category->getCreateData(),
58
        ];
59
60
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options), $this->getAccessToken());
61
        $productClient->createCategory($category);
62
63
        self::assertTrue(true); //-- fix till issue is solved: https://github.com/mockery/mockery/issues/376
64
    }
65
66
    /**
67
     * @test
68
     */
69 View Code Duplication
    public function getDiscounts()
70
    {
71
        $method = 'get';
72
        $url = sprintf(ProductClient::GET_DISCOUNTS, self::DEFAULT_ORGANIZATION_UUID);
73
        $options = [
74
            'headers' => [
75
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN)
76
            ],
77
            'query' => null,
78
        ];
79
80
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options), $this->getAccessToken());
81
        $discounts = $productClient->getDiscounts();
82
        self::assertTrue(is_array($discounts));
83
    }
84
85
    /**
86
     * @test
87
     */
88 View Code Duplication
    public function createDiscount()
89
    {
90
        $discount = $this->getDiscount();
91
        $method = 'post';
92
        $url = sprintf(ProductClient::POST_DISCOUNT, self::DEFAULT_ORGANIZATION_UUID);
93
        $options = [
94
            'headers' => [
95
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN),
96
                'content-type' => 'application/json',
97
                'Accept' => 'application/json',
98
            ],
99
            'body' => $discount->getCreateData(),
100
        ];
101
102
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options), $this->getAccessToken());
103
        $productClient->createDiscount($discount);
104
105
        self::assertTrue(true); //-- fix till issue is solved: https://github.com/mockery/mockery/issues/376
106
    }
107
108
    /**
109
     * @test
110
     */
111 View Code Duplication
    public function deleteDiscount()
112
    {
113
        $discount = $this->getDiscount();
114
        $method = 'delete';
115
        $url = sprintf(
116
            ProductClient::DELETE_DISCOUNT,
117
            self::DEFAULT_ORGANIZATION_UUID,
118
            (string) $discount->getUuid()
119
        );
120
        $options = [
121
            'headers' => [
122
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN),
123
            ],
124
        ];
125
126
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options), $this->getAccessToken());
127
        $productClient->deleteDiscount($discount);
128
129
        self::assertTrue(true); //-- fix till issue is solved: https://github.com/mockery/mockery/issues/376
130
    }
131
132
    /**
133
     * @test
134
     */
135
    public function getLibrary()
136
    {
137
        $method = 'get';
138
        $url = sprintf(ProductClient::GET_LIBRARY, self::DEFAULT_ORGANIZATION_UUID);
139
        $options = [
140
            'headers' => [
141
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN)
142
            ],
143
            'query' => null,
144
        ];
145
146
        $return = [
147
            'fromEventLogUuid' => Uuid::uuid1(),
148
            'untilEventLogUuid' => Uuid::uuid1(),
149
            'products' => [],
150
            'discounts' => [],
151
            'deletedProducts' => [],
152
            'deletedDiscounts' => [],
153
        ];
154
155
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options, $return), $this->getAccessToken());
156
        $library = $productClient->getLibrary();
157
        self::assertInstanceOf(Library::class, $library);
158
    }
159
160
    /**
161
     * @test
162
     */
163 View Code Duplication
    public function getProducts()
164
    {
165
        $method = 'get';
166
        $url = sprintf(ProductClient::GET_PRODUCTS, self::DEFAULT_ORGANIZATION_UUID);
167
        $options = [
168
            'headers' => [
169
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN)
170
            ],
171
            'query' => null,
172
        ];
173
174
        $return = [
175
176
        ];
177
178
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options, $return), $this->getAccessToken());
179
        $products = $productClient->getProducts();
180
        self::assertTrue(is_array($products));
181
    }
182
183
    /**
184
     * @test
185
     */
186 View Code Duplication
    public function createProduct()
187
    {
188
        $product = $this->getProduct();
189
        $method = 'post';
190
        $url = sprintf(ProductClient::POST_PRODUCT, self::DEFAULT_ORGANIZATION_UUID);
191
        $options = [
192
            'headers' => [
193
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN),
194
                'content-type' => 'application/json',
195
                'Accept' => 'application/json',
196
            ],
197
            'body' => $product->getCreateData(),
198
        ];
199
200
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options), $this->getAccessToken());
201
        $productClient->createProduct($product);
202
203
        self::assertTrue(true); //-- fix till issue is solved: https://github.com/mockery/mockery/issues/376
204
    }
205
206
    /**
207
     * @test
208
     */
209 View Code Duplication
    public function deleteProduct()
210
    {
211
        $product = $this->getProduct();
212
        $method = 'delete';
213
        $url = sprintf(
214
            ProductClient::DELETE_PRODUCT,
215
            self::DEFAULT_ORGANIZATION_UUID,
216
            (string) $product->getUuid()
217
        );
218
        $options = [
219
            'headers' => [
220
                'Authorization' => sprintf('Bearer %s', self::ACCESS_TOKEN),
221
            ],
222
        ];
223
224
        $productClient = new ProductClient($this->getGuzzleClient($method, $url, $options), $this->getAccessToken());
225
        $productClient->deleteProduct($product);
226
227
        self::assertTrue(true); //-- fix till issue is solved: https://github.com/mockery/mockery/issues/376
228
    }
229
230
    private function getDiscount(): Discount
231
    {
232
        return Discount::new('name', 'description', new ImageCollection());
233
    }
234
235
    private function getProduct(): Product
236
    {
237
        return Product::new(
238
            'name',
239
            'description',
240
            new CategoryCollection(),
241
            new ImageCollection(),
242
            new VariantCollection([ Variant::new(
243
                null,
244
                null,
245
                null,
246
                null,
247
                1,
248
                null,
249
                Money::EUR(0),
250
                null,
251
                21
252
            )])
253
        );
254
    }
255
}
256