Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tbt-267] plan valid to fix #2956

Merged
merged 8 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/components/billing/credit-balance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import { reads } from '@ember/object/computed';
import { subtractOneDay } from 'travis/utils/subtract-day';

export default Component.extend({

Expand All @@ -23,6 +24,11 @@ export default Component.extend({
}),
creditsPrivateValidDate: reads('subscription.addonUsage.private.validDate'),

formattedCreditsPrivateValidDate: computed('creditsPrivateValidDate', function () {
let validDate = this.get('creditsPrivateValidDate');
return subtractOneDay(validDate);
}),

creditsTotal: computed('creditsTab', 'creditsPublicTotal', 'creditsPrivateTotal', function () {
if (this.creditsTab === 1)
return this.creditsPublicTotal;
Expand Down
9 changes: 8 additions & 1 deletion app/components/billing/summary-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { computed } from '@ember/object';
import { reads, or, not, and, bool } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import isCurrentTrial from 'travis/utils/computed-is-current-trial';
import { subtractOneDay } from 'travis/utils/subtract-day';

const VALID_TO_FETCH_MAX_ATTEMPTS = 2;

Expand All @@ -28,6 +29,7 @@ export default Component.extend({
isSubscribed: computed('subscription.isSubscribed', function () {
return this.subscription.isSubscribed;
}),

validto: computed('subscription.validTo', function () {
try {
if (this.subscription.validTo == null && this.storage.subscriptionValidToAttempts < VALID_TO_FETCH_MAX_ATTEMPTS) {
Expand All @@ -37,8 +39,13 @@ export default Component.extend({
} catch (e) {
console.log(e);
}
return this.subscription.validToFromAddon || this.subscription.validTo;
return this.subscription.validTo || this.subscription.validToFromAddon;
}),

formattedValidTo: computed('validto', function () {
return subtractOneDay(this.validto);
}),

isCurrentTrial: isCurrentTrial(),
isExpired: or('subscription.isExpired', 'subscription.subscriptionExpiredByDate'),
canceledOrExpired: or('isExpired', 'isCanceled'),
Expand Down
7 changes: 7 additions & 0 deletions app/components/billing/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Component from '@ember/component';
import { computed } from '@ember/object';
import { reads, or, not, and, bool } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { subtractOneDay } from 'travis/utils/subtract-day';


export default Component.extend({
store: service(),
Expand Down Expand Up @@ -42,4 +44,9 @@ export default Component.extend({
subscriptionExpiredPrefix: computed('subscription.validTo', function () {
return Date.now() > Date.parse(this.subscription.validTo) ? 'Expired' : 'Expires';
}),

formattedValidTo: computed('subscription.validTo', function () {
let validDate = this.get('subscription.validTo');
return subtractOneDay(validDate);
}),
});
4 changes: 2 additions & 2 deletions app/templates/components/billing/credit-balance.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
{{#if this.subscription.isCanceled}}
{{format-number this.creditsAvailable}} available credits (expiry date: {{moment-format this.creditsValidityDate 'MMMM DD, YYYY'}})
{{else}}
{{format-number this.creditsAvailable}} available credits (purchase date: {{moment-format this.creditsPrivatePurchaseDate 'MMMM DD, YYYY'}}
{{format-number this.creditsAvailable}} available credits (purchased on: {{moment-format this.creditsPrivatePurchaseDate 'MMMM DD, YYYY'}}
{{#if this.creditsPrivateValidDate}}
, valid until: {{moment-format this.creditsPrivateValidDate 'MMMM DD, YYYY'}}
, valid until: {{this.formattedCreditsPrivateValidDate}}
{{/if}})
{{/if}}
{{/if}}
Expand Down
8 changes: 4 additions & 4 deletions app/templates/components/billing/summary-v2.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<span class="badge green square" data-test-active-status='true'>
active
</span>
{{else if this.subscription.isExpired}}
{{else if this.isExpired}}
<span class="badge red square" data-test-expired-status='true'>
expired
</span>
Expand All @@ -53,13 +53,13 @@
>
{{#if (and this.isSubscribed (not this.subscription.subscriptionExpiredByDate))}}
{{#if this.isCurrentTrial }}(Free Trial Period) {{/if}}
Valid until {{moment-format this.validto "MMMM D, YYYY"}}
Valid until {{this.formattedValidTo}}
{{else if this.isIncomplete}}
Incomplete
{{else if (and this.isComplete this.isCanceled)}}
{{this.subscriptionExpiredPrefix}} on {{moment-format this.subscription.validTo "MMMM D, YYYY"}}
{{else if (and this.isComplete this.isExpired)}}
{{this.subscriptionExpiredPrefix}} on {{moment-format this.subscription.validTo "MMMM D, YYYY"}}
{{this.subscriptionExpiredPrefix}} on {{this.formattedValidTo}}
{{/if}}
</span>

Expand Down Expand Up @@ -180,7 +180,7 @@
This manual subscription is paid to Travis CI by bank transfer. If you have any questions or would like to update your plan,
<ExternalLinkTo @href={{config-get 'urls.resources'}} @title="Travis CI Resources">
contact our support team.
</ExternalLinkTo>
</ExternalLinkTo>
</div>
<br />
{{#if (and this.subscription.hasUserLicenseAddons)}}
Expand Down
4 changes: 2 additions & 2 deletions app/templates/components/billing/summary.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{if this.canceledOrExpired 'dark-red' 'cement-grey'}}'
>
{{#if this.isSubscribed}}
Valid until {{moment-format this.subscription.validTo "MMMM D, YYYY"}}
Valid until {{this.formattedValidTo}}
{{else if this.isIncomplete}}
Incomplete
{{else if (and this.isComplete this.isCanceled)}}
Expand All @@ -47,7 +47,7 @@
{{else if (and this.isComplete this.subscription.cancellationRequested)}}
Expires {{moment-from-now this.subscription.validTo}} on {{moment-format this.subscription.validTo "MMMM D"}}, cancellation requested
{{else if (and this.isComplete this.isExpired)}}
{{this.subscriptionExpiredPrefix}} on {{moment-format this.subscription.validTo "MMMM D, YYYY"}}
{{this.subscriptionExpiredPrefix}} on {{this.formattedValidTo}}
{{/if}}
</span>
{{/if}}
Expand Down
5 changes: 5 additions & 0 deletions app/utils/subtract-day.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import moment from 'moment';

export function subtractOneDay(date) {
return moment(date).subtract(1, 'days').format('MMMM D, YYYY');
}
6 changes: 3 additions & 3 deletions tests/acceptance/profile/billing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ module('Acceptance | profile/billing', function (hooks) {
await profilePage.billing.visit();

assert.equal(profilePage.billing.plan.name, 'Small Business1 plan expired manual subscription');
assert.equal(profilePage.billing.planMessage.text, 'Expired on July 16, 2018');
assert.equal(profilePage.billing.planMessage.text, 'Expired on July 15, 2018');
assert.equal(profilePage.billing.price.text, '$69');
});

Expand Down Expand Up @@ -648,7 +648,7 @@ module('Acceptance | profile/billing', function (hooks) {
assert.ok(profilePage.billing.annualInvitation.isHidden);

assert.equal(profilePage.billing.plan.name, 'Small Business1 plan expired github marketplace subscription');
assert.equal(profilePage.billing.planMessage.text, 'Expired on June 19, 2018');
assert.equal(profilePage.billing.planMessage.text, 'Expired on June 18, 2018');
});

test('view billing on an annual plan', async function (assert) {
Expand Down Expand Up @@ -1043,7 +1043,7 @@ module('Acceptance | profile/billing', function (hooks) {
await profilePage.billing.visit();

assert.equal(profilePage.billing.plan.name, 'Unknown plan active');
assert.dom(profilePage.billing.plan.concurrency.scope).hasTextContaining('Unknown concurrent jobs Valid until June 19, 2018');
assert.dom(profilePage.billing.plan.concurrency.scope).hasTextContaining('Unknown concurrent jobs Valid until June 18, 2018');
assert.ok(profilePage.billing.price.isHidden);
assert.ok(profilePage.billing.annualInvitation.isHidden);
});
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/components/billing/summary-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module('Integration | Component | billing-summary', function (hooks) {
});

test('it renders active subscription', async function (assert) {
const date = moment(this.subscription.validTo.getTime()).format('MMMM D, YYYY');
const date = moment(this.subscription.validTo.getTime()).subtract(1, 'days').format('MMMM D, YYYY');

await render(hbs`<Billing::Summary
@subscription={{this.subscription}}
Expand Down Expand Up @@ -89,7 +89,7 @@ module('Integration | Component | billing-summary', function (hooks) {
});

test('it renders expired subscription', async function (assert) {
const date = moment(this.subscription.validTo.getTime()).format('MMMM D, YYYY');
const date = moment(this.subscription.validTo.getTime()).subtract(1, 'days').format('MMMM D, YYYY');

this.set('subscription', {
...this.subscription,
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/components/billing/summary-v2-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module('Integration | Component | billing-summary-v2', function (hooks) {
});

test('it renders active subscription', async function (assert) {
const date = moment(this.subscription.validTo.getTime()).format('MMMM D, YYYY');
const date = moment(this.subscription.validTo.getTime()).subtract(1, 'days').format('MMMM D, YYYY');

await render(hbs`<Billing::SummaryV2
@subscription={{this.subscription}}
Expand All @@ -75,7 +75,7 @@ module('Integration | Component | billing-summary-v2', function (hooks) {
});

test('it renders active subscription with trial', async function (assert) {
const date = moment(this.subscription.validTo.getTime()).format('MMMM D, YYYY');
const date = moment(this.subscription.validTo.getTime()).subtract(1, 'days').format('MMMM D, YYYY');

const owner = {
get() {
Expand Down Expand Up @@ -138,7 +138,7 @@ module('Integration | Component | billing-summary-v2', function (hooks) {
});

test('it renders expired subscription', async function (assert) {
const date = moment(this.subscription.validTo.getTime()).format('MMMM D, YYYY');
const date = moment(this.subscription.validTo.getTime()).subtract(1, 'days').format('MMMM D, YYYY');

this.set('subscription', {
...this.subscription,
Expand Down