2022-03-06 18:30:01 -05:00
|
|
|
import { click, visit } from "@ember/test-helpers";
|
2022-03-07 08:34:05 -05:00
|
|
|
import { test } from "qunit";
|
2023-05-04 09:52:04 -04:00
|
|
|
import pretender, { response } from "discourse/tests/helpers/create-pretender";
|
2024-01-16 11:51:44 -05:00
|
|
|
import { acceptance, count } from "discourse/tests/helpers/qunit-helpers";
|
2024-03-27 17:50:15 -04:00
|
|
|
import I18n from "discourse-i18n";
|
2024-01-16 11:51:44 -05:00
|
|
|
import { stubStripe } from "discourse/plugins/discourse-subscriptions/helpers/stripe";
|
2023-05-04 09:52:04 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2019-10-09 22:52:55 -04:00
|
|
|
|
2024-09-17 19:49:28 -04:00
|
|
|
acceptance("Subscriptions", function (needs) {
|
2021-01-04 14:32:33 -05:00
|
|
|
needs.user();
|
2022-03-06 18:30:01 -05:00
|
|
|
needs.hooks.beforeEach(function () {
|
2020-01-09 22:41:32 -05:00
|
|
|
stubStripe();
|
2021-01-04 14:32:33 -05:00
|
|
|
});
|
2020-01-09 22:41:32 -05:00
|
|
|
|
2022-03-06 18:30:01 -05:00
|
|
|
test("subscribing", async function (assert) {
|
2021-01-04 14:32:33 -05:00
|
|
|
await visit("/s");
|
|
|
|
await click(".product:first-child a");
|
2020-01-10 00:47:28 -05:00
|
|
|
|
2021-01-04 14:32:33 -05:00
|
|
|
assert.ok(
|
2022-03-06 18:30:01 -05:00
|
|
|
count(".discourse-subscriptions-section-columns") > 0,
|
2021-01-04 14:32:33 -05:00
|
|
|
"has the sections for billing"
|
|
|
|
);
|
2020-01-11 17:08:00 -05:00
|
|
|
|
2021-01-04 14:32:33 -05:00
|
|
|
assert.ok(
|
2022-03-06 18:30:01 -05:00
|
|
|
count(".subscribe-buttons button") > 0,
|
2021-01-04 14:32:33 -05:00
|
|
|
"has buttons for subscribe"
|
|
|
|
);
|
|
|
|
});
|
2023-05-04 09:52:04 -04:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2024-03-27 17:50:15 -04:00
|
|
|
|
|
|
|
// 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"
|
|
|
|
);
|
|
|
|
});
|
2019-10-09 22:52:55 -04:00
|
|
|
});
|