Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
klmp200 committed Dec 23, 2024
1 parent 6f003ff commit 139221d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
4 changes: 2 additions & 2 deletions counter/static/bundled/counter/counter-click-index.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 2 additions & 0 deletions counter/static/bundled/counter/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
type ErrorMessage = string;

export interface InitialFormData {
/* Used to refill the form when the backend raises an error */
id?: keyof Record<string, Product>;
Expand Down
23 changes: 7 additions & 16 deletions counter/tests/test_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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 (
Expand All @@ -43,7 +43,7 @@
)


class FullClickSetup:
class TestFullClickBase(TestCase):
@classmethod
def setUpTestData(cls):
cls.customer = subscriber_user.make()
Expand All @@ -54,8 +54,7 @@ def setUpTestData(cls):
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)
Expand All @@ -67,10 +66,7 @@ def setUpTestData(cls):
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)

Expand All @@ -89,7 +85,7 @@ def updated_amount(self, user: User) -> Decimal:
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(
Expand Down Expand Up @@ -218,7 +214,7 @@ def to_form(self, index: int) -> dict[str, str]:
}


class TestCounterClick(FullClickSetup, TestCase):
class TestCounterClick(TestFullClickBase):
@classmethod
def setUpTestData(cls):
super().setUpTestData()
Expand Down Expand Up @@ -257,16 +253,11 @@ def setUpTestData(cls):
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
Expand Down

0 comments on commit 139221d

Please sign in to comment.