|
1 | 1 | # Main aspects of Clopos: Product, Sales, Order and Receipt |
2 | 2 | import random |
3 | | -import uuid |
4 | 3 | from typing import TYPE_CHECKING |
5 | 4 |
|
6 | | -import pytest |
7 | 5 | from pytest_mock import MockerFixture |
8 | 6 |
|
9 | | -from integrify.clopos.schemas.common.response import BaseResponse, ErrorResponse |
| 7 | +from integrify.clopos.schemas.common.response import BaseResponse, ErrorResponse, ObjectResponse |
10 | 8 | from integrify.clopos.schemas.enums import OrderStatus, ProductType |
11 | 9 | from integrify.clopos.schemas.orders.object import Order |
12 | | -from integrify.clopos.schemas.products.object import Product |
| 10 | +from integrify.clopos.schemas.products.object import Product, StopList |
13 | 11 | from integrify.clopos.schemas.receipts.object import Receipt |
| 12 | +from integrify.schemas import APIResponse |
| 13 | +from tests.client import CloposTestClientClass |
14 | 14 | from tests.conftest import requires_env |
15 | 15 |
|
16 | 16 | if TYPE_CHECKING: |
17 | 17 | from tests.client import CloposTestClientClass |
18 | 18 |
|
19 | | -# used to create, get, delete a receipt |
20 | | -RECEIPT_ID = None |
21 | | - |
22 | 19 |
|
23 | 20 | @requires_env() |
24 | 21 | def test_get_products(authed_client: 'CloposTestClientClass'): |
@@ -169,6 +166,16 @@ def test_get_product_by_id_wrong_id(authed_client: 'CloposTestClientClass'): |
169 | 166 | assert resp.body.error == 'No query results for model [App\\Models\\Client\\Product] 1000' |
170 | 167 |
|
171 | 168 |
|
| 169 | +@requires_env() |
| 170 | +def test_get_stop_list(authed_client: 'CloposTestClientClass'): |
| 171 | + resp = authed_client.get_stop_list() |
| 172 | + |
| 173 | + assert resp.ok |
| 174 | + assert resp.body.success |
| 175 | + assert isinstance(resp.body.data, list) |
| 176 | + assert isinstance(resp.body.data[0], StopList) |
| 177 | + |
| 178 | + |
172 | 179 | @requires_env() |
173 | 180 | def test_get_orders(authed_client: 'CloposTestClientClass'): |
174 | 181 | resp = authed_client.get_orders() |
@@ -318,135 +325,52 @@ def test_get_receipt_by_id_wrong_id(authed_client: 'CloposTestClientClass'): |
318 | 325 |
|
319 | 326 |
|
320 | 327 | @requires_env() |
321 | | -def test_create_receipt(authed_client: 'CloposTestClientClass'): |
322 | | - global RECEIPT_ID |
323 | | - |
324 | | - cid = uuid.uuid4().hex |
325 | | - |
326 | | - data = { |
327 | | - 'address': '', |
328 | | - 'by_card': 0, |
329 | | - 'by_cash': 30000, |
330 | | - 'cid': cid, |
331 | | - 'closed_at': 1755524813947, |
332 | | - 'created_at': 1755524813947, |
333 | | - 'customer_discount_type': 0, |
334 | | - 'delivery_fee': 0, |
335 | | - 'discount_rate': 0, |
336 | | - 'discount_type': 0, |
337 | | - 'discount_value': 0, |
338 | | - 'gift_total': 0, |
339 | | - 'guests': 1, |
340 | | - 'meta': { |
341 | | - 'preprint_count': 0, |
342 | | - 'sale_type': {'name': 'Satis usulu 1'}, |
343 | | - 'user': {'name': 'Clopos'}, |
344 | | - 'terminal_updated_at': 1755524813947, |
345 | | - 'availiableDeposit': 30000, |
346 | | - }, |
347 | | - 'original_subtotal': 30000, |
348 | | - 'payment_methods': [{'id': 1, 'name': 'Cash', 'amount': 30000}], |
349 | | - 'printed': False, |
350 | | - 'receipt_products': [ |
351 | | - { |
352 | | - 'cid': 'f5b17d93-5586-411b-9e9d-934d3aa2e2ff', |
353 | | - 'product_id': 31042, |
354 | | - 'portion_size': 1, |
355 | | - 'is_gift': 0, |
356 | | - 'meta': { |
357 | | - 'product': { |
358 | | - 'name': 'Апельсинли реване', |
359 | | - 'giftable': False, |
360 | | - 'price': 22000, |
361 | | - 'modifier_name': 'not found', |
362 | | - 'discountable': True, |
363 | | - 'sold_by_weight': False, |
364 | | - 'priceWithoutTaxes': 22000, |
365 | | - 'barcode': '', |
366 | | - 'taxes': [], |
367 | | - 'station': {'id': 57, 'name': 'Отдел Кондитер'}, |
368 | | - }, |
369 | | - 'originalPrice': 22000, |
370 | | - 'total_gift': 0, |
371 | | - 'discountedPrice': 0, |
372 | | - 'terminal_updated_at': 1755524813946, |
373 | | - }, |
374 | | - 'price': 22000, |
375 | | - 'count': 1, |
376 | | - 'subtotal': 22000, |
377 | | - 'total': 22000, |
378 | | - }, |
379 | | - { |
380 | | - 'cid': 'c5202cc3-1f03-47b1-9dbc-5f049dabf997', |
381 | | - 'product_id': 31046, |
382 | | - 'portion_size': 1, |
383 | | - 'is_gift': 0, |
384 | | - 'meta': { |
385 | | - 'product': { |
386 | | - 'name': 'Ачма узум жевиз', |
387 | | - 'giftable': False, |
388 | | - 'price': 8000, |
389 | | - 'modifier_name': 'not found', |
390 | | - 'discountable': True, |
391 | | - 'sold_by_weight': False, |
392 | | - 'priceWithoutTaxes': 8000, |
393 | | - 'barcode': '', |
394 | | - 'taxes': [], |
395 | | - 'station': {'id': 57, 'name': 'Отдел Кондитер'}, |
396 | | - }, |
397 | | - 'originalPrice': 8000, |
398 | | - 'total_gift': 0, |
399 | | - 'discountedPrice': 0, |
400 | | - 'terminal_updated_at': 1755524813947, |
401 | | - }, |
402 | | - 'price': 8000, |
403 | | - 'count': 1, |
404 | | - 'subtotal': 8000, |
405 | | - 'total': 8000, |
406 | | - }, |
407 | | - ], |
408 | | - 'remaining': 0, |
409 | | - 'rps_discount': 0, |
410 | | - 'sale_type_id': 1000, |
411 | | - 'service_charge': 0, |
412 | | - 'service_charge_value': 0, |
413 | | - 'status': 2, |
414 | | - 'subtotal': 30000, |
415 | | - 'terminal_id': 1, |
416 | | - 'total': 30000, |
417 | | - 'total_tax': 0, |
418 | | - 'user_id': 1, |
419 | | - } |
420 | | - |
421 | | - resp = authed_client.create_receipt(**data) # type: ignore |
| 328 | +def test_create_receipt( |
| 329 | + authed_client: 'CloposTestClientClass', |
| 330 | + new_receipt_resp: APIResponse[ObjectResponse[Receipt]], |
| 331 | +): |
| 332 | + assert new_receipt_resp.ok |
| 333 | + assert isinstance(new_receipt_resp.body.data, Receipt) |
| 334 | + |
| 335 | + resp = authed_client.get_receipt_by_id(new_receipt_resp.body.data.id) |
422 | 336 |
|
423 | 337 | assert resp.ok |
424 | 338 | assert isinstance(resp.body.data, Receipt) |
425 | 339 |
|
426 | | - resp = authed_client.get_receipt_by_id(resp.body.data.id) |
427 | 340 |
|
428 | | - RECEIPT_ID = resp.body.data.id |
| 341 | +@requires_env() |
| 342 | +def test_get_receipt_by_id(authed_client: 'CloposTestClientClass', new_receipt_object: Receipt): |
| 343 | + resp = authed_client.get_receipt_by_id(new_receipt_object.id) |
| 344 | + |
429 | 345 | assert resp.ok |
| 346 | + assert resp.body.success |
430 | 347 | assert isinstance(resp.body.data, Receipt) |
431 | | - assert resp.body.data.cid == cid |
| 348 | + |
| 349 | + assert resp.body.data.id == new_receipt_object.id |
432 | 350 |
|
433 | 351 |
|
434 | 352 | @requires_env() |
435 | | -@pytest.mark.skipif(not RECEIPT_ID, reason='test_create_receipt must be run successfully first') |
436 | | -def test_get_receipt_by_id(authed_client: 'CloposTestClientClass'): |
437 | | - resp = authed_client.get_receipt_by_id(RECEIPT_ID) # type: ignore[arg-type] |
| 353 | +def test_update_closed_receipt(authed_client: 'CloposTestClientClass', new_receipt_object: Receipt): |
| 354 | + resp = authed_client.get_receipt_by_id(new_receipt_object.id) |
438 | 355 |
|
439 | 356 | assert resp.ok |
440 | 357 | assert resp.body.success |
441 | 358 | assert isinstance(resp.body.data, Receipt) |
| 359 | + assert resp.body.data.status != OrderStatus.NEW |
| 360 | + |
| 361 | + resp = authed_client.update_closed_receipt( |
| 362 | + id=new_receipt_object.id, |
| 363 | + order_status=OrderStatus.NEW, |
| 364 | + ) |
442 | 365 |
|
443 | | - assert resp.body.data.id == RECEIPT_ID |
| 366 | + assert resp.ok |
| 367 | + assert isinstance(resp.body.data, Receipt) |
| 368 | + assert resp.body.data.order_status == OrderStatus.NEW |
444 | 369 |
|
445 | 370 |
|
446 | 371 | @requires_env() |
447 | | -@pytest.mark.skipif(not RECEIPT_ID, reason='test_create_receipt must be run successfully first') |
448 | | -def test_delete_receipt(authed_client: 'CloposTestClientClass'): |
449 | | - resp = authed_client.delete_receipt(RECEIPT_ID) # type: ignore[arg-type] |
| 372 | +def test_delete_receipt(authed_client: 'CloposTestClientClass', new_receipt_object: Receipt): |
| 373 | + resp = authed_client.delete_receipt(new_receipt_object.id) |
450 | 374 |
|
451 | 375 | assert resp.ok |
452 | 376 | assert isinstance(resp.body, BaseResponse) |
0 commit comments