DEV: add frontend tests to make sure pricing-table works
We test three conditions: 1. Make sure the customer email is prefilled, if there is a logged in discourse user 2. The pricing table also displays, if there is no logged in discourse user 3. If the pricing table is not configured, the pricing table element does not show up.
This commit is contained in:
@@ -1,18 +0,0 @@
|
||||
import { visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe";
|
||||
|
||||
acceptance("Discourse Subscriptions", function (needs) {
|
||||
needs.user();
|
||||
needs.hooks.beforeEach(function () {
|
||||
stubStripe();
|
||||
});
|
||||
|
||||
test("viewing product page", async function (assert) {
|
||||
await visit("/s");
|
||||
|
||||
assert.ok(count(".product-list") > 0, "has product page");
|
||||
assert.ok(count(".product:first-child a") > 0, "has a link");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,50 @@
|
||||
import { acceptance } from "discourse/tests/helpers/qunit-helpers";
|
||||
import { visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
|
||||
acceptance("Discourse Subscriptions", function (needs) {
|
||||
needs.user();
|
||||
needs.settings({
|
||||
discourse_subscriptions_pricing_table: JSON.stringify({
|
||||
pricingTableId: "pricingTableId",
|
||||
publishableKey: "publishableKey",
|
||||
}),
|
||||
});
|
||||
|
||||
test("pricing table element includes email", async function (assert) {
|
||||
await visit("/subscriptions");
|
||||
|
||||
assert.equal(
|
||||
document.querySelector("stripe-pricing-table").outerHTML,
|
||||
`<stripe-pricing-table pricing-table-id="pricingTableId" publishable-key="publishableKey" customer-email="eviltrout@example.com"></stripe-pricing-table>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
acceptance("Discourse Subscriptions", function (needs) {
|
||||
needs.settings({
|
||||
discourse_subscriptions_pricing_table: JSON.stringify({
|
||||
pricingTableId: "pricingTableId",
|
||||
publishableKey: "publishableKey",
|
||||
}),
|
||||
});
|
||||
|
||||
test("pricing table works for people without account", async function (assert) {
|
||||
await visit("/subscriptions");
|
||||
|
||||
assert.equal(
|
||||
document.querySelector("stripe-pricing-table").outerHTML,
|
||||
`<stripe-pricing-table pricing-table-id="pricingTableId" publishable-key="publishableKey"></stripe-pricing-table>`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
acceptance("Discourse Subscriptions", function (needs) {
|
||||
needs.user();
|
||||
|
||||
test("pricing table element does not show up if not configured", async function (assert) {
|
||||
await visit("/subscriptions");
|
||||
|
||||
assert.equal(document.querySelector("stripe-pricing-table"), null);
|
||||
});
|
||||
});
|
||||
@@ -1,66 +0,0 @@
|
||||
import { click, visit } from "@ember/test-helpers";
|
||||
import { test } from "qunit";
|
||||
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
||||
import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
|
||||
import I18n from "discourse-i18n";
|
||||
import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe";
|
||||
|
||||
function singleProductPretender() {
|
||||
pretender.get("/s", () => {
|
||||
const products = [
|
||||
{
|
||||
id: "prod_23o8I7tU4g56",
|
||||
name: "Awesome Product",
|
||||
description:
|
||||
"Subscribe to our awesome product. For only $230.10 per month, you can get access. This is a test site. No real credit card transactions.",
|
||||
},
|
||||
];
|
||||
|
||||
return response(products);
|
||||
});
|
||||
}
|
||||
|
||||
acceptance("Discourse Subscriptions", function (needs) {
|
||||
needs.user();
|
||||
needs.hooks.beforeEach(function () {
|
||||
stubStripe();
|
||||
});
|
||||
|
||||
test("subscribing", async function (assert) {
|
||||
await visit("/s");
|
||||
await click(".product:first-child a");
|
||||
|
||||
assert.ok(
|
||||
count(".discourse-subscriptions-section-columns") > 0,
|
||||
"has the sections for billing"
|
||||
);
|
||||
|
||||
assert.ok(
|
||||
count(".subscribe-buttons button") > 0,
|
||||
"has buttons for subscribe"
|
||||
);
|
||||
});
|
||||
|
||||
test("skips products list on sites with one product", async function (assert) {
|
||||
singleProductPretender();
|
||||
|
||||
await visit("/s");
|
||||
|
||||
assert.dom(".subscribe-buttons button").exists({ count: 1 });
|
||||
assert.dom("input.subscribe-promo-code").exists();
|
||||
assert.dom("button.btn-payment").exists();
|
||||
});
|
||||
|
||||
// In YAML `NO:` is a boolean, so we need quotes around `"NO":`.
|
||||
test("Norway is translated correctly", async function (assert) {
|
||||
assert.equal(
|
||||
I18n.t("discourse_subscriptions.subscribe.countries.NO"),
|
||||
"Norway"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
I18n.t("discourse_subscriptions.subscribe.countries.NG"),
|
||||
"Nigeria"
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
export default function (helpers) {
|
||||
const { response } = helpers;
|
||||
|
||||
this.get("/s", () => {
|
||||
this.get("/subscriptions", () => {
|
||||
const products = [
|
||||
{
|
||||
id: "prod_23o8I7tU4g56",
|
||||
@@ -20,7 +20,7 @@ export default function (helpers) {
|
||||
return response(products);
|
||||
});
|
||||
|
||||
this.get("/s/:id", () => {
|
||||
this.get("/subscriptions/:id", () => {
|
||||
const product = {
|
||||
id: "prod_23o8I7tU4g56",
|
||||
name: "Awesome Product",
|
||||
|
||||
Reference in New Issue
Block a user