format the rate in the plan model

This commit is contained in:
Rimian Perkins 2019-10-31 10:44:46 +11:00
parent dbaa30ba18
commit 842fac9176
2 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,13 @@
import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
const Plan = Discourse.Model.extend({});
const Plan = Discourse.Model.extend({
@computed("amount", "currency", "interval")
subscriptionRate(amount, currency, interval) {
const dollars = parseFloat(amount / 100).toFixed(2);
return `$${dollars} ${currency.toUpperCase()} / ${interval}`;
},
});
Plan.reopenClass({
findAll() {

View File

@ -0,0 +1,17 @@
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
QUnit.module("discourse-patrons:model:plan");
QUnit.test("subscriptionRate", assert => {
const plan = Plan.create({
amount: 2399,
currency: 'aud',
interval: 'month'
});
assert.equal(
plan.get("subscriptionRate"),
"$23.99 AUD / month",
"it should return the formatted subscription rate"
);
});