mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-02-27 22:29:27 +00:00
abstract out the stripe component for easy future testing
This commit is contained in:
parent
f1de907c32
commit
8d8e9f9ad1
12
README.md
12
README.md
@ -28,17 +28,9 @@ Accept donations from visitors to your [Discourse](https://www.discourse.org/) f
|
|||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
* To run the rails specs, install the plugin and run `bundle exec rake plugin:spec[discourse-donations]` in the discourse root directory.
|
These commands should run:
|
||||||
* To run qunit tests: `MODULE='Acceptance: Discourse Donations' bundle exec rake qunit:test[20000]`.
|
|
||||||
* To run Component tests: `MODULE='component:stripe-card' bundle exec rake qunit:test[20000]`.
|
|
||||||
|
|
||||||
**Note:**
|
* ```yarn prettier --list-different 'assets/**/*.scss' '**/*.es6'```
|
||||||
|
|
||||||
* If you're using a zsh shell, then you probably get this error: `zsh: no matches found ...` and you'll need to escape the square brackets with backslashes.
|
|
||||||
|
|
||||||
## TODO
|
|
||||||
|
|
||||||
* Handle custom fields
|
|
||||||
|
|
||||||
## Tested Credit Card Numbers
|
## Tested Credit Card Numbers
|
||||||
|
|
||||||
|
@ -1,35 +1,3 @@
|
|||||||
import { default as computed } from "ember-addons/ember-computed-decorators";
|
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
@computed
|
|
||||||
causes() {
|
|
||||||
const categoryEnabled =
|
|
||||||
Discourse.SiteSettings.discourse_donations_cause_category;
|
|
||||||
|
|
||||||
if (categoryEnabled) {
|
|
||||||
let categoryIds = Discourse.SiteSettings.discourse_donations_causes_categories.split(
|
|
||||||
"|"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (categoryIds.length) {
|
|
||||||
categoryIds = categoryIds.map(Number);
|
|
||||||
return this.site
|
|
||||||
.get("categoriesList")
|
|
||||||
.filter(c => {
|
|
||||||
return categoryIds.indexOf(c.id) > -1;
|
|
||||||
})
|
|
||||||
.map(c => {
|
|
||||||
return {
|
|
||||||
id: c.id,
|
|
||||||
name: c.name
|
|
||||||
};
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const causes = Discourse.SiteSettings.discourse_donations_causes;
|
|
||||||
return causes ? causes.split("|") : [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
@ -265,6 +265,7 @@ export default Ember.Component.extend({
|
|||||||
self.concatMessages(result.messages);
|
self.concatMessages(result.messages);
|
||||||
|
|
||||||
self.endTranscation();
|
self.endTranscation();
|
||||||
|
self.onCompleteTransation();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,10 @@ export default Ember.Controller.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
stripeTransationCompleteCtr() {
|
||||||
|
console.log('done!');
|
||||||
|
},
|
||||||
|
|
||||||
loadDonations() {
|
loadDonations() {
|
||||||
let email = this.get("email");
|
let email = this.get("email");
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
<form id="payment-form" class="form-horizontal">
|
<form id="payment-form" class="form-horizontal">
|
||||||
<div class="control-group discourse-donations-cause">
|
<div class="donations-page-payment">
|
||||||
<label class="control-label">
|
{{stripe-card
|
||||||
{{i18n 'discourse_donations.cause.label'}}
|
charges=charges
|
||||||
</label>
|
subscriptions=subscriptions
|
||||||
<div class="controls controls-dropdown">
|
onCompleteTransation=onCompleteTransation
|
||||||
{{combo-box content=causes value=cause none='discourse_donations.cause.placeholder'}}
|
}}
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,13 +1,3 @@
|
|||||||
<form id="payment-form" class="form-horizontal">
|
|
||||||
<div class="control-group discourse-donations-cause">
|
|
||||||
<label class="control-label">
|
|
||||||
{{i18n 'discourse_donations.cause.label'}}
|
|
||||||
</label>
|
|
||||||
<div class="controls controls-dropdown">
|
|
||||||
{{combo-box content=causes value=cause none='discourse_donations.cause.placeholder'}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label">
|
<label class="control-label">
|
||||||
{{i18n 'discourse_donations.type'}}
|
{{i18n 'discourse_donations.type'}}
|
||||||
@ -104,7 +94,8 @@
|
|||||||
|
|
||||||
<div class="control-group save-button">
|
<div class="control-group save-button">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
{{#d-button action="submitStripeCard" disabled=disableSubmit class="btn btn-primary btn-payment"}}
|
|
||||||
|
{{#d-button action="submitStripeCard" class="btn btn-primary btn-payment"}}
|
||||||
{{#if create_accounts}}
|
{{#if create_accounts}}
|
||||||
{{i18n 'discourse_donations.submit_with_create_account'}}
|
{{i18n 'discourse_donations.submit_with_create_account'}}
|
||||||
{{else}}
|
{{else}}
|
||||||
@ -125,4 +116,3 @@
|
|||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
|
@ -5,32 +5,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="donations-page-payment">
|
<div class="donations-page-payment">
|
||||||
{{stripe-card charges=charges subscriptions=subscriptions}}
|
{{donation-form
|
||||||
</div>
|
charges=charges
|
||||||
|
subscriptions=subscriptions
|
||||||
<div class="donations-page-donations">
|
onCompleteTransation=(action "stripeTransationCompleteCtr")
|
||||||
<h3>{{i18n 'discourse_donations.donations.title'}}</h3>
|
}}
|
||||||
{{#if loadingDonations}}
|
|
||||||
<span>{{i18n 'discourse_donations.donations.loading'}}</span>
|
|
||||||
{{loading-spinner size='small'}}
|
|
||||||
{{else}}
|
|
||||||
{{#if currentUser}}
|
|
||||||
{{#if hasDonations}}
|
|
||||||
{{donation-list charges=charges subscriptions=subscriptions customer=customer}}
|
|
||||||
{{else}}
|
|
||||||
{{i18n 'discourse_donations.donations.none'}}
|
|
||||||
{{/if}}
|
|
||||||
{{else}}
|
|
||||||
{{#if hasDonations}}
|
|
||||||
{{donation-list charges=charges subscriptions=subscriptions customer=customer}}
|
|
||||||
{{else}}
|
|
||||||
{{#if hasEmailResult}}
|
|
||||||
{{i18n 'discourse_donations.donations.none_email' email=email}}
|
|
||||||
{{else}}
|
|
||||||
{{input value=email placeholder=(i18n 'email')}}
|
|
||||||
{{d-button action='loadDonations' label='discourse_donations.donations.load' disabled=loadDonationsDisabled}}
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -5,10 +5,12 @@ moduleForComponent("donation-form", { integration: true });
|
|||||||
componentTest("donation form has content", {
|
componentTest("donation form has content", {
|
||||||
template: `{{donation-form}}`,
|
template: `{{donation-form}}`,
|
||||||
|
|
||||||
|
beforeEach() {
|
||||||
|
this.registry.register('component:stripe-card', Ember.Component.extend({ tagName: 'dummy-component-tag' }));
|
||||||
|
},
|
||||||
|
|
||||||
async test(assert) {
|
async test(assert) {
|
||||||
assert.ok(find('#payment-form').length, 'The form renders');
|
assert.ok(find('#payment-form').length, "The form renders");
|
||||||
assert.equal(find('.discourse-donations-cause .selected-name')
|
assert.ok(find('dummy-component-tag').length, "The stripe component renders");
|
||||||
.text()
|
|
||||||
.trim(), 'Select a cause', 'It has the combo box');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -6,9 +6,9 @@ componentTest("donation-row", {
|
|||||||
template: `{{donation-row currency=3 amount=21 period='monthly'}}`,
|
template: `{{donation-row currency=3 amount=21 period='monthly'}}`,
|
||||||
|
|
||||||
test(assert) {
|
test(assert) {
|
||||||
assert.equal(find(".donation-row-currency").text(), "3");
|
assert.equal(find(".donation-row-currency").text(), "3", "It has currency");
|
||||||
assert.equal(find(".donation-row-amount").text(), "21");
|
assert.equal(find(".donation-row-amount").text(), "21", "It has an amount");
|
||||||
assert.equal(find(".donation-row-period").text(), "monthly");
|
assert.equal(find(".donation-row-period").text(), "monthly", "It has a period");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -21,6 +21,6 @@ componentTest("donation-row cancels subscription", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
async test(assert) {
|
async test(assert) {
|
||||||
assert.ok(find(".donation-row-subscription").length);
|
assert.ok(find(".donation-row-subscription").length, "It has a subscription");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user