зеркало из https://github.com/mozilla/fxa.git
fix(contentful): Fix Contentful errors around complexity - EligibilityContentByPlanIds
This commit is contained in:
Родитель
208b51b3c8
Коммит
3c34572801
|
@ -13,12 +13,18 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
|
|||
* Therefore it is highly recommended to use the babel or swc plugin for production.
|
||||
*/
|
||||
const documents = {
|
||||
"\n query CapabilityServiceByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeLegacyPlans\n capabilitiesCollection(skip: 0, limit: 25) {\n items {\n slug\n servicesCollection(skip: 0, limit: 15) {\n items {\n oauthClientId\n }\n }\n }\n }\n }\n }\n }\n }\n": types.CapabilityServiceByPlanIdsDocument,
|
||||
"\n query EligibilityContentByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n offering {\n stripeProductId\n stripeLegacyPlans\n countries\n linkedFrom {\n subGroupCollection(skip: $skip, limit: $limit) {\n items {\n groupName\n offeringCollection(skip: $skip, limit: $limit) {\n items {\n stripeProductId\n stripeLegacyPlans\n countries\n }\n }\n }\n }\n }\n }\n }\n }\n }\n": types.EligibilityContentByPlanIdsDocument,
|
||||
"\n query Offering($id: String!, $locale: String!) {\n offering(id: $id, locale: $locale) {\n stripeProductId\n countries\n defaultPurchase {\n purchaseDetails {\n productName\n details\n subtitle\n webIcon\n }\n }\n }\n }\n": types.OfferingDocument,
|
||||
"\n query PurchaseWithDetailsOfferingContent(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n purchaseDetails {\n details\n productName\n subtitle\n webIcon\n }\n offering {\n stripeProductId\n stripeLegacyPlans\n commonContent {\n privacyNoticeUrl\n privacyNoticeDownloadUrl\n termsOfServiceUrl\n termsOfServiceDownloadUrl\n cancellationUrl\n emailIcon\n successActionButtonUrl\n successActionButtonLabel\n newsletterLabelTextCode\n newsletterSlug\n }\n }\n }\n }\n }\n": types.PurchaseWithDetailsOfferingContentDocument,
|
||||
"\n query PurchaseWithDetails($id: String!, $locale: String!) {\n purchase(id: $id, locale: $locale) {\n internalName\n description\n purchaseDetails {\n productName\n details\n webIcon\n }\n }\n }\n": types.PurchaseWithDetailsDocument,
|
||||
"\n query ServicesWithCapabilities($skip: Int!, $limit: Int!, $locale: String!) {\n serviceCollection(skip: $skip, limit: $limit, locale: $locale) {\n items {\n oauthClientId\n capabilitiesCollection(skip: $skip, limit: $limit) {\n items {\n slug\n }\n }\n }\n }\n }\n": types.ServicesWithCapabilitiesDocument,
|
||||
'\n query CapabilityServiceByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeLegacyPlans\n capabilitiesCollection(skip: 0, limit: 25) {\n items {\n slug\n servicesCollection(skip: 0, limit: 15) {\n items {\n oauthClientId\n }\n }\n }\n }\n }\n }\n }\n }\n':
|
||||
types.CapabilityServiceByPlanIdsDocument,
|
||||
'\n query EligibilityContentByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeProductId\n stripeLegacyPlans\n countries\n linkedFrom {\n subGroupCollection(skip: 0, limit: 25) {\n items {\n groupName\n offeringCollection(skip: 0, limit: 20) {\n items {\n stripeProductId\n stripeLegacyPlans\n countries\n }\n }\n }\n }\n }\n }\n }\n }\n }\n':
|
||||
types.EligibilityContentByPlanIdsDocument,
|
||||
'\n query Offering($id: String!, $locale: String!) {\n offering(id: $id, locale: $locale) {\n stripeProductId\n countries\n defaultPurchase {\n purchaseDetails {\n productName\n details\n subtitle\n webIcon\n }\n }\n }\n }\n':
|
||||
types.OfferingDocument,
|
||||
'\n query PurchaseWithDetailsOfferingContent(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n purchaseDetails {\n details\n productName\n subtitle\n webIcon\n }\n offering {\n stripeProductId\n stripeLegacyPlans\n commonContent {\n privacyNoticeUrl\n privacyNoticeDownloadUrl\n termsOfServiceUrl\n termsOfServiceDownloadUrl\n cancellationUrl\n emailIcon\n successActionButtonUrl\n successActionButtonLabel\n newsletterLabelTextCode\n newsletterSlug\n }\n }\n }\n }\n }\n':
|
||||
types.PurchaseWithDetailsOfferingContentDocument,
|
||||
'\n query PurchaseWithDetails($id: String!, $locale: String!) {\n purchase(id: $id, locale: $locale) {\n internalName\n description\n purchaseDetails {\n productName\n details\n webIcon\n }\n }\n }\n':
|
||||
types.PurchaseWithDetailsDocument,
|
||||
'\n query ServicesWithCapabilities($skip: Int!, $limit: Int!, $locale: String!) {\n serviceCollection(skip: $skip, limit: $limit, locale: $locale) {\n items {\n oauthClientId\n capabilitiesCollection(skip: $skip, limit: $limit) {\n items {\n slug\n }\n }\n }\n }\n }\n':
|
||||
types.ServicesWithCapabilitiesDocument,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -38,30 +44,43 @@ export function graphql(source: string): unknown;
|
|||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n query CapabilityServiceByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeLegacyPlans\n capabilitiesCollection(skip: 0, limit: 25) {\n items {\n slug\n servicesCollection(skip: 0, limit: 15) {\n items {\n oauthClientId\n }\n }\n }\n }\n }\n }\n }\n }\n"): (typeof documents)["\n query CapabilityServiceByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeLegacyPlans\n capabilitiesCollection(skip: 0, limit: 25) {\n items {\n slug\n servicesCollection(skip: 0, limit: 15) {\n items {\n oauthClientId\n }\n }\n }\n }\n }\n }\n }\n }\n"];
|
||||
export function graphql(
|
||||
source: '\n query CapabilityServiceByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeLegacyPlans\n capabilitiesCollection(skip: 0, limit: 25) {\n items {\n slug\n servicesCollection(skip: 0, limit: 15) {\n items {\n oauthClientId\n }\n }\n }\n }\n }\n }\n }\n }\n'
|
||||
): (typeof documents)['\n query CapabilityServiceByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeLegacyPlans\n capabilitiesCollection(skip: 0, limit: 25) {\n items {\n slug\n servicesCollection(skip: 0, limit: 15) {\n items {\n oauthClientId\n }\n }\n }\n }\n }\n }\n }\n }\n'];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n query EligibilityContentByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n offering {\n stripeProductId\n stripeLegacyPlans\n countries\n linkedFrom {\n subGroupCollection(skip: $skip, limit: $limit) {\n items {\n groupName\n offeringCollection(skip: $skip, limit: $limit) {\n items {\n stripeProductId\n stripeLegacyPlans\n countries\n }\n }\n }\n }\n }\n }\n }\n }\n }\n"): (typeof documents)["\n query EligibilityContentByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n offering {\n stripeProductId\n stripeLegacyPlans\n countries\n linkedFrom {\n subGroupCollection(skip: $skip, limit: $limit) {\n items {\n groupName\n offeringCollection(skip: $skip, limit: $limit) {\n items {\n stripeProductId\n stripeLegacyPlans\n countries\n }\n }\n }\n }\n }\n }\n }\n }\n }\n"];
|
||||
export function graphql(
|
||||
source: '\n query EligibilityContentByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeProductId\n stripeLegacyPlans\n countries\n linkedFrom {\n subGroupCollection(skip: 0, limit: 25) {\n items {\n groupName\n offeringCollection(skip: 0, limit: 20) {\n items {\n stripeProductId\n stripeLegacyPlans\n countries\n }\n }\n }\n }\n }\n }\n }\n }\n }\n'
|
||||
): (typeof documents)['\n query EligibilityContentByPlanIds(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n total\n items {\n stripePlanChoices\n offering {\n stripeProductId\n stripeLegacyPlans\n countries\n linkedFrom {\n subGroupCollection(skip: 0, limit: 25) {\n items {\n groupName\n offeringCollection(skip: 0, limit: 20) {\n items {\n stripeProductId\n stripeLegacyPlans\n countries\n }\n }\n }\n }\n }\n }\n }\n }\n }\n'];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n query Offering($id: String!, $locale: String!) {\n offering(id: $id, locale: $locale) {\n stripeProductId\n countries\n defaultPurchase {\n purchaseDetails {\n productName\n details\n subtitle\n webIcon\n }\n }\n }\n }\n"): (typeof documents)["\n query Offering($id: String!, $locale: String!) {\n offering(id: $id, locale: $locale) {\n stripeProductId\n countries\n defaultPurchase {\n purchaseDetails {\n productName\n details\n subtitle\n webIcon\n }\n }\n }\n }\n"];
|
||||
export function graphql(
|
||||
source: '\n query Offering($id: String!, $locale: String!) {\n offering(id: $id, locale: $locale) {\n stripeProductId\n countries\n defaultPurchase {\n purchaseDetails {\n productName\n details\n subtitle\n webIcon\n }\n }\n }\n }\n'
|
||||
): (typeof documents)['\n query Offering($id: String!, $locale: String!) {\n offering(id: $id, locale: $locale) {\n stripeProductId\n countries\n defaultPurchase {\n purchaseDetails {\n productName\n details\n subtitle\n webIcon\n }\n }\n }\n }\n'];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n query PurchaseWithDetailsOfferingContent(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n purchaseDetails {\n details\n productName\n subtitle\n webIcon\n }\n offering {\n stripeProductId\n stripeLegacyPlans\n commonContent {\n privacyNoticeUrl\n privacyNoticeDownloadUrl\n termsOfServiceUrl\n termsOfServiceDownloadUrl\n cancellationUrl\n emailIcon\n successActionButtonUrl\n successActionButtonLabel\n newsletterLabelTextCode\n newsletterSlug\n }\n }\n }\n }\n }\n"): (typeof documents)["\n query PurchaseWithDetailsOfferingContent(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n purchaseDetails {\n details\n productName\n subtitle\n webIcon\n }\n offering {\n stripeProductId\n stripeLegacyPlans\n commonContent {\n privacyNoticeUrl\n privacyNoticeDownloadUrl\n termsOfServiceUrl\n termsOfServiceDownloadUrl\n cancellationUrl\n emailIcon\n successActionButtonUrl\n successActionButtonLabel\n newsletterLabelTextCode\n newsletterSlug\n }\n }\n }\n }\n }\n"];
|
||||
export function graphql(
|
||||
source: '\n query PurchaseWithDetailsOfferingContent(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n purchaseDetails {\n details\n productName\n subtitle\n webIcon\n }\n offering {\n stripeProductId\n stripeLegacyPlans\n commonContent {\n privacyNoticeUrl\n privacyNoticeDownloadUrl\n termsOfServiceUrl\n termsOfServiceDownloadUrl\n cancellationUrl\n emailIcon\n successActionButtonUrl\n successActionButtonLabel\n newsletterLabelTextCode\n newsletterSlug\n }\n }\n }\n }\n }\n'
|
||||
): (typeof documents)['\n query PurchaseWithDetailsOfferingContent(\n $skip: Int!\n $limit: Int!\n $locale: String!\n $stripePlanIds: [String]!\n ) {\n purchaseCollection(\n skip: $skip\n limit: $limit\n locale: $locale\n where: {\n OR: [\n { stripePlanChoices_contains_some: $stripePlanIds }\n { offering: { stripeLegacyPlans_contains_some: $stripePlanIds } }\n ]\n }\n ) {\n items {\n stripePlanChoices\n purchaseDetails {\n details\n productName\n subtitle\n webIcon\n }\n offering {\n stripeProductId\n stripeLegacyPlans\n commonContent {\n privacyNoticeUrl\n privacyNoticeDownloadUrl\n termsOfServiceUrl\n termsOfServiceDownloadUrl\n cancellationUrl\n emailIcon\n successActionButtonUrl\n successActionButtonLabel\n newsletterLabelTextCode\n newsletterSlug\n }\n }\n }\n }\n }\n'];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n query PurchaseWithDetails($id: String!, $locale: String!) {\n purchase(id: $id, locale: $locale) {\n internalName\n description\n purchaseDetails {\n productName\n details\n webIcon\n }\n }\n }\n"): (typeof documents)["\n query PurchaseWithDetails($id: String!, $locale: String!) {\n purchase(id: $id, locale: $locale) {\n internalName\n description\n purchaseDetails {\n productName\n details\n webIcon\n }\n }\n }\n"];
|
||||
export function graphql(
|
||||
source: '\n query PurchaseWithDetails($id: String!, $locale: String!) {\n purchase(id: $id, locale: $locale) {\n internalName\n description\n purchaseDetails {\n productName\n details\n webIcon\n }\n }\n }\n'
|
||||
): (typeof documents)['\n query PurchaseWithDetails($id: String!, $locale: String!) {\n purchase(id: $id, locale: $locale) {\n internalName\n description\n purchaseDetails {\n productName\n details\n webIcon\n }\n }\n }\n'];
|
||||
/**
|
||||
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
|
||||
*/
|
||||
export function graphql(source: "\n query ServicesWithCapabilities($skip: Int!, $limit: Int!, $locale: String!) {\n serviceCollection(skip: $skip, limit: $limit, locale: $locale) {\n items {\n oauthClientId\n capabilitiesCollection(skip: $skip, limit: $limit) {\n items {\n slug\n }\n }\n }\n }\n }\n"): (typeof documents)["\n query ServicesWithCapabilities($skip: Int!, $limit: Int!, $locale: String!) {\n serviceCollection(skip: $skip, limit: $limit, locale: $locale) {\n items {\n oauthClientId\n capabilitiesCollection(skip: $skip, limit: $limit) {\n items {\n slug\n }\n }\n }\n }\n }\n"];
|
||||
export function graphql(
|
||||
source: '\n query ServicesWithCapabilities($skip: Int!, $limit: Int!, $locale: String!) {\n serviceCollection(skip: $skip, limit: $limit, locale: $locale) {\n items {\n oauthClientId\n capabilitiesCollection(skip: $skip, limit: $limit) {\n items {\n slug\n }\n }\n }\n }\n }\n'
|
||||
): (typeof documents)['\n query ServicesWithCapabilities($skip: Int!, $limit: Int!, $locale: String!) {\n serviceCollection(skip: $skip, limit: $limit, locale: $locale) {\n items {\n oauthClientId\n capabilitiesCollection(skip: $skip, limit: $limit) {\n items {\n slug\n }\n }\n }\n }\n }\n'];
|
||||
|
||||
export function graphql(source: string) {
|
||||
return (documents as any)[source] ?? {};
|
||||
}
|
||||
|
||||
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> = TDocumentNode extends DocumentNode< infer TType, any> ? TType : never;
|
||||
export type DocumentType<TDocumentNode extends DocumentNode<any, any>> =
|
||||
TDocumentNode extends DocumentNode<infer TType, any> ? TType : never;
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -12,6 +12,8 @@ import {
|
|||
CapabilityServiceByPlanIdsResultUtil,
|
||||
EligibilityContentByPlanIdsQueryFactory,
|
||||
EligibilityContentByPlanIdsResultUtil,
|
||||
EligibilityPurchaseResult,
|
||||
EligibilityPurchaseResultFactory,
|
||||
ServicesWithCapabilitiesQueryFactory,
|
||||
ServicesWithCapabilitiesResultUtil,
|
||||
} from '../../src';
|
||||
|
@ -40,25 +42,53 @@ describe('ContentfulManager', () => {
|
|||
|
||||
describe('getPurchaseDetailsForEligibility', () => {
|
||||
it('should return empty result', async () => {
|
||||
mockClient.query = jest.fn().mockReturnValue({
|
||||
purchaseCollection: { items: [] },
|
||||
const queryData = EligibilityContentByPlanIdsQueryFactory({
|
||||
purchaseCollection: { items: [], total: 0 },
|
||||
});
|
||||
mockClient.query = jest.fn().mockReturnValue(queryData);
|
||||
const result = await manager.getPurchaseDetailsForEligibility(['test']);
|
||||
expect(result).toBeInstanceOf(EligibilityContentByPlanIdsResultUtil);
|
||||
expect(result.offeringForPlanId('test')).toBeUndefined;
|
||||
expect(result.purchaseCollection.items).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should return successfully with subgroups and offering', async () => {
|
||||
const queryData = EligibilityContentByPlanIdsQueryFactory();
|
||||
const planId = 'test';
|
||||
const purchaseResult = [
|
||||
EligibilityPurchaseResultFactory({ stripePlanChoices: [planId] }),
|
||||
];
|
||||
const queryData = EligibilityContentByPlanIdsQueryFactory({
|
||||
purchaseCollection: {
|
||||
items: purchaseResult,
|
||||
total: purchaseResult.length,
|
||||
},
|
||||
});
|
||||
mockClient.query = jest.fn().mockResolvedValueOnce(queryData);
|
||||
const result = await manager.getPurchaseDetailsForEligibility(['test']);
|
||||
const planId = result.purchaseCollection.items[0].stripePlanChoices[0];
|
||||
expect(result).toBeInstanceOf(EligibilityContentByPlanIdsResultUtil);
|
||||
expect(
|
||||
result.offeringForPlanId(planId)?.linkedFrom.subGroupCollection.items
|
||||
).toHaveLength(1);
|
||||
expect(result.offeringForPlanId(planId)).toBeDefined();
|
||||
});
|
||||
|
||||
it('should return successfully with paging', async () => {
|
||||
const pageSize = 20;
|
||||
const purchaseResult: EligibilityPurchaseResult[] = [];
|
||||
for (let i = 0; i < pageSize + 1; i += 1) {
|
||||
purchaseResult.push(EligibilityPurchaseResultFactory());
|
||||
}
|
||||
const queryData = EligibilityContentByPlanIdsQueryFactory({
|
||||
purchaseCollection: {
|
||||
items: purchaseResult,
|
||||
total: purchaseResult.length,
|
||||
},
|
||||
});
|
||||
mockClient.query = jest.fn().mockResolvedValue(queryData);
|
||||
const result = await manager.getPurchaseDetailsForEligibility(['test']);
|
||||
expect(result).toBeInstanceOf(EligibilityContentByPlanIdsResultUtil);
|
||||
expect(mockClient.query).toBeCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPurchaseDetailsForCapabilityServiceByPlanId', () => {
|
||||
|
|
|
@ -65,19 +65,29 @@ export class ContentfulManager {
|
|||
async getPurchaseDetailsForEligibility(
|
||||
stripePlanIds: string[]
|
||||
): Promise<EligibilityContentByPlanIdsResultUtil> {
|
||||
const queryResult = await this.client.query(
|
||||
eligibilityContentByPlanIdsQuery,
|
||||
{
|
||||
skip: 0,
|
||||
limit: 100,
|
||||
locale: DEFAULT_LOCALE,
|
||||
stripePlanIds,
|
||||
}
|
||||
);
|
||||
let total: number | undefined;
|
||||
let count = 0;
|
||||
const queryResults: DeepNonNullable<EligibilityContentByPlanIdsQuery>[] =
|
||||
[];
|
||||
const pageSize = 20;
|
||||
|
||||
return new EligibilityContentByPlanIdsResultUtil(
|
||||
queryResult as DeepNonNullable<EligibilityContentByPlanIdsQuery>
|
||||
);
|
||||
while (total === undefined || count < total) {
|
||||
const queryResult = (await this.client.query(
|
||||
eligibilityContentByPlanIdsQuery,
|
||||
{
|
||||
skip: count,
|
||||
limit: pageSize,
|
||||
locale: DEFAULT_LOCALE,
|
||||
stripePlanIds,
|
||||
}
|
||||
)) as DeepNonNullable<EligibilityContentByPlanIdsQuery>;
|
||||
|
||||
queryResults.push(queryResult);
|
||||
count += pageSize;
|
||||
total = queryResult.purchaseCollection.total;
|
||||
}
|
||||
|
||||
return new EligibilityContentByPlanIdsResultUtil(queryResults);
|
||||
}
|
||||
|
||||
async getServicesWithCapabilities(): Promise<ServicesWithCapabilitiesResultUtil> {
|
||||
|
|
|
@ -7,6 +7,7 @@ import { faker } from '@faker-js/faker';
|
|||
import { EligibilityContentByPlanIdsQuery } from '../../../__generated__/graphql';
|
||||
import {
|
||||
EligibilityOfferingResult,
|
||||
EligibilityPurchaseResult,
|
||||
EligibilitySubgroupOfferingResult,
|
||||
EligibilitySubgroupResult,
|
||||
} from '.';
|
||||
|
@ -14,19 +15,24 @@ import {
|
|||
export const EligibilityContentByPlanIdsQueryFactory = (
|
||||
override?: Partial<EligibilityContentByPlanIdsQuery>
|
||||
): EligibilityContentByPlanIdsQuery => {
|
||||
const items = [EligibilityPurchaseResultFactory()];
|
||||
return {
|
||||
purchaseCollection: {
|
||||
items: [
|
||||
{
|
||||
stripePlanChoices: [faker.string.sample()],
|
||||
offering: EligibilityOfferingResultFactory(),
|
||||
},
|
||||
],
|
||||
total: items.length,
|
||||
items,
|
||||
},
|
||||
...override,
|
||||
};
|
||||
};
|
||||
|
||||
export const EligibilityPurchaseResultFactory = (
|
||||
override?: Partial<EligibilityPurchaseResult>
|
||||
): EligibilityPurchaseResult => ({
|
||||
stripePlanChoices: [faker.string.sample()],
|
||||
offering: EligibilityOfferingResultFactory(),
|
||||
...override,
|
||||
});
|
||||
|
||||
export const EligibilityOfferingResultFactory = (
|
||||
override?: Partial<EligibilityOfferingResult>
|
||||
): EligibilityOfferingResult => ({
|
||||
|
|
|
@ -22,6 +22,7 @@ export const eligibilityContentByPlanIdsQuery = graphql(`
|
|||
]
|
||||
}
|
||||
) {
|
||||
total
|
||||
items {
|
||||
stripePlanChoices
|
||||
offering {
|
||||
|
@ -29,10 +30,10 @@ export const eligibilityContentByPlanIdsQuery = graphql(`
|
|||
stripeLegacyPlans
|
||||
countries
|
||||
linkedFrom {
|
||||
subGroupCollection(skip: $skip, limit: $limit) {
|
||||
subGroupCollection(skip: 0, limit: 25) {
|
||||
items {
|
||||
groupName
|
||||
offeringCollection(skip: $skip, limit: $limit) {
|
||||
offeringCollection(skip: 0, limit: 20) {
|
||||
items {
|
||||
stripeProductId
|
||||
stripeLegacyPlans
|
||||
|
|
|
@ -33,6 +33,7 @@ export interface EligibilityPurchaseResult {
|
|||
|
||||
export interface EligibilityContentByPlanIdsResult {
|
||||
purchaseCollection: {
|
||||
total: number;
|
||||
items: EligibilityPurchaseResult[];
|
||||
};
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ describe('EligibilityContentByPlanIdsResultUtil', () => {
|
|||
const purchase = result.purchaseCollection?.items[0];
|
||||
const planId = purchase?.stripePlanChoices?.[0];
|
||||
const legacyPlanId = purchase?.offering?.stripeLegacyPlans?.[0];
|
||||
const util = new EligibilityContentByPlanIdsResultUtil(
|
||||
result as EligibilityContentByPlanIdsResult
|
||||
);
|
||||
const util = new EligibilityContentByPlanIdsResultUtil([
|
||||
result as EligibilityContentByPlanIdsResult,
|
||||
]);
|
||||
expect(util).toBeDefined();
|
||||
expect(util.offeringForPlanId(planId ?? '')?.stripeProductId).toBeDefined();
|
||||
expect(
|
||||
|
|
|
@ -11,15 +11,17 @@ import {
|
|||
export class EligibilityContentByPlanIdsResultUtil {
|
||||
private purchaseByPlanId: Record<string, EligibilityPurchaseResult> = {};
|
||||
|
||||
constructor(private rawResult: EligibilityContentByPlanIdsResult) {
|
||||
for (const purchase of rawResult.purchaseCollection.items) {
|
||||
purchase.stripePlanChoices?.forEach((planId) => {
|
||||
this.purchaseByPlanId[planId] = purchase;
|
||||
});
|
||||
constructor(private rawResults: EligibilityContentByPlanIdsResult[]) {
|
||||
for (const rawResult of rawResults) {
|
||||
for (const purchase of rawResult.purchaseCollection.items) {
|
||||
purchase.stripePlanChoices?.forEach((planId) => {
|
||||
this.purchaseByPlanId[planId] = purchase;
|
||||
});
|
||||
|
||||
purchase.offering.stripeLegacyPlans?.forEach((planId) => {
|
||||
this.purchaseByPlanId[planId] = purchase;
|
||||
});
|
||||
purchase.offering.stripeLegacyPlans?.forEach((planId) => {
|
||||
this.purchaseByPlanId[planId] = purchase;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,7 +29,17 @@ export class EligibilityContentByPlanIdsResultUtil {
|
|||
return this.purchaseByPlanId[planId]?.offering;
|
||||
}
|
||||
|
||||
get purchaseCollection() {
|
||||
return this.rawResult.purchaseCollection;
|
||||
get purchaseCollection(): EligibilityContentByPlanIdsResult['purchaseCollection'] {
|
||||
return {
|
||||
total: this.rawResults.length,
|
||||
items: [
|
||||
...new Map(
|
||||
this.rawResults
|
||||
.map((rawResult) => rawResult.purchaseCollection.items)
|
||||
.flat()
|
||||
.map((res) => [JSON.stringify(res), res])
|
||||
).values(),
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче