mirror of
https://github.com/penpot/penpot.git
synced 2026-11-20 17:11:15 +00:00
Move the pure subscription rules out of the browser specs and into unit tests, then keep only the cases a browser can prove. - Extract show-manage-subscription-link? and show-main-menu-power-up? from the dashboard team panel and the workspace main menu, and use them at both call sites. A new subscription_dashboard_test.cljs covers which plan a subscription reads to, including unpaid and canceled demotion, the owner and enterprise sides of both affordances, and the banner and members-CTA boundaries: four editors over the seats, no usage data, and the demoted plans. - Add get-versions-stored-days tests to workspace_versions_test.cljs: an active nitrate or enterprise license keeps 90 days, a canceled one lets the team plan decide, a license without the admin console does not count, and unlimited, enterprise, professional and planless teams keep 30, 90 and 7 days. - Rewrite the profile usage tests as async tests with mock/with-mocks* and an async transport double: the editors from the usage call reach [:props :subscription :editors], a failing call leaves the profile untouched and logs once, and the call is skipped without the subscriptions flag. - Cut the e2e suite from 13 cases to 7. Five dashboard cases keep the menu icon, the two sidebar plan names, the owner-only settings link and the members CTA; two workspace cases keep the translated days warning with the upsell step and the enterprise menu with no upsell. Assert the unlimited glyph and drop the CTA count. - Drop the three get-team-info mocks the dashboard never calls and six unreferenced subscription fixtures, reusing the invitations fixture. - Sort the subscription test requires in runner.cljs: cljfmt's :sort-ns-references? wants subscription-dashboard-test first. Closes #13005 AI-assisted-by: deepseek-v4.1-flash
86 lines
3.5 KiB
Clojure
86 lines
3.5 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns frontend-tests.data.profile-test
|
|
(:require
|
|
[app.common.uuid :as uuid]
|
|
[app.config :as cf]
|
|
[app.main.data.profile :as dprof]
|
|
[app.main.repo :as rp]
|
|
[beicon.v2.core :as rx]
|
|
[cljs.test :as t :include-macros true]
|
|
[frontend-tests.helpers.async :as async]
|
|
[frontend-tests.helpers.mock :as mock]))
|
|
|
|
(t/deftest profile-update-params-omits-nil-values
|
|
(t/is (= {:fullname "Updated Name"}
|
|
(dprof/profile-update-params {:fullname "Updated Name"
|
|
:lang nil
|
|
:theme nil}))))
|
|
|
|
(t/deftest profile-update-params-preserves-present-values
|
|
(t/is (= {:fullname "Updated Name"
|
|
:lang "en"
|
|
:theme "dark"}
|
|
(dprof/profile-update-params {:fullname "Updated Name"
|
|
:lang "en"
|
|
:theme "dark"}))))
|
|
|
|
(t/deftest update-profile-accepts-nil-optional-values
|
|
(t/is (some? (dprof/update-profile {:id uuid/zero
|
|
:fullname "Updated Name"
|
|
:theme nil}))))
|
|
|
|
;; The editors from the usage call reach the profile so the dashboard
|
|
;; predicates can count them; a failure must leave the profile untouched.
|
|
|
|
(defn- authenticated-profile
|
|
[subscription]
|
|
{:id (uuid/next)
|
|
:props {:subscription subscription}})
|
|
|
|
(t/deftest ^:async fetching-the-profile-copies-the-editors-from-the-usage-call
|
|
(let [editors [{:id (uuid/next) :name "Leia"}]
|
|
profile (authenticated-profile {:quantity 2})
|
|
result (await
|
|
(mock/with-mocks*
|
|
{cf/flags (conj cf/flags :subscriptions)
|
|
rp/cmd! (mock/stub
|
|
(fn [_ _]
|
|
(->> (rx/of {:editors editors})
|
|
(rx/observe-on :async))))}
|
|
(await (async/->promise (dprof/on-fetch-profile-success profile)))))]
|
|
(t/is (= editors (get-in result [:props :subscription :editors])))))
|
|
|
|
(t/deftest ^:async a-failing-usage-call-keeps-the-profile
|
|
(let [profile (authenticated-profile {:quantity 2})
|
|
errors (atom 0)
|
|
previous-error (.-error js/console)]
|
|
(try
|
|
(set! (.-error js/console) (fn [& _] (swap! errors inc)))
|
|
(let [result (await
|
|
(mock/with-mocks*
|
|
{cf/flags (conj cf/flags :subscriptions)
|
|
rp/cmd! (mock/stub
|
|
(fn [_ _]
|
|
(->> (rx/throw (ex-info "boom" {}))
|
|
(rx/observe-on :async))))}
|
|
(await (async/->promise (dprof/on-fetch-profile-success profile)))))]
|
|
(t/is (= profile result))
|
|
(t/is (= 1 @errors)))
|
|
(finally
|
|
(set! (.-error js/console) previous-error)))))
|
|
|
|
(t/deftest ^:async without-the-subscriptions-flag-the-usage-call-is-skipped
|
|
(let [profile (authenticated-profile {:quantity 2})
|
|
result (await
|
|
(mock/with-mocks*
|
|
{cf/flags (disj cf/flags :subscriptions)
|
|
rp/cmd! mock/rpc-cmd-mock}
|
|
(await (async/->promise (dprof/on-fetch-profile-success profile)))))]
|
|
(t/is (empty? @mock/rpc-calls))
|
|
(t/is (= profile result))))
|