|
10 | 10 | use GuzzleHttp\RequestOptions; |
11 | 11 | use Lamoda\OmsClient\Exception\OmsGeneralErrorException; |
12 | 12 | use Lamoda\OmsClient\Exception\OmsRequestErrorException; |
| 13 | +use Lamoda\OmsClient\Exception\OmsSignerErrorException; |
13 | 14 | use Lamoda\OmsClient\Serializer\SerializerInterface; |
14 | 15 | use Lamoda\OmsClient\V2\Dto\CloseICArrayResponse; |
15 | 16 | use Lamoda\OmsClient\V2\Dto\CreateOrderForEmissionICRequestLight; |
|
18 | 19 | use Lamoda\OmsClient\V2\Dto\GetICsFromOrderResponse; |
19 | 20 | use Lamoda\OmsClient\V2\Extension; |
20 | 21 | use Lamoda\OmsClient\V2\OmsApi; |
| 22 | +use Lamoda\OmsClient\V2\Signer\SignerInterface; |
| 23 | +use PHPUnit\Framework\Assert; |
21 | 24 | use PHPUnit\Framework\MockObject\MockObject; |
22 | 25 | use PHPUnit\Framework\TestCase; |
23 | 26 | use Psr\Http\Message\RequestInterface; |
@@ -184,6 +187,112 @@ public function testCreateOrderForEmissionIC(): void |
184 | 187 | $this->assertEquals($expectedResult, $result); |
185 | 188 | } |
186 | 189 |
|
| 190 | + public function testCreateOrderForEmissionICWithSignature(): void |
| 191 | + { |
| 192 | + $createOrderForEmissionICRequestLight = new CreateOrderForEmissionICRequestLight( |
| 193 | + '', |
| 194 | + '', |
| 195 | + '', |
| 196 | + '', |
| 197 | + '', |
| 198 | + new \DateTimeImmutable(), |
| 199 | + [] |
| 200 | + ); |
| 201 | + |
| 202 | + $serializedRequest = '{"test": "value"}'; |
| 203 | + $signature = 'signature'; |
| 204 | + |
| 205 | + $this->serializer->expects($this->once()) |
| 206 | + ->method('serialize') |
| 207 | + ->with( |
| 208 | + $createOrderForEmissionICRequestLight |
| 209 | + ) |
| 210 | + ->willReturn($serializedRequest); |
| 211 | + |
| 212 | + |
| 213 | + $this->client->expects($this->once()) |
| 214 | + ->method('request') |
| 215 | + ->with( |
| 216 | + 'POST', |
| 217 | + 'api/v2/light/orders', |
| 218 | + [ |
| 219 | + RequestOptions::BODY => $serializedRequest, |
| 220 | + RequestOptions::HEADERS => [ |
| 221 | + 'Content-Type' => 'application/json', |
| 222 | + 'clientToken' => self::TOKEN, |
| 223 | + 'X-Signature' => $signature |
| 224 | + ], |
| 225 | + RequestOptions::QUERY => [ |
| 226 | + 'omsId' => self::OMS_ID, |
| 227 | + ], |
| 228 | + RequestOptions::HTTP_ERRORS => true, |
| 229 | + ] |
| 230 | + ) |
| 231 | + ->willReturn( |
| 232 | + (new Response()) |
| 233 | + ->withBody(stream_for(self::API_RESPONSE)) |
| 234 | + ); |
| 235 | + |
| 236 | + $expectedResult = new CreateOrderForEmissionICResponse(self::OMS_ID, self::ORDER_ID, 100); |
| 237 | + $this->serializer |
| 238 | + ->method('deserialize') |
| 239 | + ->willReturn($expectedResult); |
| 240 | + |
| 241 | + $signer = $this->createMock(SignerInterface::class); |
| 242 | + $signer->method('sign') |
| 243 | + ->with(base64_encode($serializedRequest)) |
| 244 | + ->willReturn($signature); |
| 245 | + |
| 246 | + $result = $this->api->createOrderForEmissionIC( |
| 247 | + Extension::light(), |
| 248 | + self::TOKEN, |
| 249 | + self::OMS_ID, |
| 250 | + $createOrderForEmissionICRequestLight, |
| 251 | + $signer |
| 252 | + ); |
| 253 | + |
| 254 | + $this->assertEquals($expectedResult, $result); |
| 255 | + } |
| 256 | + |
| 257 | + public function testCreateOrderForEmissionFinishedWithSignerException(): void |
| 258 | + { |
| 259 | + $createOrderForEmissionICRequestLight = new CreateOrderForEmissionICRequestLight( |
| 260 | + '', |
| 261 | + '', |
| 262 | + '', |
| 263 | + '', |
| 264 | + '', |
| 265 | + new \DateTimeImmutable(), |
| 266 | + [] |
| 267 | + ); |
| 268 | + |
| 269 | + $serializedRequest = '{"test": "value"}'; |
| 270 | + |
| 271 | + $this->serializer->expects($this->once()) |
| 272 | + ->method('serialize') |
| 273 | + ->with( |
| 274 | + $createOrderForEmissionICRequestLight |
| 275 | + ) |
| 276 | + ->willReturn($serializedRequest); |
| 277 | + |
| 278 | + |
| 279 | + $this->client->expects($this->never()) |
| 280 | + ->method('request'); |
| 281 | + |
| 282 | + $signer = $this->createMock(SignerInterface::class); |
| 283 | + $signer->method('sign') |
| 284 | + ->willThrowException(new \Exception('Something happened in signer')); |
| 285 | + |
| 286 | + $this->expectException(OmsSignerErrorException::class); |
| 287 | + $this->api->createOrderForEmissionIC( |
| 288 | + Extension::light(), |
| 289 | + self::TOKEN, |
| 290 | + self::OMS_ID, |
| 291 | + $createOrderForEmissionICRequestLight, |
| 292 | + $signer |
| 293 | + ); |
| 294 | + } |
| 295 | + |
187 | 296 | public function testGetICBufferStatus(): void |
188 | 297 | { |
189 | 298 | $this->client->expects($this->once()) |
|
0 commit comments