Skip to content

Commit dc9fff1

Browse files
committed
refactor: remove trial subscription functionality
Remove the trial subscription logic from the SubscriptionModel and related components. This streamlines the cancellation process, ensuring only active subscriptions are handled. Update tests to reflect these changes and ensure they pass without the trial-related assertions.
1 parent 9932753 commit dc9fff1

File tree

7 files changed

+7
-66
lines changed

7 files changed

+7
-66
lines changed

app/components/membership-page/actions-section.hbs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
<MembershipPage::Section @title="Actions" ...attributes>
2-
{{#if @subscription.isTrialing}}
3-
<ButtonWithSpinner
4-
class="bg-red-600 hover:bg-red-700 text-sm mt-4 text-white"
5-
{{on "click" @onCancelSubscriptionButtonClick}}
6-
data-test-cancel-trial-button
7-
>
8-
Cancel Trial
9-
</ButtonWithSpinner>
10-
{{else if (and @subscription.isActive (not @subscription.cancelAt))}}
2+
{{#if (and @subscription.isActive (not @subscription.cancelAt))}}
113
<ButtonWithSpinner
124
class="bg-red-600 hover:bg-red-700 text-sm mt-4 text-white"
135
{{on "click" @onCancelSubscriptionButtonClick}}

app/components/membership-page/cancel-subscription-modal.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ export default class CancelSubscriptionModalComponent extends Component {
2121
return this.selectedReason || (this.otherReasonIsSelected && this.reasonDescription.length > 0);
2222
}
2323

24+
// TODO: See if we can remove this
2425
get cancellationIsWithinTrialPeriod() {
25-
return this.subscription.isTrialing;
26+
return false;
2627
}
2728

2829
get placeholderTextForReasonDescriptionInput() {

app/components/membership-page/membership-plan-section.hbs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{{! @glint-nocheck: not typesafe yet }}
22
<MembershipPage::Section @title="Membership Plan" data-test-membership-plan-section>
33
<div class="text-gray-700 {{if @subscription.user.isVip 'line-through' ''}}" data-test-membership-plan-description>
4-
{{#if @subscription.isTrialing}}
5-
Your trial for the
6-
<b class="font-semibold">{{@subscription.pricingPlanName}}</b>
7-
plan is currently active.
8-
{{else if @subscription.isActive}}
4+
{{#if @subscription.isActive}}
95
{{#if @subscription.cancelAt}}
106
<p class="mb-3">
117
Your CodeCrafters membership is valid until

app/models/subscription.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export default class SubscriptionModel extends Model {
88
@attr('date') declare endedAt: Date | null;
99
@attr('string') declare pricingPlanName: string;
1010
@attr('date') declare startDate: Date;
11-
@attr('date') declare trialEnd: Date | null;
1211

1312
@belongsTo('user', { async: false, inverse: 'subscriptions' }) declare user: UserModel;
1413

@@ -20,10 +19,6 @@ export default class SubscriptionModel extends Model {
2019
return this.endedAt;
2120
}
2221

23-
get isTrialing() {
24-
return this.isActive && this.trialEnd && new Date() < this.trialEnd;
25-
}
26-
2722
declare cancel: (this: Model, payload: unknown) => Promise<void>;
2823
declare cancelTrial: (this: Model, payload: unknown) => Promise<void>;
2924
}

tests/acceptance/manage-membership-test.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { module, test } from 'qunit';
22
import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers';
33
import { setupWindowMock } from 'ember-window-mock/test-support';
4-
import { signInAsSubscriber, signInAsTrialingSubscriber } from 'codecrafters-frontend/tests/support/authentication-helpers';
4+
import { signInAsSubscriber } from 'codecrafters-frontend/tests/support/authentication-helpers';
55
import catalogPage from 'codecrafters-frontend/tests/pages/catalog-page';
66
import { formatWithOptions } from 'date-fns/fp';
77
import membershipPage from 'codecrafters-frontend/tests/pages/membership-page';
@@ -57,36 +57,6 @@ module('Acceptance | manage-membership-test', function (hooks) {
5757
.includesText('🎉 You have VIP access to all CodeCrafters content, valid until');
5858
});
5959

60-
test('subscriber can cancel trial', async function (assert) {
61-
testScenario(this.server);
62-
signInAsTrialingSubscriber(this.owner, this.server);
63-
64-
await membershipPage.visit();
65-
assert.strictEqual(membershipPage.membershipPlanSection.descriptionText, 'Your trial for the Monthly plan is currently active.');
66-
67-
await membershipPage.clickOnCancelTrialButton();
68-
assert.ok(membershipPage.cancelSubscriptionModal.isVisible);
69-
assert.ok(membershipPage.cancelSubscriptionModal.cancelButtonIsDisabled, 'cancel button is disabled without selecting a reason');
70-
71-
await membershipPage.cancelSubscriptionModal.selectReason('I need more content');
72-
assert.notOk(membershipPage.cancelSubscriptionModal.cancelButtonIsDisabled, 'cancel button is enabled after selecting a reason');
73-
74-
await membershipPage.cancelSubscriptionModal.selectReason('Other reason');
75-
assert.ok(membershipPage.cancelSubscriptionModal.cancelButtonIsDisabled, 'cancel button is disabled if other reason is selected');
76-
77-
await membershipPage.cancelSubscriptionModal.fillInReasonDescription('Feeling Blue');
78-
assert.notOk(membershipPage.cancelSubscriptionModal.cancelButtonIsDisabled, 'cancel button is enabled if other reason is provided');
79-
80-
assert.strictEqual(membershipPage.cancelSubscriptionModal.cancelButtonText, 'Cancel Trial');
81-
82-
await membershipPage.cancelSubscriptionModal.clickOnCancelSubscriptionButton();
83-
await settled(); // Investigate why clickable() doesn't call settled()
84-
85-
assert.notOk(membershipPage.cancelSubscriptionModal.isVisible);
86-
87-
assert.strictEqual(membershipPage.membershipPlanSection.descriptionText, 'Your CodeCrafters membership is currently inactive.');
88-
});
89-
9060
test('subscriber can cancel subscription', async function (assert) {
9161
testScenario(this.server);
9262
signInAsSubscriber(this.owner, this.server);

tests/acceptance/vote-page/course-ideas-test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ module('Acceptance | vote-page | course-ideas', function (hooks) {
1616
createCourseIdeas(this.server);
1717

1818
let courseIdea = this.server.schema.courseIdeas.first();
19-
courseIdea.update({ votesCount: 1 });
19+
courseIdea.update({ votesCount: 1, developmentStatus: 'released' });
2020

2121
await votePage.visit();
2222
await percySnapshot('Challenge Ideas (anonymous)');
2323

2424
assert.strictEqual(votePage.findCourseIdeaCard(courseIdea.name).voteButtonText, '1 vote');
25+
assert.ok(votePage.findCourseIdeaCard(courseIdea.name).isGreyedOut, 'should be greyed out if released');
2526

2627
const releasedIdeaCard = votePage.findCourseIdeaCard('Build your own Regex Parser');
2728
const notStartedIdeaCard = votePage.findCourseIdeaCard('Build your own Shell');

tests/support/authentication-helpers.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,3 @@ export function signInAsSubscribedTeamMember(owner, server) {
106106

107107
return signIn(owner, server, user);
108108
}
109-
110-
// TODO: Remove this?
111-
export function signInAsTrialingSubscriber(owner, server, user) {
112-
user = user || server.schema.users.find('63c51e91-e448-4ea9-821b-a80415f266d3');
113-
114-
server.create('subscription', {
115-
currentPeriodEnd: new Date(new Date().getTime() + 24 * 60 * 60 * 1000),
116-
user: user,
117-
pricingPlanName: 'Monthly',
118-
trialEnd: new Date(new Date().getTime() + 24 * 60 * 60 * 1000),
119-
});
120-
121-
return signIn(owner, server, user);
122-
}

0 commit comments

Comments
 (0)