mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-02-17 00:45:08 +00:00
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";
|
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({
|
Plan.reopenClass({
|
||||||
findAll() {
|
findAll() {
|
||||||
|
17
test/javascripts/models/plan-test.js.es6
Normal file
17
test/javascripts/models/plan-test.js.es6
Normal 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"
|
||||||
|
);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user