Skip to content

Commit 5c1bf3e

Browse files
authored
Merge pull request #15012 from mozilla/train-253-uplift-4
Train 253 - Uplift 4
2 parents c5c4daa + 409576f commit 5c1bf3e

File tree

4 files changed

+73
-5
lines changed

4 files changed

+73
-5
lines changed

packages/fxa-auth-server/test/local/payments/stripe.js

+41
Original file line numberDiff line numberDiff line change
@@ -4607,6 +4607,47 @@ describe('#integration - StripeHelper', () => {
46074607
const actual = await stripeHelper.subscriptionsToResponse(input);
46084608
assert.deepEqual(actual, expected);
46094609
});
4610+
4611+
it('formats the subscription, when total_excluding_tax and subtotal_excluding_tax are not set', async () => {
4612+
const missingExcludingTaxPaidInvoice = deepCopy(paidInvoice);
4613+
delete missingExcludingTaxPaidInvoice.total_excluding_tax;
4614+
delete missingExcludingTaxPaidInvoice.subtotal_excluding_tax;
4615+
const latestInvoiceItems = stripeInvoiceToLatestInvoiceItemsDTO(
4616+
missingExcludingTaxPaidInvoice
4617+
);
4618+
const input = { data: [subscription1] };
4619+
sandbox
4620+
.stub(stripeHelper.stripe.invoices, 'retrieve')
4621+
.resolves(missingExcludingTaxPaidInvoice);
4622+
const callback = sandbox.stub(stripeHelper, 'expandResource');
4623+
callback.onCall(0).resolves(missingExcludingTaxPaidInvoice);
4624+
callback.onCall(1).resolves({ id: productId, name: productName });
4625+
const expected = [
4626+
{
4627+
_subscription_type: MozillaSubscriptionTypes.WEB,
4628+
created: subscription1.created,
4629+
current_period_end: subscription1.current_period_end,
4630+
current_period_start: subscription1.current_period_start,
4631+
cancel_at_period_end: false,
4632+
end_at: null,
4633+
plan_id: subscription1.plan.id,
4634+
product_id: product1.id,
4635+
product_name: productName,
4636+
status: 'active',
4637+
subscription_id: subscription1.id,
4638+
failure_code: undefined,
4639+
failure_message: undefined,
4640+
latest_invoice: paidInvoice.number,
4641+
latest_invoice_items: latestInvoiceItems,
4642+
promotion_code: null,
4643+
promotion_duration: null,
4644+
promotion_end: null,
4645+
},
4646+
];
4647+
4648+
const actual = await stripeHelper.subscriptionsToResponse(input);
4649+
assert.deepEqual(actual, expected);
4650+
});
46104651
});
46114652

46124653
describe('when the subscription is set to cancel', () => {

packages/fxa-auth-server/test/local/routes/validators.js

+14
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,20 @@ describe('lib/routes/validators:', () => {
849849
assert.ok(!res.error);
850850
});
851851

852+
it('accepts a Stripe subscription with missing or undefined optional parameters', () => {
853+
const stripeSubMissing = deepCopy(stripeSub);
854+
const stripeSubUndefined = deepCopy(stripeSub);
855+
delete stripeSubMissing.latest_invoice_items.subtotal_excluding_tax;
856+
stripeSubUndefined.latest_invoice_items.subtotal_excluding_tax =
857+
undefined;
858+
859+
const res =
860+
validators.subscriptionsMozillaSubscriptionsValidator.validate({
861+
subscriptions: [stripeSubMissing, stripeSubUndefined],
862+
});
863+
assert.ok(!res.error);
864+
});
865+
852866
it('accepts a list with only Google Play subscriptions', () => {
853867
const res =
854868
validators.subscriptionsMozillaSubscriptionsValidator.validate({

packages/fxa-payments-server/src/components/PaymentConfirmation/index.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Customer, Profile, Plan } from '../../store/types';
99
import { PAYPAL_CUSTOMER } from '../../lib/mock-data';
1010
import { MozillaSubscriptionTypes } from 'fxa-shared/subscriptions/types';
1111
import { Meta } from '@storybook/react';
12-
import { LatestInvoiceItems } from 'fxa-shared/dto/auth/payments/invoice';
12+
import { FirstInvoicePreview } from 'fxa-shared/dto/auth/payments/invoice';
1313

1414
export default {
1515
title: 'components/PaymentConfirmation',
@@ -49,7 +49,7 @@ const selectedPlanWithMetadata: Plan = {
4949
},
5050
};
5151

52-
const invoice: LatestInvoiceItems = {
52+
const invoice: FirstInvoicePreview = {
5353
line_items: [],
5454
subtotal: 735,
5555
subtotal_excluding_tax: null,

packages/fxa-shared/dto/auth/payments/invoice.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,21 @@ export type subsequentInvoicePreview = {
137137

138138
export type subsequentInvoicePreviewsSchema = Array<subsequentInvoicePreview>;
139139

140-
export interface LatestInvoiceItems extends FirstInvoicePreview {}
140+
export interface LatestInvoiceItems
141+
extends Omit<
142+
FirstInvoicePreview,
143+
'subtotal_excluding_tax' | 'total_excluding_tax'
144+
> {
145+
subtotal_excluding_tax?: number | null;
146+
total_excluding_tax?: number | null;
147+
}
141148

142-
export const latestInvoiceItemsSchema = firstInvoicePreviewSchema;
149+
export const latestInvoiceItemsSchema = firstInvoicePreviewSchema.fork(
150+
['subtotal_excluding_tax', 'total_excluding_tax'],
151+
(schema) => schema.optional().allow(null)
152+
);
143153

144-
export type latestInvoiceItemsSchema = firstInvoicePreviewSchema;
154+
export type latestInvoiceItemsSchema = firstInvoicePreviewSchema & {
155+
subtotal_excluding_tax?: number | null;
156+
total_excluding_tax?: number | null;
157+
};

0 commit comments

Comments
 (0)