format the rate in the plan model
This commit is contained in:
parent
dbaa30ba18
commit
842fac9176
|
@ -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() {
|
||||
|
|
|
@ -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"
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue