@shopbite-de/storefront 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.example +13 -0
- package/.github/workflows/ci.yaml +2 -0
- package/CLAUDE.md +54 -30
- package/GLOSSARY.md +327 -0
- package/README.md +5 -6
- package/app/app.vue +50 -40
- package/app/components/Address/Card.vue +2 -2
- package/app/components/Address/Detail.vue +17 -45
- package/app/components/Address/Form.vue +38 -26
- package/app/components/BranchSwitch.vue +40 -0
- package/app/components/Cart/Bar.vue +9 -9
- package/app/components/Cart/Item.vue +27 -36
- package/app/components/Cart/QuickView.vue +17 -16
- package/app/components/Cart/Upsell.vue +19 -27
- package/app/components/Category/Breadcrumb.vue +3 -8
- package/app/components/Category/FilterGroup.vue +6 -6
- package/app/components/Category/Listing.vue +44 -66
- package/app/components/Checkout/DeliveryTimeSelect.vue +21 -48
- package/app/components/Checkout/OrderMessage.vue +29 -0
- package/app/components/Checkout/OrdererAddress.vue +40 -0
- package/app/components/Checkout/PaymentAndDelivery.vue +40 -35
- package/app/components/Checkout/Summary.vue +89 -74
- package/app/components/Checkout/VoucherInput.vue +8 -8
- package/app/components/Contact/Form.vue +97 -13
- package/app/components/Footer.vue +2 -2
- package/app/components/Header.vue +9 -9
- package/app/components/Home/Categories.vue +13 -17
- package/app/components/Home/Facts.vue +6 -4
- package/app/components/Home/Hero.vue +1 -1
- package/app/components/Home/Highlights.vue +8 -8
- package/app/components/Home/Restaurant.vue +2 -2
- package/app/components/Menu/BonCard.vue +21 -37
- package/app/components/Menu/CartPanel.vue +2 -2
- package/app/components/Menu/CategoryIndex.vue +8 -12
- package/app/components/Menu/OrderMode.vue +2 -2
- package/app/components/Menu/SectionHeader.vue +6 -10
- package/app/components/Navigation/MobileTop.vue +12 -20
- package/app/components/Order/Confirmation.vue +10 -10
- package/app/components/Order/Detail.vue +47 -49
- package/app/components/Product/Configurator.vue +46 -30
- package/app/components/Product/CrossSelling.vue +56 -71
- package/app/components/Product/DeselectIngredient.vue +10 -11
- package/app/components/Product/Detail.vue +62 -55
- package/app/components/Product/FoodLabels.vue +4 -9
- package/app/components/Product/QuickView.vue +22 -30
- package/app/components/User/Detail.vue +20 -43
- package/app/components/User/LoginForm.vue +11 -17
- package/app/components/User/RegistrationForm.vue +3 -3
- package/app/components/Wishlist.vue +99 -106
- package/app/components/WishlistSaveButton.vue +17 -9
- package/app/composables/useAccountAddresses.ts +89 -0
- package/app/composables/useAccountOrders.ts +35 -0
- package/app/composables/useAddToCart.ts +63 -110
- package/app/composables/useCartData.ts +55 -0
- package/app/composables/useCartMutations.ts +93 -85
- package/app/composables/useCartUpsell.ts +27 -71
- package/app/composables/useCategoryListing.ts +36 -59
- package/app/composables/useCategorySeo.ts +11 -16
- package/app/composables/useCheckoutMethodGuard.ts +22 -46
- package/app/composables/useCheckoutMethods.ts +89 -0
- package/app/composables/useCheckoutOrderMessage.ts +19 -0
- package/app/composables/useCheckoutOrderer.ts +69 -0
- package/app/composables/useCommercePrice.ts +46 -9
- package/app/composables/useContactForm.ts +25 -32
- package/app/composables/useCustomer.ts +169 -0
- package/app/composables/useDeliveryTime.ts +112 -122
- package/app/composables/useHolidays.ts +12 -62
- package/app/composables/useHomeMenuCategories.ts +5 -5
- package/app/composables/useListingSearch.ts +9 -8
- package/app/composables/useLiveShopData.ts +15 -9
- package/app/composables/useMenuRootId.ts +3 -6
- package/app/composables/useMenuSection.ts +14 -0
- package/app/composables/useMenuSectionSchema.ts +23 -30
- package/app/composables/useNavigation.ts +24 -29
- package/app/composables/useOpeningHours.ts +21 -0
- package/app/composables/useOpeningHoursData.ts +9 -9
- package/app/composables/useOrder.ts +37 -0
- package/app/composables/useOrderMode.ts +18 -16
- package/app/composables/usePlaceOrder.ts +37 -0
- package/app/composables/useProductCartQuantity.ts +6 -6
- package/app/composables/useProductDetail.ts +28 -53
- package/app/composables/useProductEvents.ts +6 -5
- package/app/composables/useProductQuickView.ts +35 -68
- package/app/composables/useRegistrationForm.ts +85 -34
- package/app/composables/useRestaurantSchema.ts +7 -7
- package/app/composables/useSearchTracking.ts +6 -6
- package/app/composables/useSectionRoute.ts +48 -0
- package/app/composables/useServiceSchedule.ts +23 -0
- package/app/composables/useShippingLeadTime.ts +8 -6
- package/app/composables/useShippingMethodChoice.ts +13 -23
- package/app/composables/useShippingMethods.ts +31 -0
- package/app/composables/useShopConfig.ts +60 -0
- package/app/composables/useShopData.ts +20 -0
- package/app/composables/useSortingSelection.ts +5 -8
- package/app/composables/useStoreStatus.ts +13 -37
- package/app/composables/useTopSellers.ts +3 -3
- package/app/composables/useTrackEvent.ts +29 -24
- package/app/composables/useVoucherCode.ts +47 -12
- package/app/composables/useWishlistEntries.ts +233 -177
- package/app/error.vue +3 -2
- package/app/layouts/account.vue +4 -3
- package/app/pages/[...all].vue +6 -16
- package/app/pages/account/recover/password/index.vue +6 -14
- package/app/pages/anmelden.vue +1 -1
- package/app/pages/bestellung/[id]/erfolg.vue +3 -3
- package/app/pages/bestellung/[id]/fehler.vue +18 -29
- package/app/pages/bestellung/kasse.vue +24 -7
- package/app/pages/konto/adressen.vue +95 -40
- package/app/pages/konto/bestellungen.vue +10 -13
- package/app/pages/konto/index.vue +12 -2
- package/app/pages/konto/profil.vue +241 -42
- package/app/pages/passwort-vergessen.vue +5 -10
- package/app/pages/registrierung/bestaetigen.vue +9 -23
- package/app/pages/registrierung/index.vue +19 -11
- package/app/pages/suche.vue +29 -29
- package/app/plugins/shopware-layer-offline.ts +38 -0
- package/app/plugins/visitor-has-session.server.ts +19 -0
- package/app/utils/accountMessages.ts +74 -0
- package/app/utils/accountReads.ts +34 -0
- package/app/utils/bffWrite.ts +89 -0
- package/app/utils/dish.ts +121 -0
- package/app/utils/leadTime.ts +25 -29
- package/app/utils/media.ts +11 -17
- package/app/utils/menuGroups.ts +22 -35
- package/app/utils/money.ts +41 -0
- package/app/utils/openingHours.ts +30 -30
- package/app/utils/orderStatus.ts +17 -0
- package/app/utils/productUrl.ts +14 -31
- package/app/utils/restaurantTime.ts +326 -0
- package/app/utils/schema.ts +39 -42
- package/app/utils/wishlist.ts +139 -0
- package/docs/adr/0001-backend-agnostic-storefront.md +409 -0
- package/eslint.config.mjs +42 -2
- package/nuxt.config.ts +28 -0
- package/package.json +1 -1
- package/server/adapters/memory/cart.ts +370 -0
- package/server/adapters/memory/catalog.ts +367 -0
- package/server/adapters/memory/contact.ts +89 -0
- package/server/adapters/memory/customer.ts +458 -0
- package/server/adapters/memory/demo-menu.json +1190 -0
- package/server/adapters/memory/demoImages.ts +13 -0
- package/server/adapters/memory/demoMenu.ts +234 -0
- package/server/adapters/memory/demoNavigation.ts +71 -0
- package/server/adapters/memory/index.ts +122 -0
- package/server/adapters/memory/navigation.ts +168 -0
- package/server/adapters/memory/ordering.ts +379 -0
- package/server/adapters/memory/seed.ts +136 -0
- package/server/adapters/memory/wishlist.ts +166 -0
- package/server/adapters/notImplemented.ts +67 -0
- package/server/adapters/registry.ts +32 -0
- package/server/adapters/runtimeConfig.ts +14 -0
- package/server/adapters/shopware/cart.ts +792 -0
- package/server/adapters/shopware/catalog.ts +850 -0
- package/server/adapters/shopware/checkout.ts +138 -0
- package/server/adapters/shopware/contact.ts +255 -0
- package/server/adapters/shopware/customer.ts +460 -0
- package/server/adapters/shopware/index.ts +165 -0
- package/server/adapters/shopware/menuRoot.ts +24 -0
- package/server/adapters/shopware/navigation.ts +426 -0
- package/server/adapters/shopware/ordering.ts +1185 -0
- package/server/adapters/shopware/request.ts +67 -0
- package/server/adapters/shopware/shop.ts +249 -0
- package/server/adapters/shopware/storeApi.ts +62 -0
- package/server/adapters/shopware/wishlist.ts +473 -0
- package/server/api/__sitemap__/urls.get.ts +10 -38
- package/server/api/account/addresses/[addressId]/default.post.ts +13 -0
- package/server/api/account/addresses/[addressId].delete.ts +14 -0
- package/server/api/account/addresses/[addressId].patch.ts +15 -0
- package/server/api/account/addresses/index.get.ts +6 -0
- package/server/api/account/addresses/index.post.ts +9 -0
- package/server/api/account/email.post.ts +10 -0
- package/server/api/account/index.delete.ts +11 -0
- package/server/api/account/index.get.ts +9 -0
- package/server/api/account/login.post.ts +14 -0
- package/server/api/account/logout.post.ts +11 -0
- package/server/api/account/orders.get.ts +13 -0
- package/server/api/account/password-reset/confirm.post.ts +13 -0
- package/server/api/account/password-reset.post.ts +16 -0
- package/server/api/account/password.post.ts +18 -0
- package/server/api/account/profile.patch.ts +6 -0
- package/server/api/account/register/confirm.post.ts +13 -0
- package/server/api/account/register.post.ts +15 -0
- package/server/api/breadcrumb/[sectionId].get.ts +33 -0
- package/server/api/cart/index.get.ts +4 -0
- package/server/api/cart/lines/[lineId].delete.ts +6 -0
- package/server/api/cart/lines/[lineId].patch.ts +10 -0
- package/server/api/cart/lines.post.ts +10 -0
- package/server/api/cart/vouchers/[code].delete.ts +9 -0
- package/server/api/cart/vouchers.post.ts +12 -0
- package/server/api/checkout/guest.post.ts +13 -0
- package/server/api/checkout/orderer/addresses/[addressId].patch.ts +16 -0
- package/server/api/checkout/orderer.get.ts +10 -0
- package/server/api/checkout/orders.post.ts +60 -0
- package/server/api/checkout/payment-methods.get.ts +9 -0
- package/server/api/checkout/selection.get.ts +10 -0
- package/server/api/checkout/selection.post.ts +14 -0
- package/server/api/checkout/shipping-methods.get.ts +9 -0
- package/server/api/contact/form.get.ts +13 -0
- package/server/api/contact/index.post.ts +24 -0
- package/server/api/listing/[sectionId].get.ts +33 -0
- package/server/api/menu/dishes/[dishId]/variant.get.ts +29 -0
- package/server/api/menu/dishes/[dishId].get.ts +19 -0
- package/server/api/menu/dishes/index.get.ts +26 -0
- package/server/api/menu/media/[name].get.ts +18 -0
- package/server/api/menu/root.get.ts +12 -0
- package/server/api/menu/sections/[sectionId].get.ts +18 -0
- package/server/api/menu/upsell.get.ts +12 -0
- package/server/api/navigation/[kind].get.ts +75 -0
- package/server/api/orders/[orderId]/payment.post.ts +24 -0
- package/server/api/orders/[orderId].get.ts +13 -0
- package/server/api/payment-methods.get.ts +11 -15
- package/server/api/resolve-path.get.ts +20 -0
- package/server/api/search.get.ts +16 -80
- package/server/api/session.post.ts +18 -0
- package/server/api/shop/branches.get.ts +9 -0
- package/server/api/shop/config.get.ts +9 -0
- package/server/api/shop/holidays.get.ts +9 -0
- package/server/api/shop/opening-hours.get.ts +9 -0
- package/server/api/top-sellers.get.ts +14 -50
- package/server/api/wishlist/entries/[entryId].delete.ts +8 -0
- package/server/api/wishlist/entries.post.ts +13 -0
- package/server/api/wishlist/index.get.ts +13 -0
- package/server/api/wishlist/merge.post.ts +12 -0
- package/server/plugins/visitor-session.ts +35 -0
- package/server/ports/CartPort.ts +48 -0
- package/server/ports/CatalogPort.ts +66 -0
- package/server/ports/CheckoutPort.ts +128 -0
- package/server/ports/ContactPort.ts +38 -0
- package/server/ports/CustomerPort.ts +154 -0
- package/server/ports/NavigationPort.ts +58 -0
- package/server/ports/OrderPort.ts +31 -0
- package/server/ports/ShopPort.ts +29 -0
- package/server/ports/WishlistPort.ts +47 -0
- package/server/ports/index.ts +42 -0
- package/server/ports/session.ts +22 -0
- package/server/routes/llms.txt.ts +28 -154
- package/server/session/forwardedFor.ts +24 -0
- package/server/session/sameOrigin.ts +47 -0
- package/server/session/seal.ts +147 -0
- package/server/session/visitorSession.ts +288 -0
- package/server/utils/accountRoutes.ts +173 -0
- package/server/utils/backend.ts +21 -0
- package/server/utils/backoff.ts +18 -5
- package/server/utils/cacheKeys.ts +11 -0
- package/server/utils/cachePurge.ts +47 -27
- package/server/utils/cartRoutes.ts +124 -0
- package/server/utils/catalogData.ts +24 -0
- package/server/utils/checkoutRoutes.ts +326 -0
- package/server/utils/contactRoutes.ts +86 -0
- package/server/utils/domainHttp.ts +73 -0
- package/server/utils/listingParams.ts +49 -20
- package/server/utils/llmsTxt.ts +64 -19
- package/server/utils/navigationData.ts +14 -0
- package/server/utils/orderPlacement.ts +322 -0
- package/server/utils/outageBreaker.ts +126 -0
- package/server/utils/pathRoutes.ts +160 -0
- package/server/utils/requestBody.ts +43 -0
- package/server/utils/shopData.ts +132 -0
- package/server/utils/sitemap.ts +14 -36
- package/server/utils/storeApi.ts +71 -23
- package/server/utils/visitorSession.ts +209 -0
- package/server/utils/wishlistRoutes.ts +55 -0
- package/shared/domain/customer/index.ts +2 -0
- package/shared/domain/customer/types.ts +88 -0
- package/shared/domain/discoverability/index.ts +4 -0
- package/shared/domain/discoverability/paths.ts +93 -0
- package/shared/domain/discoverability/route.ts +32 -0
- package/shared/domain/discoverability/types.ts +75 -0
- package/shared/domain/index.ts +11 -0
- package/shared/domain/kernel/calendar.ts +88 -0
- package/shared/domain/kernel/errors.ts +100 -0
- package/shared/domain/kernel/freeze.ts +13 -0
- package/shared/domain/kernel/ids.ts +6 -0
- package/shared/domain/kernel/index.ts +8 -0
- package/shared/domain/kernel/media.ts +17 -0
- package/shared/domain/kernel/money.ts +104 -0
- package/shared/domain/kernel/timeOfDay.ts +39 -0
- package/shared/domain/menu/dishConfiguration.ts +72 -0
- package/shared/domain/menu/index.ts +3 -0
- package/shared/domain/menu/types.ts +185 -0
- package/shared/domain/ordering/index.ts +3 -0
- package/shared/domain/ordering/time.ts +114 -0
- package/shared/domain/ordering/types.ts +195 -0
- package/shared/domain/restaurant/holiday.ts +38 -0
- package/shared/domain/restaurant/index.ts +4 -0
- package/shared/domain/restaurant/openingInterval.ts +97 -0
- package/shared/domain/restaurant/types.ts +75 -0
- package/test/a11y/presets.test.ts +49 -31
- package/test/contract/cart.contract.ts +592 -0
- package/test/contract/cart.spec.ts +5 -0
- package/test/contract/cartFixtures.ts +573 -0
- package/test/contract/catalog.contract.ts +714 -0
- package/test/contract/catalog.spec.ts +5 -0
- package/test/contract/catalogFixtures.ts +572 -0
- package/test/contract/checkout.contract.ts +123 -0
- package/test/contract/checkout.spec.ts +5 -0
- package/test/contract/contact.contract.ts +149 -0
- package/test/contract/contact.spec.ts +4 -0
- package/test/contract/contactFixtures.ts +148 -0
- package/test/contract/customer.contract.ts +831 -0
- package/test/contract/customer.spec.ts +4 -0
- package/test/contract/customerFixtures.ts +468 -0
- package/test/contract/fixtures.ts +260 -0
- package/test/contract/harness.ts +45 -0
- package/test/contract/navigation.contract.ts +336 -0
- package/test/contract/navigation.spec.ts +5 -0
- package/test/contract/navigationFixtures.ts +311 -0
- package/test/contract/ordering.contract.ts +655 -0
- package/test/contract/ordering.spec.ts +4 -0
- package/test/contract/orderingFixtures.ts +498 -0
- package/test/contract/shop.contract.ts +164 -0
- package/test/contract/shop.spec.ts +5 -0
- package/test/contract/wishlist.contract.ts +375 -0
- package/test/contract/wishlist.spec.ts +4 -0
- package/test/contract/wishlistFixtures.ts +199 -0
- package/test/nuxt/AccountPagesPreset.test.ts +320 -83
- package/test/nuxt/AuthPagesPreset.test.ts +17 -24
- package/test/nuxt/CartBar.test.ts +12 -8
- package/test/nuxt/CartCheckoutPreset.test.ts +36 -33
- package/test/nuxt/CartItem.test.ts +39 -20
- package/test/nuxt/CartQuickView.test.ts +106 -0
- package/test/nuxt/CartUpsell.test.ts +37 -39
- package/test/nuxt/CategoryBreadcrumb.test.ts +26 -0
- package/test/nuxt/CheckoutFormsPreset.test.ts +92 -13
- package/test/nuxt/CheckoutOnePage.test.ts +28 -21
- package/test/nuxt/CheckoutPageMessage.test.ts +31 -0
- package/test/nuxt/CheckoutSummary.test.ts +163 -48
- package/test/nuxt/CheckoutVoucherInput.test.ts +77 -80
- package/test/nuxt/ContactFormPreset.test.ts +97 -36
- package/test/nuxt/DeliveryTimeSelect.test.ts +72 -45
- package/test/nuxt/FooterStoreStatus.test.ts +2 -2
- package/test/nuxt/HeaderFooterPreset.test.ts +11 -19
- package/test/nuxt/HomeCategories.test.ts +47 -0
- package/test/nuxt/HomeLeadTimes.test.ts +3 -3
- package/test/nuxt/MenuBonCard.test.ts +45 -32
- package/test/nuxt/NavigationMobileTop.test.ts +30 -28
- package/test/nuxt/OrderPagesPreset.test.ts +83 -52
- package/test/nuxt/PaymentAndDelivery.test.ts +25 -26
- package/test/nuxt/ProductConfigurator.test.ts +81 -0
- package/test/nuxt/ProductCrossSelling.test.ts +23 -20
- package/test/nuxt/ProductDeselectIngredient.test.ts +6 -9
- package/test/nuxt/ProductFoodLabels.test.ts +7 -24
- package/test/nuxt/ProductSheetPreset.test.ts +24 -24
- package/test/nuxt/RegisterConfirmPage.test.ts +26 -45
- package/test/nuxt/RegistrationForm.test.ts +57 -53
- package/test/nuxt/RegistrationPage.test.ts +37 -0
- package/test/nuxt/WishlistPage.test.ts +119 -43
- package/test/nuxt/WishlistSaveButton.test.ts +39 -12
- package/test/nuxt/accountSwitch.test.ts +106 -0
- package/test/nuxt/bffWrite.test.ts +41 -0
- package/test/nuxt/liveShopData.test.ts +36 -68
- package/test/nuxt/shopwareLayerOffline.test.ts +32 -0
- package/test/nuxt/useAddToCart.test.ts +142 -115
- package/test/nuxt/useCartMutations.test.ts +165 -113
- package/test/nuxt/useCartUpsell.test.ts +36 -63
- package/test/nuxt/useCategoryListing.test.ts +75 -118
- package/test/nuxt/useCheckoutMethodGuard.test.ts +54 -105
- package/test/nuxt/useCustomer.test.ts +127 -0
- package/test/nuxt/useDeliveryTime.test.ts +169 -157
- package/test/nuxt/useNavigation.test.ts +81 -0
- package/test/nuxt/useOpeningHoursData.test.ts +18 -18
- package/test/nuxt/useOrder.test.ts +38 -0
- package/test/nuxt/usePlaceOrder.test.ts +88 -0
- package/test/nuxt/useSearchTracking.test.ts +2 -2
- package/test/nuxt/useSectionRoute.test.ts +86 -0
- package/test/nuxt/useShippingLeadTime.test.ts +17 -17
- package/test/nuxt/useShippingMethodChoice.test.ts +22 -22
- package/test/nuxt/useShippingMethods.test.ts +71 -0
- package/test/nuxt/useShopConfig.test.ts +64 -0
- package/test/nuxt/useStoreStatus.test.ts +34 -50
- package/test/nuxt/useTopSellers.test.ts +6 -5
- package/test/nuxt/useTrackEvent.test.ts +68 -6
- package/test/nuxt/useWishlistEntries.test.ts +392 -128
- package/test/support/cart.ts +43 -0
- package/test/support/dishes.ts +116 -0
- package/test/support/navigation.ts +17 -0
- package/test/unit/accountMessages.spec.ts +53 -0
- package/test/unit/accountRoutes.spec.ts +637 -0
- package/test/unit/adapters/memoryCustomer.spec.ts +67 -0
- package/test/unit/adapters/memoryDemoMenu.spec.ts +174 -0
- package/test/unit/adapters/registry.spec.ts +100 -0
- package/test/unit/adapters/shopwareCart.spec.ts +636 -0
- package/test/unit/adapters/shopwareCatalog.spec.ts +486 -0
- package/test/unit/adapters/shopwareCheckout.spec.ts +197 -0
- package/test/unit/adapters/shopwareContact.spec.ts +296 -0
- package/test/unit/adapters/shopwareCustomer.spec.ts +256 -0
- package/test/unit/adapters/shopwareNavigation.spec.ts +594 -0
- package/test/unit/adapters/shopwareOrdering.spec.ts +620 -0
- package/test/unit/adapters/shopwareShop.spec.ts +259 -0
- package/test/unit/adapters/shopwareWishlist.spec.ts +306 -0
- package/test/unit/adapters/useBackend.spec.ts +41 -0
- package/test/unit/backoff.spec.ts +47 -0
- package/test/unit/boundedCache.spec.ts +59 -59
- package/test/unit/cacheKeys.spec.ts +44 -0
- package/test/unit/cachePurge.spec.ts +44 -19
- package/test/unit/cartRoutes.spec.ts +567 -0
- package/test/unit/catalogRoutes.spec.ts +287 -0
- package/test/unit/checkoutRoutes.spec.ts +545 -0
- package/test/unit/dish.spec.ts +128 -0
- package/test/unit/domain/discoverability.spec.ts +154 -0
- package/test/unit/domain/dishConfiguration.spec.ts +85 -0
- package/test/unit/domain/money.spec.ts +102 -0
- package/test/unit/domain/time.spec.ts +336 -0
- package/test/unit/domainHttp.spec.ts +74 -0
- package/test/unit/forwardedFor.spec.ts +24 -0
- package/test/unit/layoutCacheRoutes.spec.ts +47 -471
- package/test/unit/leadTime.spec.ts +28 -23
- package/test/unit/llmsTxt.spec.ts +120 -9
- package/test/unit/media.spec.ts +25 -26
- package/test/unit/menuGroups.spec.ts +31 -21
- package/test/unit/navigationRoutes.spec.ts +648 -0
- package/test/unit/nitroStubs.ts +6 -1
- package/test/unit/openingHours.spec.ts +57 -34
- package/test/unit/orderPlacement.spec.ts +362 -0
- package/test/unit/outageBreaker.spec.ts +213 -0
- package/test/unit/productUrl.spec.ts +10 -28
- package/test/unit/requestBody.spec.ts +56 -0
- package/test/unit/restaurantTime.spec.ts +295 -0
- package/test/unit/schema.spec.ts +58 -26
- package/test/unit/session/sameOrigin.spec.ts +76 -0
- package/test/unit/session/seal.spec.ts +128 -0
- package/test/unit/session/visitorSession.spec.ts +439 -0
- package/test/unit/shopRoutes.spec.ts +257 -0
- package/test/unit/sitemap.spec.ts +11 -47
- package/test/unit/storeApiForVisitor.spec.ts +109 -0
- package/test/unit/useCategorySeo.spec.ts +57 -31
- package/test/unit/wishlistContactRoutes.spec.ts +607 -0
- package/vitest.config.ts +5 -1
- package/app/components/SalesChannelSwitch.vue +0 -73
- package/app/composables/useBusinessHours.ts +0 -192
- package/app/composables/useCategoryById.ts +0 -10
- package/app/composables/useNavigationSearch.ts +0 -45
- package/app/composables/useProductConfigurator.ts +0 -70
- package/app/composables/useProductCrossSelling.ts +0 -42
- package/app/composables/useProductVariants.ts +0 -61
- package/app/composables/useProductVariantsZwei.ts +0 -62
- package/app/composables/useSeoUrlRoute.ts +0 -124
- package/app/composables/useShopBiteConfig.ts +0 -69
- package/app/composables/useSyncWishlist.ts +0 -119
- package/app/types/Association.d.ts +0 -14
- package/app/utils/product.ts +0 -139
- package/app/utils/seoPath.ts +0 -68
- package/app/utils/time.ts +0 -20
- package/server/api/breadcrumb/[categoryId].get.ts +0 -31
- package/server/api/category/[categoryId].get.ts +0 -37
- package/server/api/listing/[categoryId].get.ts +0 -102
- package/server/api/navigation/[type].get.ts +0 -97
- package/server/api/product/[productId]/cross-selling.get.ts +0 -26
- package/server/api/product/[productId].get.ts +0 -76
- package/server/api/product/variant.get.ts +0 -98
- package/server/api/seo-url/index.get.ts +0 -17
- package/server/api/seo-url/known.get.ts +0 -33
- package/server/api/shopbite/business-hours.get.ts +0 -22
- package/server/api/shopbite/config.get.ts +0 -6
- package/server/api/shopbite/holidays.get.ts +0 -20
- package/server/utils/menuRoot.ts +0 -31
- package/server/utils/seoPaths.ts +0 -130
- package/server/utils/seoUrlCache.ts +0 -98
- package/server/utils/shopBiteConfig.ts +0 -30
- package/test/nuxt/useBusinessHours.test.ts +0 -106
- package/test/nuxt/useProductConfigurator.test.ts +0 -87
- package/test/nuxt/useProductVariants.test.ts +0 -95
- package/test/nuxt/useProductVariantsZwei.test.ts +0 -52
- package/test/nuxt/useSeoUrlRoute.test.ts +0 -176
- package/test/nuxt/useShopBiteConfig.test.ts +0 -131
- package/test/nuxt/useSyncWishlist.test.ts +0 -85
- package/test/unit/product.spec.ts +0 -160
- package/test/unit/seoPath.spec.ts +0 -161
- package/test/unit/seoPaths.spec.ts +0 -117
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The Store API outage breaker (step 6 review): it opens only after two
|
|
5
|
+
* requests without an answer (deadline, no connection) within 15 s with
|
|
6
|
+
* no answer between, and then fails requests at once for 30 s; any answer
|
|
7
|
+
* closes it. Other errors never count. The order placement and its
|
|
8
|
+
* follow-up look-ups bypass it and never open it.
|
|
9
|
+
*/
|
|
10
|
+
const timeout = () =>
|
|
11
|
+
Object.assign(new Error("[POST] <no response> aborted due to timeout"), {
|
|
12
|
+
name: "FetchError",
|
|
13
|
+
cause: Object.assign(new Error("timeout"), { name: "TimeoutError" }),
|
|
14
|
+
});
|
|
15
|
+
const refused = () =>
|
|
16
|
+
Object.assign(new Error("[GET] <no response> fetch failed"), {
|
|
17
|
+
name: "FetchError",
|
|
18
|
+
cause: Object.assign(new TypeError("fetch failed"), {
|
|
19
|
+
cause: { code: "ECONNREFUSED" },
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
const refusal = () =>
|
|
23
|
+
Object.assign(new Error("[POST] 400"), {
|
|
24
|
+
name: "FetchError",
|
|
25
|
+
statusCode: 400,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
vi.resetModules();
|
|
30
|
+
vi.useFakeTimers({ toFake: ["Date"] });
|
|
31
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:00Z"));
|
|
32
|
+
});
|
|
33
|
+
afterEach(() => {
|
|
34
|
+
vi.useRealTimers();
|
|
35
|
+
vi.unstubAllGlobals();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
async function breaker() {
|
|
39
|
+
return import("../../server/utils/outageBreaker");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const fails = (error: unknown) => () => Promise.reject(error);
|
|
43
|
+
const answers = () => Promise.resolve("answer");
|
|
44
|
+
|
|
45
|
+
describe("outage breaker", () => {
|
|
46
|
+
it("stays closed after one request without an answer", async () => {
|
|
47
|
+
const { guardedRequest } = await breaker();
|
|
48
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
49
|
+
await expect(guardedRequest(answers)).resolves.toBe("answer");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("opens after two within 15 s and fails fast for 30 s", async () => {
|
|
53
|
+
const { guardedRequest } = await breaker();
|
|
54
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
55
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:10Z"));
|
|
56
|
+
await expect(guardedRequest(fails(refused()))).rejects.toThrow();
|
|
57
|
+
const request = vi.fn(answers);
|
|
58
|
+
await expect(guardedRequest(request)).rejects.toMatchObject({
|
|
59
|
+
statusCode: 503,
|
|
60
|
+
});
|
|
61
|
+
expect(request).not.toHaveBeenCalled();
|
|
62
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:41Z"));
|
|
63
|
+
await expect(guardedRequest(request)).resolves.toBe("answer");
|
|
64
|
+
// closed by the answer: one more failure does not open it again
|
|
65
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
66
|
+
await expect(guardedRequest(answers)).resolves.toBe("answer");
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("lets one request through 10 s after the last probe and closes at its answer", async () => {
|
|
70
|
+
const { guardedRequest } = await breaker();
|
|
71
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
72
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
73
|
+
const request = vi.fn(answers);
|
|
74
|
+
await expect(guardedRequest(request)).rejects.toMatchObject({
|
|
75
|
+
statusCode: 503,
|
|
76
|
+
});
|
|
77
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:05Z"));
|
|
78
|
+
await expect(guardedRequest(request)).rejects.toMatchObject({
|
|
79
|
+
statusCode: 503,
|
|
80
|
+
});
|
|
81
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:10Z"));
|
|
82
|
+
// Shopware is back: the probe answers and the breaker closes
|
|
83
|
+
await expect(guardedRequest(request)).resolves.toBe("answer");
|
|
84
|
+
await expect(guardedRequest(request)).resolves.toBe("answer");
|
|
85
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("keeps failing fast when the probe finds no answer either", async () => {
|
|
89
|
+
const { guardedRequest } = await breaker();
|
|
90
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
91
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
92
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:25Z"));
|
|
93
|
+
const probe = vi.fn(fails(timeout()));
|
|
94
|
+
await expect(guardedRequest(probe)).rejects.toThrow();
|
|
95
|
+
expect(probe).toHaveBeenCalledTimes(1);
|
|
96
|
+
const next = vi.fn(answers);
|
|
97
|
+
await expect(guardedRequest(next)).rejects.toMatchObject({
|
|
98
|
+
statusCode: 503,
|
|
99
|
+
});
|
|
100
|
+
expect(next).not.toHaveBeenCalled();
|
|
101
|
+
// a long outage: the failed probe keeps it open past the first 30 s
|
|
102
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:31Z"));
|
|
103
|
+
await expect(guardedRequest(next)).rejects.toMatchObject({
|
|
104
|
+
statusCode: 503,
|
|
105
|
+
});
|
|
106
|
+
expect(next).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("never lets a second probe through while one is in flight", async () => {
|
|
110
|
+
const { guardedRequest } = await breaker();
|
|
111
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
112
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
113
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:10Z"));
|
|
114
|
+
let finish!: () => void;
|
|
115
|
+
const slow = guardedRequest(
|
|
116
|
+
() =>
|
|
117
|
+
new Promise<string>((_, reject) => {
|
|
118
|
+
finish = () => reject(timeout());
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:25Z"));
|
|
122
|
+
const other = vi.fn(answers);
|
|
123
|
+
await expect(guardedRequest(other)).rejects.toMatchObject({
|
|
124
|
+
statusCode: 503,
|
|
125
|
+
});
|
|
126
|
+
expect(other).not.toHaveBeenCalled();
|
|
127
|
+
finish();
|
|
128
|
+
await expect(slow).rejects.toThrow();
|
|
129
|
+
// the next probe waits 10 s after this one ended
|
|
130
|
+
await expect(guardedRequest(other)).rejects.toMatchObject({
|
|
131
|
+
statusCode: 503,
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("does not count failures further apart than 15 s", async () => {
|
|
136
|
+
const { guardedRequest } = await breaker();
|
|
137
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
138
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:16Z"));
|
|
139
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
140
|
+
await expect(guardedRequest(answers)).resolves.toBe("answer");
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("is reset by any answer between, also a refusal", async () => {
|
|
144
|
+
const { guardedRequest } = await breaker();
|
|
145
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
146
|
+
await expect(guardedRequest(fails(refusal()))).rejects.toThrow();
|
|
147
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
148
|
+
await expect(guardedRequest(answers)).resolves.toBe("answer");
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("never counts errors that are no missing answer", async () => {
|
|
152
|
+
const { guardedRequest } = await breaker();
|
|
153
|
+
await expect(
|
|
154
|
+
guardedRequest(fails(new SyntaxError("Unexpected token < in JSON"))),
|
|
155
|
+
).rejects.toThrow();
|
|
156
|
+
await expect(
|
|
157
|
+
guardedRequest(fails(new TypeError("x is not a function"))),
|
|
158
|
+
).rejects.toThrow();
|
|
159
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
160
|
+
await expect(guardedRequest(answers)).resolves.toBe("answer");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("lets the order placement and its look-ups pass and never opens for them", async () => {
|
|
164
|
+
const { guardedRequest, bypassOutageBreaker } = await breaker();
|
|
165
|
+
// a slow order and its look-up do not open it
|
|
166
|
+
await expect(
|
|
167
|
+
bypassOutageBreaker(() => guardedRequest(fails(timeout()))),
|
|
168
|
+
).rejects.toThrow();
|
|
169
|
+
await expect(
|
|
170
|
+
bypassOutageBreaker(() => guardedRequest(fails(timeout()))),
|
|
171
|
+
).rejects.toThrow();
|
|
172
|
+
await expect(guardedRequest(answers)).resolves.toBe("answer");
|
|
173
|
+
// open for everybody else, the order's look-up still asks
|
|
174
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
175
|
+
await expect(guardedRequest(fails(timeout()))).rejects.toThrow();
|
|
176
|
+
await expect(guardedRequest(answers)).rejects.toMatchObject({
|
|
177
|
+
statusCode: 503,
|
|
178
|
+
});
|
|
179
|
+
await expect(
|
|
180
|
+
bypassOutageBreaker(() => guardedRequest(answers)),
|
|
181
|
+
).resolves.toBe("answer");
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe("Store API utils behind the breaker", () => {
|
|
186
|
+
it("fail fast while it is open and ask again after it", async () => {
|
|
187
|
+
let down = true;
|
|
188
|
+
const plain = vi.fn(async () => {
|
|
189
|
+
if (down) throw timeout();
|
|
190
|
+
return {};
|
|
191
|
+
});
|
|
192
|
+
const raw = vi.fn(async () => ({ _data: {}, headers: new Headers() }));
|
|
193
|
+
vi.stubGlobal("$fetch", Object.assign(plain, { raw }));
|
|
194
|
+
vi.stubGlobal("useRuntimeConfig", () => ({
|
|
195
|
+
shopware: { endpoint: "" },
|
|
196
|
+
public: {
|
|
197
|
+
shopware: { endpoint: "http://shopware/store-api", accessToken: "k" },
|
|
198
|
+
},
|
|
199
|
+
}));
|
|
200
|
+
const { storeApiGet, storeApiPost, storeApiForVisitor } =
|
|
201
|
+
await import("../../server/utils/storeApi");
|
|
202
|
+
await expect(storeApiGet("/context")).rejects.toThrow();
|
|
203
|
+
await expect(storeApiPost("/product", {})).rejects.toThrow();
|
|
204
|
+
expect(plain).toHaveBeenCalledTimes(2);
|
|
205
|
+
await expect(
|
|
206
|
+
storeApiForVisitor({ method: "POST", path: "/account/customer" }),
|
|
207
|
+
).rejects.toMatchObject({ statusCode: 503 });
|
|
208
|
+
expect(raw).not.toHaveBeenCalled();
|
|
209
|
+
down = false;
|
|
210
|
+
vi.setSystemTime(new Date("2026-11-22T12:00:31Z"));
|
|
211
|
+
await expect(storeApiGet("/context")).resolves.toEqual({});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -1,49 +1,31 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
parseListParam,
|
|
4
|
-
|
|
4
|
+
dishLink,
|
|
5
5
|
withQuickViewConfiguration,
|
|
6
6
|
} from "../../app/utils/productUrl";
|
|
7
7
|
|
|
8
|
-
describe("
|
|
9
|
-
it("uses the
|
|
8
|
+
describe("dishLink", () => {
|
|
9
|
+
it("uses the dish's own link when the backend keeps one", () => {
|
|
10
10
|
expect(
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
productNumber: "LF-21",
|
|
14
|
-
seoUrls: [
|
|
15
|
-
{ seoPathInfo: "Pizza-Margherita/LF-21", isCanonical: false },
|
|
16
|
-
{
|
|
17
|
-
seoPathInfo: "Speisekarte/Pizza/?produkt=LF-21",
|
|
18
|
-
isCanonical: true,
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
},
|
|
11
|
+
dishLink(
|
|
12
|
+
{ number: "LF-21", path: "/Speisekarte/Pizza/?produkt=LF-21" },
|
|
22
13
|
"/Speisekarte/Nudeln/",
|
|
23
14
|
),
|
|
24
15
|
).toBe("/Speisekarte/Pizza/?produkt=LF-21");
|
|
25
16
|
});
|
|
26
17
|
|
|
27
|
-
it("
|
|
18
|
+
it("opens the dish's sheet over its section otherwise", () => {
|
|
28
19
|
expect(
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
productNumber: "LF-21",
|
|
32
|
-
seoUrls: [
|
|
33
|
-
{ seoPathInfo: "Pizza-Margherita/LF-21", isCanonical: true },
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
"/Speisekarte/Pizza/",
|
|
37
|
-
),
|
|
20
|
+
dishLink({ number: "LF-21", path: null }, "/Speisekarte/Pizza/"),
|
|
38
21
|
).toBe("/Speisekarte/Pizza/?produkt=LF-21");
|
|
39
|
-
expect(
|
|
22
|
+
expect(dishLink({ number: "A 1/2", path: null }, "c/Pizza/")).toBe(
|
|
40
23
|
"/c/Pizza/?produkt=A+1%2F2",
|
|
41
24
|
);
|
|
42
25
|
});
|
|
43
26
|
|
|
44
|
-
it("is undefined without
|
|
45
|
-
expect(
|
|
46
|
-
expect(productDeepLink({}, "/c/Pizza/")).toBeUndefined();
|
|
27
|
+
it("is undefined without a link and a section", () => {
|
|
28
|
+
expect(dishLink({ number: "LF-21", path: null })).toBeUndefined();
|
|
47
29
|
});
|
|
48
30
|
});
|
|
49
31
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { stubNitro } from "./nitroStubs";
|
|
4
|
+
|
|
5
|
+
type Event = {
|
|
6
|
+
headers: Record<string, string>;
|
|
7
|
+
node: { req: unknown };
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type Refusal = { statusCode: number; data: unknown };
|
|
11
|
+
|
|
12
|
+
async function readSmall(event: Event, max?: number): Promise<unknown> {
|
|
13
|
+
stubNitro({
|
|
14
|
+
getRequestHeader: (given: Event, name: string) => given.headers[name],
|
|
15
|
+
readBody: async () => "parsed",
|
|
16
|
+
});
|
|
17
|
+
const { readSmallBody } = await import("../../server/utils/requestBody");
|
|
18
|
+
return readSmallBody(event as never, max);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const streamed = (text: string, headers: Record<string, string> = {}) => ({
|
|
22
|
+
headers,
|
|
23
|
+
node: { req: Readable.from([Buffer.from(text)]) },
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
vi.unstubAllGlobals();
|
|
28
|
+
vi.resetModules();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("readSmallBody", () => {
|
|
32
|
+
it("parses a small JSON body", async () => {
|
|
33
|
+
expect(await readSmall(streamed('{"a":1}'))).toEqual({ a: 1 });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("refuses a declared length above the cap before reading", async () => {
|
|
37
|
+
const error = (await readSmall(
|
|
38
|
+
streamed("{}", { "content-length": "11" }),
|
|
39
|
+
10,
|
|
40
|
+
).catch((failure: Refusal) => failure)) as Refusal;
|
|
41
|
+
expect(error.statusCode).toBe(413);
|
|
42
|
+
expect(error.data).toEqual({ code: "payload_too_large" });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("refuses a body that grows above the cap while it streams in", async () => {
|
|
46
|
+
const error = (await readSmall(streamed("x".repeat(100)), 10).catch(
|
|
47
|
+
(failure: Refusal) => failure,
|
|
48
|
+
)) as Refusal;
|
|
49
|
+
expect(error.statusCode).toBe(413);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("answers no body for an empty one or no JSON", async () => {
|
|
53
|
+
expect(await readSmall(streamed(""))).toBeUndefined();
|
|
54
|
+
expect(await readSmall(streamed("nicht json"))).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
firstSlot,
|
|
4
|
+
formatClock,
|
|
5
|
+
formatClosing,
|
|
6
|
+
minutesInWindow,
|
|
7
|
+
restaurantNow,
|
|
8
|
+
servicePeriodsOn,
|
|
9
|
+
serviceSpans,
|
|
10
|
+
storeStatusAt,
|
|
11
|
+
wishedTimeWindow,
|
|
12
|
+
} from "../../app/utils/restaurantTime";
|
|
13
|
+
import {
|
|
14
|
+
holiday,
|
|
15
|
+
openingInterval,
|
|
16
|
+
sortOpeningHours,
|
|
17
|
+
type ServiceSchedule,
|
|
18
|
+
type Weekday,
|
|
19
|
+
} from "../../shared/domain";
|
|
20
|
+
|
|
21
|
+
const hours = (rows: [Weekday, string, string][]) =>
|
|
22
|
+
sortOpeningHours(
|
|
23
|
+
rows.map(([weekday, opens, closes]) => ({
|
|
24
|
+
weekday,
|
|
25
|
+
interval: openingInterval(opens, closes),
|
|
26
|
+
})),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A restaurant in Berlin: lunch and dinner Wednesday to Friday, Friday
|
|
31
|
+
* night until 01:30 (split at midnight like the domain keeps it), Saturday
|
|
32
|
+
* dinner, Sunday until the end of the day, closed Monday and Tuesday.
|
|
33
|
+
*/
|
|
34
|
+
const SCHEDULE: ServiceSchedule = {
|
|
35
|
+
timeZone: "Europe/Berlin",
|
|
36
|
+
openingHours: hours([
|
|
37
|
+
[3, "11:30", "14:30"],
|
|
38
|
+
[3, "17:30", "23:00"],
|
|
39
|
+
[4, "11:30", "14:30"],
|
|
40
|
+
[4, "17:30", "23:00"],
|
|
41
|
+
[5, "11:30", "14:30"],
|
|
42
|
+
[5, "17:00", "24:00"],
|
|
43
|
+
[6, "00:00", "01:30"],
|
|
44
|
+
[6, "17:00", "23:00"],
|
|
45
|
+
[7, "12:00", "24:00"],
|
|
46
|
+
]),
|
|
47
|
+
holidays: [],
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** A Berlin wall-clock time in November 2026 (UTC+1). */
|
|
51
|
+
const berlin = (day: number, time: string) =>
|
|
52
|
+
new Date(`2026-11-${String(day).padStart(2, "0")}T${time}:00+01:00`);
|
|
53
|
+
// 2026-11-18 is a Wednesday, 20 a Friday, 21 a Saturday, 23 a Monday.
|
|
54
|
+
|
|
55
|
+
describe("restaurantNow", () => {
|
|
56
|
+
it("reads date, weekday and time in the restaurant's time zone", () => {
|
|
57
|
+
// 23:30 UTC on Friday is already Saturday 00:30 in Berlin
|
|
58
|
+
expect(
|
|
59
|
+
restaurantNow(new Date("2026-11-20T23:30:00Z"), "Europe/Berlin"),
|
|
60
|
+
).toEqual({ date: "2026-11-21", weekday: 6, minutes: 30 });
|
|
61
|
+
expect(
|
|
62
|
+
restaurantNow(new Date("2026-11-20T23:30:00Z"), "America/New_York"),
|
|
63
|
+
).toEqual({ date: "2026-11-20", weekday: 5, minutes: 18 * 60 + 30 });
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe("serviceSpans", () => {
|
|
68
|
+
it("joins a late-night opening that the domain split at midnight", () => {
|
|
69
|
+
expect(serviceSpans(SCHEDULE.openingHours, 5)).toEqual([
|
|
70
|
+
{ opens: 690, closes: 870 },
|
|
71
|
+
{ opens: 1020, closes: 1440 + 90 },
|
|
72
|
+
]);
|
|
73
|
+
// the continuation is Friday's, not an opening of its own on Saturday
|
|
74
|
+
expect(serviceSpans(SCHEDULE.openingHours, 6)).toEqual([
|
|
75
|
+
{ opens: 1020, closes: 1380 },
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("keeps an interval up to 24:00 without continuation as it is", () => {
|
|
80
|
+
expect(serviceSpans(SCHEDULE.openingHours, 7)).toEqual([
|
|
81
|
+
{ opens: 720, closes: 1440 },
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("does not join days that are open around the clock", () => {
|
|
86
|
+
const always = hours(
|
|
87
|
+
([1, 2, 3, 4, 5, 6, 7] as Weekday[]).map((day) => [
|
|
88
|
+
day,
|
|
89
|
+
"00:00",
|
|
90
|
+
"24:00",
|
|
91
|
+
]),
|
|
92
|
+
);
|
|
93
|
+
expect(serviceSpans(always, 3)).toEqual([{ opens: 0, closes: 1440 }]);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("servicePeriodsOn", () => {
|
|
98
|
+
it("carries yesterday's late-night span over midnight", () => {
|
|
99
|
+
expect(servicePeriodsOn(SCHEDULE, "2026-11-21")).toEqual([
|
|
100
|
+
{ opens: -420, closes: 90 },
|
|
101
|
+
{ opens: 1020, closes: 1380 },
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("serves nothing on a holiday, and not yesterday's span after a holiday", () => {
|
|
106
|
+
const friday = {
|
|
107
|
+
...SCHEDULE,
|
|
108
|
+
holidays: [
|
|
109
|
+
holiday({ id: "h", firstDay: "2026-11-20", lastDay: "2026-11-20" }),
|
|
110
|
+
],
|
|
111
|
+
};
|
|
112
|
+
expect(servicePeriodsOn(friday, "2026-11-20")).toEqual([]);
|
|
113
|
+
expect(servicePeriodsOn(friday, "2026-11-21")).toEqual([
|
|
114
|
+
{ opens: 1020, closes: 1380 },
|
|
115
|
+
]);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
describe("storeStatusAt", () => {
|
|
120
|
+
it("is open until the end of the current span", () => {
|
|
121
|
+
expect(storeStatusAt(berlin(18, "12:30"), SCHEDULE)).toEqual({
|
|
122
|
+
open: true,
|
|
123
|
+
closesAt: "14:30",
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("closes a late-night span after midnight", () => {
|
|
128
|
+
expect(storeStatusAt(berlin(20, "23:00"), SCHEDULE)).toEqual({
|
|
129
|
+
open: true,
|
|
130
|
+
closesAt: "01:30",
|
|
131
|
+
});
|
|
132
|
+
expect(storeStatusAt(berlin(21, "00:45"), SCHEDULE)).toEqual({
|
|
133
|
+
open: true,
|
|
134
|
+
closesAt: "01:30",
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("says 24:00 for a span up to the end of the day", () => {
|
|
139
|
+
expect(storeStatusAt(berlin(22, "20:00"), SCHEDULE)).toEqual({
|
|
140
|
+
open: true,
|
|
141
|
+
closesAt: "24:00",
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("names the next opening today, tomorrow or later", () => {
|
|
146
|
+
expect(storeStatusAt(berlin(18, "15:00"), SCHEDULE)).toEqual({
|
|
147
|
+
open: false,
|
|
148
|
+
nextOpening: "17:30 Uhr",
|
|
149
|
+
});
|
|
150
|
+
expect(storeStatusAt(berlin(18, "23:30"), SCHEDULE)).toEqual({
|
|
151
|
+
open: false,
|
|
152
|
+
nextOpening: "morgen um 11:30 Uhr",
|
|
153
|
+
});
|
|
154
|
+
expect(storeStatusAt(berlin(23, "10:00"), SCHEDULE)).toEqual({
|
|
155
|
+
open: false,
|
|
156
|
+
nextOpening: "Mittwoch, 25.11. um 11:30 Uhr",
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("skips holidays", () => {
|
|
161
|
+
const schedule = {
|
|
162
|
+
...SCHEDULE,
|
|
163
|
+
holidays: [
|
|
164
|
+
holiday({ id: "h", firstDay: "2026-11-18", lastDay: "2026-11-19" }),
|
|
165
|
+
],
|
|
166
|
+
};
|
|
167
|
+
expect(storeStatusAt(berlin(18, "12:30"), schedule)).toEqual({
|
|
168
|
+
open: false,
|
|
169
|
+
nextOpening: "Freitag, 20.11. um 11:30 Uhr",
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("decides by the restaurant's clock, not the visitor's", () => {
|
|
174
|
+
// 12:30 in Berlin is 06:30 in New York: open in Berlin
|
|
175
|
+
const instant = berlin(18, "12:30");
|
|
176
|
+
expect(storeStatusAt(instant, SCHEDULE).open).toBe(true);
|
|
177
|
+
expect(
|
|
178
|
+
storeStatusAt(instant, { ...SCHEDULE, timeZone: "America/New_York" })
|
|
179
|
+
.open,
|
|
180
|
+
).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("wishedTimeWindow", () => {
|
|
185
|
+
it("starts at now plus the lead time within the current span", () => {
|
|
186
|
+
expect(wishedTimeWindow(berlin(18, "12:00"), SCHEDULE, 30)).toEqual({
|
|
187
|
+
kind: "open",
|
|
188
|
+
ready: 750,
|
|
189
|
+
span: { opens: 690, closes: 870 },
|
|
190
|
+
earliest: 750,
|
|
191
|
+
latest: 870,
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("assumes 30 minutes without a lead time", () => {
|
|
196
|
+
const window = wishedTimeWindow(berlin(18, "12:00"), SCHEDULE, null);
|
|
197
|
+
expect(window).toMatchObject({ kind: "open", earliest: 750 });
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("offers the next span of today before it opens", () => {
|
|
201
|
+
expect(wishedTimeWindow(berlin(18, "15:00"), SCHEDULE, 30)).toMatchObject({
|
|
202
|
+
kind: "open",
|
|
203
|
+
earliest: 1050,
|
|
204
|
+
latest: 1380,
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("runs past midnight in a late-night span", () => {
|
|
209
|
+
expect(wishedTimeWindow(berlin(20, "23:50"), SCHEDULE, 30)).toMatchObject({
|
|
210
|
+
kind: "open",
|
|
211
|
+
earliest: 1440 + 20,
|
|
212
|
+
latest: 1440 + 90,
|
|
213
|
+
});
|
|
214
|
+
expect(wishedTimeWindow(berlin(21, "00:30"), SCHEDULE, 30)).toMatchObject({
|
|
215
|
+
kind: "open",
|
|
216
|
+
earliest: 60,
|
|
217
|
+
latest: 90,
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("has nothing left once the last span ends before the order is ready", () => {
|
|
222
|
+
expect(wishedTimeWindow(berlin(18, "22:45"), SCHEDULE, 30)).toEqual({
|
|
223
|
+
kind: "none_left",
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("knows weekly closing days and holidays", () => {
|
|
228
|
+
expect(wishedTimeWindow(berlin(23, "12:00"), SCHEDULE, 30)).toEqual({
|
|
229
|
+
kind: "closing_day",
|
|
230
|
+
weekday: 1,
|
|
231
|
+
});
|
|
232
|
+
const schedule = {
|
|
233
|
+
...SCHEDULE,
|
|
234
|
+
holidays: [
|
|
235
|
+
holiday({ id: "h", firstDay: "2026-11-18", lastDay: "2026-11-18" }),
|
|
236
|
+
],
|
|
237
|
+
};
|
|
238
|
+
expect(wishedTimeWindow(berlin(18, "12:00"), schedule, 30)).toEqual({
|
|
239
|
+
kind: "holiday",
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("ends a span up to 24:00 at the last slot of the day", () => {
|
|
244
|
+
// Sunday 12:00–24:00: 00:00 would read as the morning of the same day
|
|
245
|
+
expect(wishedTimeWindow(berlin(22, "22:00"), SCHEDULE, 30)).toMatchObject({
|
|
246
|
+
kind: "open",
|
|
247
|
+
earliest: 1350,
|
|
248
|
+
latest: 1435,
|
|
249
|
+
});
|
|
250
|
+
expect(wishedTimeWindow(berlin(22, "23:10"), SCHEDULE, 25)).toMatchObject({
|
|
251
|
+
kind: "open",
|
|
252
|
+
earliest: 1415,
|
|
253
|
+
latest: 1435,
|
|
254
|
+
});
|
|
255
|
+
expect(wishedTimeWindow(berlin(22, "23:40"), SCHEDULE, 30)).toEqual({
|
|
256
|
+
kind: "none_left",
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("offers no pre-order for the next day", () => {
|
|
261
|
+
// Wednesday 23:30: the plugin refuses an order for Thursday's lunch
|
|
262
|
+
expect(wishedTimeWindow(berlin(18, "23:30"), SCHEDULE, 30).kind).toBe(
|
|
263
|
+
"none_left",
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe("slots", () => {
|
|
269
|
+
it("rounds the first slot up to the 5-minute grid", () => {
|
|
270
|
+
expect(firstSlot(763, 870)).toBe(765);
|
|
271
|
+
expect(firstSlot(765, 870)).toBe(765);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("takes the last slot before the end when rounding passes it", () => {
|
|
275
|
+
expect(firstSlot(868, 871)).toBe(870);
|
|
276
|
+
expect(firstSlot(867, 869)).toBeNull();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("reads a time after midnight in a window that runs past it", () => {
|
|
280
|
+
expect(minutesInWindow("00:30", 1410, 1530)).toBe(1470);
|
|
281
|
+
expect(minutesInWindow("23:45", 1410, 1530)).toBe(1425);
|
|
282
|
+
// outside: the nearer end decides
|
|
283
|
+
expect(minutesInWindow("02:00", 1410, 1530)).toBe(1440 + 120);
|
|
284
|
+
expect(minutesInWindow("22:00", 1410, 1530)).toBe(1320);
|
|
285
|
+
expect(minutesInWindow("12:00", 690, 870)).toBe(720);
|
|
286
|
+
expect(minutesInWindow("1200", 690, 870)).toBeNull();
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("formats clock and closing times", () => {
|
|
290
|
+
expect(formatClock(1470)).toBe("00:30");
|
|
291
|
+
expect(formatClock(-420)).toBe("17:00");
|
|
292
|
+
expect(formatClosing(1440)).toBe("24:00");
|
|
293
|
+
expect(formatClosing(1530)).toBe("01:30");
|
|
294
|
+
});
|
|
295
|
+
});
|