DEV: Fix imports (#113)

This commit is contained in:
Jarek Radosz 2022-03-07 00:30:01 +01:00 committed by GitHub
parent d6eaba632d
commit 98c843b8f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 189 additions and 156 deletions

View File

@ -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";

View File

@ -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,

View File

@ -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,

View File

@ -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() {

View File

@ -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) {

View File

@ -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() {

View File

@ -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",

View File

@ -5,6 +5,6 @@
"author": "Discourse",
"license": "MIT",
"devDependencies": {
"eslint-config-discourse": "^1.1.8"
"eslint-config-discourse": "^2.0.0"
}
}

View File

@ -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");
});
});

View File

@ -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"
);
});

View File

@ -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");
},
});

View File

@ -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"
);
},
});

View File

@ -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"
);
},
});
});

View File

@ -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"
);
},
});
});

View File

@ -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"
);
});
});

View File

@ -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"