diff --git a/app/components/billing/credit-balance.js b/app/components/billing/credit-balance.js index 106cf5417a..63a5a6d17f 100644 --- a/app/components/billing/credit-balance.js +++ b/app/components/billing/credit-balance.js @@ -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({ @@ -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; diff --git a/app/components/billing/summary-v2.js b/app/components/billing/summary-v2.js index c75fd09582..96d2397032 100644 --- a/app/components/billing/summary-v2.js +++ b/app/components/billing/summary-v2.js @@ -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; @@ -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) { @@ -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'), diff --git a/app/components/billing/summary.js b/app/components/billing/summary.js index 27ebe49829..6b21ec1928 100644 --- a/app/components/billing/summary.js +++ b/app/components/billing/summary.js @@ -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(), @@ -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); + }), }); diff --git a/app/templates/components/billing/credit-balance.hbs b/app/templates/components/billing/credit-balance.hbs index a47652a760..1262017850 100644 --- a/app/templates/components/billing/credit-balance.hbs +++ b/app/templates/components/billing/credit-balance.hbs @@ -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}} diff --git a/app/templates/components/billing/summary-v2.hbs b/app/templates/components/billing/summary-v2.hbs index 7e09942532..a1dad1c215 100644 --- a/app/templates/components/billing/summary-v2.hbs +++ b/app/templates/components/billing/summary-v2.hbs @@ -39,7 +39,7 @@ active - {{else if this.subscription.isExpired}} + {{else if this.isExpired}} expired @@ -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}} @@ -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, contact our support team. - +
{{#if (and this.subscription.hasUserLicenseAddons)}} diff --git a/app/templates/components/billing/summary.hbs b/app/templates/components/billing/summary.hbs index 47919017fa..048a0f5880 100644 --- a/app/templates/components/billing/summary.hbs +++ b/app/templates/components/billing/summary.hbs @@ -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)}} @@ -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}} {{/if}} diff --git a/app/utils/subtract-day.js b/app/utils/subtract-day.js new file mode 100644 index 0000000000..2e175c570d --- /dev/null +++ b/app/utils/subtract-day.js @@ -0,0 +1,5 @@ +import moment from 'moment'; + +export function subtractOneDay(date) { + return moment(date).subtract(1, 'days').format('MMMM D, YYYY'); +} diff --git a/tests/acceptance/profile/billing-test.js b/tests/acceptance/profile/billing-test.js index f6c99ce87a..2de1e61442 100644 --- a/tests/acceptance/profile/billing-test.js +++ b/tests/acceptance/profile/billing-test.js @@ -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'); }); @@ -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) { @@ -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); }); diff --git a/tests/integration/components/billing/summary-test.js b/tests/integration/components/billing/summary-test.js index 7af9ea23ab..f705ff3d6e 100644 --- a/tests/integration/components/billing/summary-test.js +++ b/tests/integration/components/billing/summary-test.js @@ -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`