From 98c843b8f282353c18fa3f454cd998ad4c460b5d Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Mon, 7 Mar 2022 00:30:01 +0100 Subject: [PATCH] DEV: Fix imports (#113) --- ...-subscriptions-products-show-plans-show.js | 1 + .../admin-plugins-discourse-subscriptions.js | 1 + .../discourse/controllers/subscribe-show.js | 1 + ...-discourse-subscriptions-products-index.js | 1 + ...s-discourse-subscriptions-products-show.js | 1 + ...s-discourse-subscriptions-subscriptions.js | 1 + .../routes/user-billing-subscriptions.js | 1 + package.json | 2 +- test/javascripts/acceptance/payments-test.js | 11 +-- test/javascripts/acceptance/subscribe-test.js | 12 +-- .../components/payment-options-test.js | 43 ---------- .../components/payment-plan-test.js | 68 ---------------- .../components/payment-options-test.js | 53 +++++++++++++ .../components/payment-plan-test.js | 78 +++++++++++++++++++ test/javascripts/models/plan-test.js | 63 ++++++++------- yarn.lock | 8 +- 16 files changed, 189 insertions(+), 156 deletions(-) delete mode 100644 test/javascripts/components/payment-options-test.js delete mode 100644 test/javascripts/components/payment-plan-test.js create mode 100644 test/javascripts/integration/components/payment-options-test.js create mode 100644 test/javascripts/integration/components/payment-plan-test.js diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js index 251a367..09b174c 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions-products-show-plans-show.js @@ -2,6 +2,7 @@ import discourseComputed from "discourse-common/utils/decorators"; import DiscourseURL from "discourse/lib/url"; import Controller from "@ember/controller"; import { alias } from "@ember/object/computed"; +import bootbox from "bootbox"; const RECURRING = "recurring"; const ONE_TIME = "one_time"; diff --git a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions.js b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions.js index e2415bf..d537344 100644 --- a/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions.js +++ b/assets/javascripts/discourse/controllers/admin-plugins-discourse-subscriptions.js @@ -4,6 +4,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; import Controller from "@ember/controller"; import discourseComputed from "discourse-common/utils/decorators"; import I18n from "I18n"; +import bootbox from "bootbox"; export default Controller.extend({ loading: false, diff --git a/assets/javascripts/discourse/controllers/subscribe-show.js b/assets/javascripts/discourse/controllers/subscribe-show.js index 45a91d5..77f5df4 100644 --- a/assets/javascripts/discourse/controllers/subscribe-show.js +++ b/assets/javascripts/discourse/controllers/subscribe-show.js @@ -4,6 +4,7 @@ import Transaction from "discourse/plugins/discourse-subscriptions/discourse/mod import I18n from "I18n"; import { not } from "@ember/object/computed"; import discourseComputed from "discourse-common/utils/decorators"; +import bootbox from "bootbox"; export default Controller.extend({ selectedPlan: null, diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-index.js b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-index.js index 941e19f..c2dda31 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-index.js +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-index.js @@ -2,6 +2,7 @@ import Route from "@ember/routing/route"; import AdminProduct from "discourse/plugins/discourse-subscriptions/discourse/models/admin-product"; import I18n from "I18n"; import { action } from "@ember/object"; +import bootbox from "bootbox"; export default Route.extend({ model() { diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js index 4c62939..7058592 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-products-show.js @@ -4,6 +4,7 @@ import AdminPlan from "discourse/plugins/discourse-subscriptions/discourse/model import I18n from "I18n"; import { hash } from "rsvp"; import { action } from "@ember/object"; +import bootbox from "bootbox"; export default Route.extend({ model(params) { diff --git a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-subscriptions.js b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-subscriptions.js index b6b5bba..565d377 100644 --- a/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-subscriptions.js +++ b/assets/javascripts/discourse/routes/admin-plugins-discourse-subscriptions-subscriptions.js @@ -2,6 +2,7 @@ import I18n from "I18n"; import Route from "@ember/routing/route"; import AdminSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/admin-subscription"; import { action } from "@ember/object"; +import bootbox from "bootbox"; export default Route.extend({ model() { diff --git a/assets/javascripts/discourse/routes/user-billing-subscriptions.js b/assets/javascripts/discourse/routes/user-billing-subscriptions.js index 919239a..61e970d 100644 --- a/assets/javascripts/discourse/routes/user-billing-subscriptions.js +++ b/assets/javascripts/discourse/routes/user-billing-subscriptions.js @@ -2,6 +2,7 @@ import Route from "@ember/routing/route"; import UserSubscription from "discourse/plugins/discourse-subscriptions/discourse/models/user-subscription"; import I18n from "I18n"; import { action } from "@ember/object"; +import bootbox from "bootbox"; export default Route.extend({ templateName: "user/billing/subscriptions", diff --git a/package.json b/package.json index 028efc4..12c8021 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,6 @@ "author": "Discourse", "license": "MIT", "devDependencies": { - "eslint-config-discourse": "^1.1.8" + "eslint-config-discourse": "^2.0.0" } } diff --git a/test/javascripts/acceptance/payments-test.js b/test/javascripts/acceptance/payments-test.js index 3d5ee22..d3fa60e 100644 --- a/test/javascripts/acceptance/payments-test.js +++ b/test/javascripts/acceptance/payments-test.js @@ -1,16 +1,17 @@ -import { acceptance } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance, count } from "discourse/tests/helpers/qunit-helpers"; import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe"; +import { visit } from "@ember/test-helpers"; acceptance("Discourse Subscriptions", function (needs) { needs.user(); - needs.hooks.beforeEach(() => { + needs.hooks.beforeEach(function () { stubStripe(); }); - test("viewing product page", async (assert) => { + test("viewing product page", async function (assert) { await visit("/s"); - assert.ok($(".product-list").length, "has product page"); - assert.ok($(".product:first-child a").length, "has a link"); + assert.ok(count(".product-list") > 0, "has product page"); + assert.ok(count(".product:first-child a") > 0, "has a link"); }); }); diff --git a/test/javascripts/acceptance/subscribe-test.js b/test/javascripts/acceptance/subscribe-test.js index aaf9fd6..e4db47d 100644 --- a/test/javascripts/acceptance/subscribe-test.js +++ b/test/javascripts/acceptance/subscribe-test.js @@ -1,24 +1,24 @@ -import { acceptance } from "discourse/tests/helpers/qunit-helpers"; +import { acceptance, count } from "discourse/tests/helpers/qunit-helpers"; import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe"; +import { click, visit } from "@ember/test-helpers"; acceptance("Discourse Subscriptions", function (needs) { needs.user(); - needs.hooks.beforeEach(() => { + needs.hooks.beforeEach(function () { stubStripe(); }); - test("subscribing", async (assert) => { + test("subscribing", async function (assert) { await visit("/s"); - await click(".product:first-child a"); assert.ok( - $(".discourse-subscriptions-section-columns").length, + count(".discourse-subscriptions-section-columns") > 0, "has the sections for billing" ); assert.ok( - $(".subscribe-buttons button").length, + count(".subscribe-buttons button") > 0, "has buttons for subscribe" ); }); diff --git a/test/javascripts/components/payment-options-test.js b/test/javascripts/components/payment-options-test.js deleted file mode 100644 index db49949..0000000 --- a/test/javascripts/components/payment-options-test.js +++ /dev/null @@ -1,43 +0,0 @@ -import componentTest from "discourse/tests/helpers/component-test"; - -moduleForComponent("payment-options", { integration: true }); - -componentTest("Discourse Subscriptions payment options have no plans", { - template: `{{payment-options plans=plans}}`, - - async test(assert) { - this.set("plans", false); - - assert.equal( - find(".btn-discourse-subscriptions-subscribe").length, - 0, - "The plan buttons are not shown" - ); - }, -}); - -componentTest("Discourse Subscriptions payment options has content", { - template: `{{payment-options - plans=plans - selectedPlan=selectedPlan - }}`, - - beforeEach() { - this.set("plans", [ - { - currency: "aud", - recurring: { interval: "year" }, - amountDollars: "44.99", - }, - { - currency: "gdp", - recurring: { interval: "month" }, - amountDollars: "9.99", - }, - ]); - }, - - async test(assert) { - assert.equal(this.selectedPlan, null, "No plans are selected by default"); - }, -}); diff --git a/test/javascripts/components/payment-plan-test.js b/test/javascripts/components/payment-plan-test.js deleted file mode 100644 index 0bd3973..0000000 --- a/test/javascripts/components/payment-plan-test.js +++ /dev/null @@ -1,68 +0,0 @@ -import componentTest from "discourse/tests/helpers/component-test"; - -moduleForComponent("payment-plan", { integration: true }); - -componentTest("Payment plan subscription button rendered", { - template: `{{payment-plan - plan=plan - selectedPlan=selectedPlan - }}`, - - beforeEach() { - this.set("plan", { - type: "recurring", - currency: "aud", - recurring: { interval: "year" }, - amountDollars: "44.99", - }); - }, - - async test(assert) { - assert.equal( - find(".btn-discourse-subscriptions-subscribe").length, - 1, - "The payment button is shown" - ); - - assert.equal( - find(".btn-discourse-subscriptions-subscribe:first-child .interval") - .text() - .trim(), - "Yearly", - "The plan interval is shown -- Yearly" - ); - - assert.equal( - find(".btn-discourse-subscriptions-subscribe:first-child .amount") - .text() - .trim(), - "$44.99", - "The plan amount and currency is shown" - ); - }, -}); - -componentTest("Payment plan one-time-payment button rendered", { - template: `{{payment-plan - plan=plan - selectedPlan=selectedPlan - }}`, - - beforeEach() { - this.set("plan", { - type: "one_time", - currency: "USD", - amountDollars: "3.99", - }); - }, - - async test(assert) { - assert.equal( - find(".btn-discourse-subscriptions-subscribe:first-child .interval") - .text() - .trim(), - "One-Time Payment", - "Shown as one time payment" - ); - }, -}); diff --git a/test/javascripts/integration/components/payment-options-test.js b/test/javascripts/integration/components/payment-options-test.js new file mode 100644 index 0000000..9f68bcd --- /dev/null +++ b/test/javascripts/integration/components/payment-options-test.js @@ -0,0 +1,53 @@ +import { count, discourseModule } from "discourse/tests/helpers/qunit-helpers"; +import componentTest, { + setupRenderingTest, +} from "discourse/tests/helpers/component-test"; +import hbs from "htmlbars-inline-precompile"; + +discourseModule("payment-options", function (hooks) { + setupRenderingTest(hooks); + + componentTest("Discourse Subscriptions payment options have no plans", { + template: hbs`{{payment-options plans=plans}}`, + + async test(assert) { + this.set("plans", false); + + assert.strictEqual( + count(".btn-discourse-subscriptions-subscribe"), + 0, + "The plan buttons are not shown" + ); + }, + }); + + componentTest("Discourse Subscriptions payment options has content", { + template: hbs`{{payment-options + plans=plans + selectedPlan=selectedPlan + }}`, + + beforeEach() { + this.set("plans", [ + { + currency: "aud", + recurring: { interval: "year" }, + amountDollars: "44.99", + }, + { + currency: "gdp", + recurring: { interval: "month" }, + amountDollars: "9.99", + }, + ]); + }, + + async test(assert) { + assert.strictEqual( + this.selectedPlan, + undefined, + "No plans are selected by default" + ); + }, + }); +}); diff --git a/test/javascripts/integration/components/payment-plan-test.js b/test/javascripts/integration/components/payment-plan-test.js new file mode 100644 index 0000000..4239374 --- /dev/null +++ b/test/javascripts/integration/components/payment-plan-test.js @@ -0,0 +1,78 @@ +import { + count, + discourseModule, + query, +} from "discourse/tests/helpers/qunit-helpers"; +import componentTest, { + setupRenderingTest, +} from "discourse/tests/helpers/component-test"; +import hbs from "htmlbars-inline-precompile"; + +discourseModule("payment-plan", function (hooks) { + setupRenderingTest(hooks); + + componentTest("Payment plan subscription button rendered", { + template: hbs`{{payment-plan + plan=plan + selectedPlan=selectedPlan + }}`, + + beforeEach() { + this.set("plan", { + type: "recurring", + currency: "aud", + recurring: { interval: "year" }, + amountDollars: "44.99", + }); + }, + + async test(assert) { + assert.strictEqual( + count(".btn-discourse-subscriptions-subscribe"), + 1, + "The payment button is shown" + ); + + assert.strictEqual( + query( + ".btn-discourse-subscriptions-subscribe:first-child .interval" + ).innerText.trim(), + "Yearly", + "The plan interval is shown -- Yearly" + ); + + assert.strictEqual( + query( + ".btn-discourse-subscriptions-subscribe:first-child .amount" + ).innerText.trim(), + "$44.99", + "The plan amount and currency is shown" + ); + }, + }); + + componentTest("Payment plan one-time-payment button rendered", { + template: hbs`{{payment-plan + plan=plan + selectedPlan=selectedPlan + }}`, + + beforeEach() { + this.set("plan", { + type: "one_time", + currency: "USD", + amountDollars: "3.99", + }); + }, + + async test(assert) { + assert.strictEqual( + query( + ".btn-discourse-subscriptions-subscribe:first-child .interval" + ).innerText.trim(), + "One-Time Payment", + "Shown as one time payment" + ); + }, + }); +}); diff --git a/test/javascripts/models/plan-test.js b/test/javascripts/models/plan-test.js index 83c4371..fdf82bc 100644 --- a/test/javascripts/models/plan-test.js +++ b/test/javascripts/models/plan-test.js @@ -1,35 +1,40 @@ +import { module, test } from "qunit"; import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan"; -QUnit.module("discourse-patrons:model:plan"); +module("discourse-patrons:model:plan", function () { + test("subscriptionRate", function (assert) { + const plan = Plan.create({ + unit_amount: "2399", + currency: "aud", + recurring: { + interval: "month", + }, + }); -QUnit.test("subscriptionRate", (assert) => { - const plan = Plan.create({ - unit_amount: "2399", - currency: "aud", - recurring: { - interval: "month", - }, + assert.strictEqual( + plan.get("subscriptionRate"), + "23.99 AUD / month", + "it returns the formatted subscription rate" + ); }); - assert.equal( - plan.get("subscriptionRate"), - "23.99 AUD / month", - "it returns the formatted subscription rate" - ); -}); - -QUnit.test("amountDollars", (assert) => { - const plan = Plan.create({ unit_amount: 2399 }); - - assert.equal( - plan.get("amountDollars"), - 23.99, - "it returns the formatted dollar amount" - ); -}); - -QUnit.test("amount", (assert) => { - const plan = Plan.create({ amountDollars: "22.12" }); - - assert.equal(plan.get("unit_amount"), 2212, "it returns the cents amount"); + test("amountDollars", function (assert) { + const plan = Plan.create({ unit_amount: 2399 }); + + assert.strictEqual( + plan.get("amountDollars"), + "23.99", + "it returns the formatted dollar amount" + ); + }); + + test("amount", function (assert) { + const plan = Plan.create({ amountDollars: "22.12" }); + + assert.strictEqual( + plan.get("unit_amount"), + 2212, + "it returns the cents amount" + ); + }); }); diff --git a/yarn.lock b/yarn.lock index 75e648a..31f1f03 100644 --- a/yarn.lock +++ b/yarn.lock @@ -498,10 +498,10 @@ escape-string-regexp@^1.0.5: resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ= -eslint-config-discourse@^1.1.8: - version "1.1.8" - resolved "https://registry.yarnpkg.com/eslint-config-discourse/-/eslint-config-discourse-1.1.8.tgz#c297831876811ea08203aa348d1ba2a963b2ae78" - integrity sha512-ZSQfhliiO5Cfa7WcKoMkN4wW/1rBJpecpMJpfjiFsElfgPj4EV4Pzksi5CvFnRbJDoZh6DYYrQfO+tW062VOUA== +eslint-config-discourse@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/eslint-config-discourse/-/eslint-config-discourse-2.0.0.tgz#811ab2cf4e32c1f0d41bd57d9736d578fe80b741" + integrity sha512-enjsLU++iibJXM64YM6Y/yUM5580wKtkti9fQdrJDFkfLJnvv8/f2j7QmNbX//MoqWfIQfY2RkHH6VTfRUg4Mw== dependencies: babel-eslint "^10.1.0" ember-template-lint "^2.11.0"