REFACTOR: Use the new format for acceptance tests. (#37)

This commit is contained in:
Roman Rizzi 2021-01-04 16:32:33 -03:00 committed by GitHub
parent 0b5f740db5
commit 088b8d2239
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 50 deletions

View File

@ -1,17 +1,16 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe"; import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe";
acceptance("Discourse Subscriptions", { acceptance("Discourse Subscriptions", function (needs) {
beforeEach() { needs.user();
needs.hooks.beforeEach(() => {
stubStripe(); stubStripe();
}, });
loggedIn: true test("viewing product page", async (assert) => {
}); await visit("/s");
QUnit.test("viewing product page", async assert => { assert.ok($(".product-list").length, "has product page");
await visit("/s"); assert.ok($(".product:first-child a").length, "has a link");
});
assert.ok($(".product-list").length, "has product page");
assert.ok($(".product:first-child a").length, "has a link");
}); });

View File

@ -1,23 +1,25 @@
import { acceptance } from "helpers/qunit-helpers"; import { acceptance } from "discourse/tests/helpers/qunit-helpers";
import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe"; import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe";
acceptance("Discourse Subscriptions", { acceptance("Discourse Subscriptions", function (needs) {
beforeEach() { needs.user();
needs.hooks.beforeEach(() => {
stubStripe(); stubStripe();
}, });
loggedIn: true test("subscribing", async (assert) => {
}); await visit("/s");
QUnit.test("subscribing", async assert => { await click(".product:first-child a");
await visit("/s");
assert.ok(
await click(".product:first-child a"); $(".discourse-subscriptions-section-columns").length,
"has the sections for billing"
assert.ok( );
$(".discourse-subscriptions-section-columns").length,
"has the sections for billing" assert.ok(
); $(".subscribe-buttons button").length,
"has buttons for subscribe"
assert.ok($(".subscribe-buttons button").length, "has buttons for subscribe"); );
});
}); });

View File

@ -1,4 +1,4 @@
import componentTest from "helpers/component-test"; import componentTest from "discourse/tests/helpers/component-test";
moduleForComponent("payment-options", { integration: true }); moduleForComponent("payment-options", { integration: true });
@ -13,7 +13,7 @@ componentTest("Discourse Subscriptions payment options have no plans", {
0, 0,
"The plan buttons are not shown" "The plan buttons are not shown"
); );
} },
}); });
componentTest("Discourse Subscriptions payment options has content", { componentTest("Discourse Subscriptions payment options has content", {
@ -27,17 +27,17 @@ componentTest("Discourse Subscriptions payment options has content", {
{ {
currency: "aud", currency: "aud",
recurring: { interval: "year" }, recurring: { interval: "year" },
amountDollars: "44.99" amountDollars: "44.99",
}, },
{ {
currency: "gdp", currency: "gdp",
recurring: { interval: "month" }, recurring: { interval: "month" },
amountDollars: "9.99" amountDollars: "9.99",
} },
]); ]);
}, },
async test(assert) { async test(assert) {
assert.equal(this.selectedPlan, null, "No plans are selected by default"); assert.equal(this.selectedPlan, null, "No plans are selected by default");
} },
}); });

View File

@ -1,4 +1,4 @@
import componentTest from "helpers/component-test"; import componentTest from "discourse/tests/helpers/component-test";
moduleForComponent("payment-plan", { integration: true }); moduleForComponent("payment-plan", { integration: true });
@ -13,7 +13,7 @@ componentTest("Payment plan subscription button rendered", {
type: "recurring", type: "recurring",
currency: "aud", currency: "aud",
recurring: { interval: "year" }, recurring: { interval: "year" },
amountDollars: "44.99" amountDollars: "44.99",
}); });
}, },
@ -39,7 +39,7 @@ componentTest("Payment plan subscription button rendered", {
"$AUD 44.99", "$AUD 44.99",
"The plan amount and currency is shown" "The plan amount and currency is shown"
); );
} },
}); });
componentTest("Payment plan one-time-payment button rendered", { componentTest("Payment plan one-time-payment button rendered", {
@ -52,7 +52,7 @@ componentTest("Payment plan one-time-payment button rendered", {
this.set("plan", { this.set("plan", {
type: "one_time", type: "one_time",
currency: "USD", currency: "USD",
amountDollars: "3.99" amountDollars: "3.99",
}); });
}, },
@ -64,5 +64,5 @@ componentTest("Payment plan one-time-payment button rendered", {
"One-Time Payment", "One-Time Payment",
"Shown as one time payment" "Shown as one time payment"
); );
} },
}); });

View File

@ -4,7 +4,7 @@ export function stubStripe() {
window.Stripe = () => { window.Stripe = () => {
return { return {
createPaymentMethod() { createPaymentMethod() {
return new Promise(resolve => { return new Promise((resolve) => {
resolve({}); resolve({});
}); });
}, },
@ -14,11 +14,11 @@ export function stubStripe() {
return { return {
on() {}, on() {},
card() {}, card() {},
mount() {} mount() {},
}; };
} },
}; };
} },
}; };
}; };
} }

View File

@ -2,13 +2,13 @@ import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/pla
QUnit.module("discourse-patrons:model:plan"); QUnit.module("discourse-patrons:model:plan");
QUnit.test("subscriptionRate", assert => { QUnit.test("subscriptionRate", (assert) => {
const plan = Plan.create({ const plan = Plan.create({
unit_amount: "2399", unit_amount: "2399",
currency: "aud", currency: "aud",
recurring: { recurring: {
interval: "month" interval: "month",
} },
}); });
assert.equal( assert.equal(
@ -18,7 +18,7 @@ QUnit.test("subscriptionRate", assert => {
); );
}); });
QUnit.test("amountDollars", assert => { QUnit.test("amountDollars", (assert) => {
const plan = Plan.create({ unit_amount: 2399 }); const plan = Plan.create({ unit_amount: 2399 });
assert.equal( assert.equal(
@ -28,7 +28,7 @@ QUnit.test("amountDollars", assert => {
); );
}); });
QUnit.test("amount", assert => { QUnit.test("amount", (assert) => {
const plan = Plan.create({ amountDollars: "22.12" }); const plan = Plan.create({ amountDollars: "22.12" });
assert.equal(plan.get("unit_amount"), 2212, "it returns the cents amount"); assert.equal(plan.get("unit_amount"), 2212, "it returns the cents amount");