From 139221dd228814fd2827d4945a53db851f45ec99 Mon Sep 17 00:00:00 2001 From: Sli Date: Mon, 23 Dec 2024 15:15:24 +0100 Subject: [PATCH] Apply review comments --- .../bundled/counter/counter-click-index.ts | 4 ++-- counter/static/bundled/counter/types.d.ts | 2 ++ counter/tests/test_counter.py | 23 ++++++------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/counter/static/bundled/counter/counter-click-index.ts b/counter/static/bundled/counter/counter-click-index.ts index 5755b7c7..23a8105d 100644 --- a/counter/static/bundled/counter/counter-click-index.ts +++ b/counter/static/bundled/counter/counter-click-index.ts @@ -1,6 +1,6 @@ import { exportToHtml } from "#core:utils/globals"; import { BasketItem } from "#counter:counter/basket"; -import type { CounterConfig } from "#counter:counter/types"; +import type { CounterConfig, ErrorMessage } from "#counter:counter/types"; exportToHtml("loadCounter", (config: CounterConfig) => { document.addEventListener("alpine:init", () => { @@ -38,7 +38,7 @@ exportToHtml("loadCounter", (config: CounterConfig) => { delete this.basket[id]; }, - addToBasket(id: string, quantity: number): string { + addToBasket(id: string, quantity: number): ErrorMessage { const item: BasketItem = this.basket[id] || new BasketItem(config.products[id], 0); diff --git a/counter/static/bundled/counter/types.d.ts b/counter/static/bundled/counter/types.d.ts index b28cb01a..4a22a916 100644 --- a/counter/static/bundled/counter/types.d.ts +++ b/counter/static/bundled/counter/types.d.ts @@ -1,3 +1,5 @@ +type ErrorMessage = string; + export interface InitialFormData { /* Used to refill the form when the backend raises an error */ id?: keyof Record; diff --git a/counter/tests/test_counter.py b/counter/tests/test_counter.py index a62e5fab..1b378d5b 100644 --- a/counter/tests/test_counter.py +++ b/counter/tests/test_counter.py @@ -30,7 +30,7 @@ from freezegun import freeze_time from model_bakery import baker from club.models import Club, Membership -from core.baker_recipes import board_user, subscriber_user +from core.baker_recipes import board_user, subscriber_user, very_old_subscriber_user from core.models import Group, User from counter.baker_recipes import product_recipe from counter.models import ( @@ -43,7 +43,7 @@ from counter.models import ( ) -class FullClickSetup: +class TestFullClickBase(TestCase): @classmethod def setUpTestData(cls): cls.customer = subscriber_user.make() @@ -54,8 +54,7 @@ class FullClickSetup: cls.subscriber = subscriber_user.make() cls.counter = baker.make(Counter, type="BAR") - cls.counter.sellers.add(cls.barmen) - cls.counter.sellers.add(cls.board_admin) + cls.counter.sellers.add(cls.barmen, cls.board_admin) cls.other_counter = baker.make(Counter, type="BAR") cls.other_counter.sellers.add(cls.barmen) @@ -67,10 +66,7 @@ class FullClickSetup: sub.subscription_end = localdate() - timedelta(days=89) sub.save() - cls.customer_old_can_not_buy = subscriber_user.make() - sub = cls.customer_old_can_not_buy.subscriptions.first() - sub.subscription_end = localdate() - timedelta(days=90) - sub.save() + cls.customer_old_can_not_buy = very_old_subscriber_user.make() cls.customer_can_not_buy = baker.make(User) @@ -89,7 +85,7 @@ class FullClickSetup: return user.customer.amount -class TestRefilling(FullClickSetup, TestCase): +class TestRefilling(TestFullClickBase): def login_in_bar(self, barmen: User | None = None): used_barman = barmen if barmen is not None else self.board_admin self.client.post( @@ -218,7 +214,7 @@ class BasketItem: } -class TestCounterClick(FullClickSetup, TestCase): +class TestCounterClick(TestFullClickBase): @classmethod def setUpTestData(cls): super().setUpTestData() @@ -257,16 +253,11 @@ class TestCounterClick(FullClickSetup, TestCase): limit_age=0, selling_price="1.5", special_selling_price="1" ) - cls.counter.products.add(cls.beer) - cls.counter.products.add(cls.beer_tap) - cls.counter.products.add(cls.snack) - cls.counter.save() + cls.counter.products.add(cls.beer, cls.beer_tap, cls.snack) cls.other_counter.products.add(cls.snack) - cls.other_counter.save() cls.club_counter.products.add(cls.stamps) - cls.club_counter.save() def login_in_bar(self, barmen: User | None = None): used_barman = barmen if barmen is not None else self.barmen