diff --git a/e2e/package.json b/e2e/package.json index 2dc73484..28efba54 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -3,7 +3,7 @@ "license": "MIT", "sideEffects": false, "scripts": { - "test": "jest --silent", + "test": "jest", "coverage": "jest --coverage", "lint": "eslint --ignore-path .eslintignore --ext spec.js,spec.ts .", "format": "prettier --write \"src/e2e/**/*.{js,ts}\"" @@ -48,6 +48,6 @@ "contributors": [], "dependencies": { "advanced-billing-sdk": "../", - "dotenv": "^16.4.4" + "uid": "^2.0.2" } } diff --git a/e2e/src/billingPortalController.spec.ts b/e2e/src/billingPortalController.spec.ts index 36524215..5d427896 100644 --- a/e2e/src/billingPortalController.spec.ts +++ b/e2e/src/billingPortalController.spec.ts @@ -4,29 +4,30 @@ import { BillingPortalController, CustomersController, Customer, - CustomerResponse + CustomerResponse, } from 'advanced-billing-sdk'; describe('Billing Portal Controller', () => { let validCustomer: Customer; let enabledCustomerIdPForBillingPortal: number; + const perPage = 10000; const validClient = createClient(); const validCustomerBody = { customer: { - firstName: "Martha", - lastName: "Washington", - email: "martha@example.com", - ccEmails: "george@example.com", - } + firstName: 'Martha', + lastName: 'Washington', + email: 'martha@example.com', + ccEmails: 'george@example.com', + }, }; const validSecondCustomerBody = { customer: { - firstName: "George", - lastName: "Washington", - email: "george@example.com", - ccEmails: "martha@example.com", - } + firstName: 'George', + lastName: 'Washington', + email: 'george@example.com', + ccEmails: 'martha@example.com', + }, }; const invalidClient = createClient({ timeout: 0, @@ -41,28 +42,45 @@ describe('Billing Portal Controller', () => { const customersController = new CustomersController(validClient); const billingPortalController = new BillingPortalController(validClient); - const invalidBillingPortalController = new BillingPortalController(invalidClient); + const invalidBillingPortalController = new BillingPortalController( + invalidClient + ); beforeAll(async () => { - validCustomer = (await customersController.createCustomer(validCustomerBody)).result.customer; - const { result: { customer } } = await billingPortalController.enableBillingPortalForCustomer(validCustomer.id || 0); + validCustomer = ( + await customersController.createCustomer(validCustomerBody) + ).result.customer; + const { + result: { customer }, + } = await billingPortalController.enableBillingPortalForCustomer( + validCustomer.id || 0 + ); enabledCustomerIdPForBillingPortal = customer.id || 0; }); describe('Enable Billing Portal for Customer', () => { test('should get a billing portal enabled for the customer', async () => { - const { result: { customer }} = await customersController.createCustomer(validSecondCustomerBody); - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const { + result: { customer }, + } = await customersController.createCustomer(validSecondCustomerBody); + const customerIDs = ( + await customersController.listCustomers({ perPage }) + ).result.map((value: CustomerResponse) => value.customer.id); const existentCustomerID = customer.id || 0; expect(existentCustomerID).not.toBe(0); expect(customerIDs.includes(existentCustomerID)).toBeTruthy(); - const { statusCode } = await billingPortalController.enableBillingPortalForCustomer(existentCustomerID); + const { statusCode } = + await billingPortalController.enableBillingPortalForCustomer( + existentCustomerID + ); expect(statusCode).toBe(200); }); test('should thrown an error when enabled billing portal with invalid customer ID', async () => { - const promise = billingPortalController.enableBillingPortalForCustomer(invalidCustomerId); + const promise = + billingPortalController.enableBillingPortalForCustomer( + invalidCustomerId + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); @@ -70,7 +88,10 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when enabled billing portal with unauthorized client', async () => { - const promise = invalidBillingPortalController.enableBillingPortalForCustomer(Number(validCustomer.id)); + const promise = + invalidBillingPortalController.enableBillingPortalForCustomer( + Number(validCustomer.id) + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(401); @@ -78,10 +99,13 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when enabled billing portal with non-existent customer ID', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const customerIDs = ( + await customersController.listCustomers({}) + ).result.map((value: CustomerResponse) => value.customer.id); expect(customerIDs.includes(nonExistentCustomerId)).toBeFalsy(); - const promise = billingPortalController.enableBillingPortalForCustomer(nonExistentCustomerId); + const promise = billingPortalController.enableBillingPortalForCustomer( + nonExistentCustomerId + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); @@ -91,16 +115,23 @@ describe('Billing Portal Controller', () => { describe('Read Billing Portal Management Link', () => { test('should read a valid management link retrieval', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const customerIDs = ( + await customersController.listCustomers({ perPage }) + ).result.map((value: CustomerResponse) => value.customer.id); expect(enabledCustomerIdPForBillingPortal).not.toBe(0); - expect(customerIDs.includes(enabledCustomerIdPForBillingPortal)).toBeTruthy(); - const { statusCode } = await billingPortalController.readBillingPortalLink(enabledCustomerIdPForBillingPortal); + expect( + customerIDs.includes(enabledCustomerIdPForBillingPortal) + ).toBeTruthy(); + const { statusCode } = + await billingPortalController.readBillingPortalLink( + enabledCustomerIdPForBillingPortal + ); expect(statusCode).toBe(200); }); test('should thrown an error when read billing portal with invalid customer ID', async () => { - const promise = billingPortalController.readBillingPortalLink(invalidCustomerId); + const promise = + billingPortalController.readBillingPortalLink(invalidCustomerId); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); @@ -108,11 +139,9 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when read billing portal with unauthorized client', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); - expect(enabledCustomerIdPForBillingPortal).not.toBe(0); - expect(customerIDs.includes(enabledCustomerIdPForBillingPortal)).toBeTruthy(); - const promise = invalidBillingPortalController.readBillingPortalLink(enabledCustomerIdPForBillingPortal); + const promise = invalidBillingPortalController.readBillingPortalLink( + enabledCustomerIdPForBillingPortal + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(401); @@ -120,10 +149,13 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when read billing portal with non-existent customer ID', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const customerIDs = ( + await customersController.listCustomers({}) + ).result.map((value: CustomerResponse) => value.customer.id); expect(customerIDs.includes(nonExistentCustomerId)).toBeFalsy(); - const promise = billingPortalController.readBillingPortalLink(nonExistentCustomerId); + const promise = billingPortalController.readBillingPortalLink( + nonExistentCustomerId + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); @@ -133,16 +165,25 @@ describe('Billing Portal Controller', () => { describe('Resend Billing Portal Invitation', () => { test('should resending a billing portal invitation', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const customerIDs = ( + await customersController.listCustomers({ perPage }) + ).result.map((value: CustomerResponse) => value.customer.id); expect(enabledCustomerIdPForBillingPortal).not.toBe(0); - expect(customerIDs.includes(enabledCustomerIdPForBillingPortal)).toBeTruthy(); - const { statusCode } = await billingPortalController.resendBillingPortalInvitation(enabledCustomerIdPForBillingPortal); + expect( + customerIDs.includes(enabledCustomerIdPForBillingPortal) + ).toBeTruthy(); + const { statusCode } = + await billingPortalController.resendBillingPortalInvitation( + enabledCustomerIdPForBillingPortal + ); expect(statusCode).toBe(200); }); test('should thrown an error when resend billing portal invitation with invalid customer ID', async () => { - const promise = billingPortalController.resendBillingPortalInvitation(invalidCustomerId); + const promise = + billingPortalController.resendBillingPortalInvitation( + invalidCustomerId + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); @@ -150,11 +191,10 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when resend billing portal invitation with unauthorized client', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); - expect(enabledCustomerIdPForBillingPortal).not.toBe(0); - expect(customerIDs.includes(enabledCustomerIdPForBillingPortal)).toBeTruthy(); - const promise = invalidBillingPortalController.resendBillingPortalInvitation(enabledCustomerIdPForBillingPortal); + const promise = + invalidBillingPortalController.resendBillingPortalInvitation( + enabledCustomerIdPForBillingPortal + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(401); @@ -162,10 +202,13 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when resend billing portal invitation with non-existent customer ID', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const customerIDs = ( + await customersController.listCustomers({}) + ).result.map((value: CustomerResponse) => value.customer.id); expect(customerIDs.includes(nonExistentCustomerId)).toBeFalsy(); - const promise = billingPortalController.resendBillingPortalInvitation(nonExistentCustomerId); + const promise = billingPortalController.resendBillingPortalInvitation( + nonExistentCustomerId + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); @@ -175,16 +218,22 @@ describe('Billing Portal Controller', () => { describe('Revoke Billing Portal Invitation for Customer', () => { test('should revoke a billing portal invitation:', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const customerIDs = ( + await customersController.listCustomers({ perPage }) + ).result.map((value: CustomerResponse) => value.customer.id); expect(enabledCustomerIdPForBillingPortal).not.toBe(0); - expect(customerIDs.includes(enabledCustomerIdPForBillingPortal)).toBeTruthy(); - const response = await billingPortalController.revokeBillingPortalAccess(enabledCustomerIdPForBillingPortal); + expect( + customerIDs.includes(enabledCustomerIdPForBillingPortal) + ).toBeTruthy(); + const response = await billingPortalController.revokeBillingPortalAccess( + enabledCustomerIdPForBillingPortal + ); expect(response.statusCode).toBe(200); }); test('should thrown an error when revoke billing portal invitation with invalid customer ID', async () => { - const promise = billingPortalController.revokeBillingPortalAccess(invalidCustomerId); + const promise = + billingPortalController.revokeBillingPortalAccess(invalidCustomerId); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); @@ -192,11 +241,9 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when revoke billing portal invitation with unauthorized client', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); - expect(enabledCustomerIdPForBillingPortal).not.toBe(0); - expect(customerIDs.includes(enabledCustomerIdPForBillingPortal)).toBeTruthy(); - const promise = invalidBillingPortalController.revokeBillingPortalAccess(enabledCustomerIdPForBillingPortal); + const promise = invalidBillingPortalController.revokeBillingPortalAccess( + enabledCustomerIdPForBillingPortal + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(401); @@ -204,10 +251,13 @@ describe('Billing Portal Controller', () => { }); test('should thrown an error when revoke billing portal invitation with non-existent customer ID', async () => { - const customerIDs = (await customersController.listCustomers({})).result - .map((value: CustomerResponse) => value.customer.id); + const customerIDs = ( + await customersController.listCustomers({}) + ).result.map((value: CustomerResponse) => value.customer.id); expect(customerIDs.includes(nonExistentCustomerId)).toBeFalsy(); - const promise = billingPortalController.revokeBillingPortalAccess(nonExistentCustomerId); + const promise = billingPortalController.revokeBillingPortalAccess( + nonExistentCustomerId + ); expect(promise).rejects.toThrow(); await promise.catch((error) => { expect(error.statusCode).toBe(404); diff --git a/e2e/src/couponsController.spec.ts b/e2e/src/couponsController.spec.ts index b1f5ca51..815eebd5 100644 --- a/e2e/src/couponsController.spec.ts +++ b/e2e/src/couponsController.spec.ts @@ -10,6 +10,7 @@ import { import { createClient, CONFIG } from './config'; import { product } from './mocks/products'; import { createMockSubscription } from './mocks/subscriptions'; +import { uid } from 'uid'; const couponBody = { coupon: { @@ -61,7 +62,7 @@ describe('Coupons Controller', () => { ( await productFamiliesController.createProductFamily({ productFamily: { - name: 'coupons-product-family ab', + name: `coupons-product-family-${uid()}`, description: 'coupons product family a', }, }) @@ -432,16 +433,17 @@ describe('Coupons Controller', () => { describe('List Coupon Usages', () => { test('should list the usages coupons ', async () => { + const handle = `${uid()}-coupon-handler`; const productResponse = await productsController.createProduct( productFamily?.id || 0, { - product: { ...product, handle: 'coupon-handler' }, + product: { ...product, handle }, } ); const subscriptionBody = createMockSubscription({ - productHandle: 'coupon-handler', - customerReference: 'coupon-reference', + productHandle: handle, + customerReference: uid(), }); const subscriptionResponse = ( diff --git a/e2e/src/customFieldsController.spec.ts b/e2e/src/customFieldsController.spec.ts index 773b4938..8dc23348 100644 --- a/e2e/src/customFieldsController.spec.ts +++ b/e2e/src/customFieldsController.spec.ts @@ -342,19 +342,20 @@ describe('Custom Fields Controller', () => { describe('filter Metafields', () => { test('should list meta fields by name filter with successful match', async () => { + await createTextSubscriptionField('text-field-for-filter'); const data = { resourceType: ResourceType.Subscriptions, - name: textSubscriptionField.name, + name: 'text-field-for-filter', }; - const { - result: { currentPage, perPage, metafields, totalCount }, - statusCode, - } = await customFieldsController.listMetafields(data); + const { result, statusCode } = + await customFieldsController.listMetafields(data); + const { currentPage, perPage, metafields, totalCount } = result; expect(statusCode).toBe(200); expect(currentPage).toBe(defaultCurrentPage); expect(perPage).toBe(defaultPerPage); - expect(totalCount).toBe(1); expect(metafields).toHaveLength(1); + expect(metafields).toHaveLength(1); + expect(totalCount).toBe(1); const { name, inputType } = (metafields || [])[0]; expect(name).toEqual(data.name); expect(inputType).toEqual(textSubscriptionField.inputType); @@ -505,7 +506,7 @@ describe('Custom Fields Controller', () => { }, }; const { - result: [{ id, name, scope }], + result: [{ name, scope }], statusCode, } = await customFieldsController.updateMetafield( ResourceType.Subscriptions, @@ -513,7 +514,6 @@ describe('Custom Fields Controller', () => { ); expect(statusCode).toBe(200); expect(name).toEqual(nameToUpdate); - expect(id).toBe(customTextField.id); expect(scope?.csv).toEqual(IncludeOption.Include); expect(scope?.invoices).toEqual(IncludeOption.Include); expect(scope?.statements).toEqual(IncludeOption.Include); @@ -733,7 +733,9 @@ describe('Custom Fields Controller', () => { test('should delete created customer text field attached to metadata and remove customer field created', async () => { const validCustomer = await createCustomer(); - const customTextField = await createTextCustomersField(); + const customTextField = await createTextCustomersField( + 'delete-customer-text-field' + ); const customerID = validCustomer.id || 0; const metaDatapayload = { metadata: [ @@ -770,10 +772,6 @@ describe('Custom Fields Controller', () => { resourceId: customerID, }); expect(metadataListResponse.statusCode).toBe(200); - expect( - metadataListResponse.result.metadata?.length - ).toBeGreaterThanOrEqual(1); - expect(metadataListResponse.result.totalCount).toBeGreaterThanOrEqual(1); const metadataFound = metadataListResponse.result.metadata?.find( (data) => data.id == metadataCreatedID ); diff --git a/e2e/src/customMetadataController/customerMetadata.spec.ts b/e2e/src/customMetadataController/customerMetadata.spec.ts index ad2b7fe7..e8db7be0 100644 --- a/e2e/src/customMetadataController/customerMetadata.spec.ts +++ b/e2e/src/customMetadataController/customerMetadata.spec.ts @@ -11,15 +11,14 @@ import { createCustomerTextMetadata, createCustomerDropdownMetadata, getMetadataIdList, - removeCustomerMetadataList, } from './utils'; import { createTextCustomersField, createDropdownCustomersField, - removeCustomerCustomList, } from '../utils/customFieldsController'; import { createCustomer } from '../utils/customers'; import { get2KbObject } from '../utils/stringKB'; +import { uid } from 'uid'; describe('Customer metadata', () => { let customerID: number; @@ -36,11 +35,6 @@ describe('Customer metadata', () => { customerID = id; }); - afterAll(async () => { - await removeCustomerMetadataList(); - await removeCustomerCustomList(); - }); - describe('Create customer metadata', () => { let textCustomerField: Metafield; @@ -51,6 +45,8 @@ describe('Customer metadata', () => { }); test('should create a customer metadata with existing metafield for attach to metadata.', async () => { + const textFieldName = `${uid()}-create`; + const textCustomerField = await createTextCustomersField(textFieldName); const metadata = { name: textCustomerField.name, value: 'Blue', @@ -74,6 +70,8 @@ describe('Customer metadata', () => { }); test('should create a customer multiple metadata with existing metafields for attached to metadata.', async () => { + const textFieldName = `${uid()}-create`; + const textCustomerField = await createTextCustomersField(textFieldName); const dropdownCustomerField = await createDropdownCustomersField( 'dropdownCustomerFieldToCreate' ); @@ -187,8 +185,6 @@ describe('Customer metadata', () => { const DEFAULT_PER_PAGE = 20; beforeAll(async () => { - await removeCustomerMetadataList(); - await removeCustomerCustomList(); textFieldCustomerToList = await createTextCustomersField('listTextCustomer'); dropdownFieldCustomerToList = await createDropdownCustomersField( @@ -297,8 +293,6 @@ describe('Customer metadata', () => { let textMetaDataCustomerToUpdate: Metadata; beforeAll(async () => { - await removeCustomerMetadataList(); - await removeCustomerCustomList(); textFieldCustomerToUpdate = await createTextCustomersField( 'textCustomerToUpdate' ); @@ -592,8 +586,6 @@ describe('Customer metadata', () => { const DEFAULT_PER_PAGE = 20; beforeAll(async () => { - await removeCustomerMetadataList(); - await removeCustomerCustomList(); textFieldCustomerToResourceList = await createTextCustomersField( 'listTextCustomerResource' ); @@ -687,7 +679,7 @@ describe('Customer metadata', () => { expect( metadataNames?.includes(dropdownMetaCustomerDataToResourceList.name) ).toBeTruthy(); - expect(totalCountBeforeDelete).toBe(DEFAULT_LENGTH + 1); + expect(totalCountBeforeDelete).toBeGreaterThanOrEqual(DEFAULT_LENGTH + 1); const { statusCode } = await customFieldsController.deleteMetadata( customerResource, diff --git a/e2e/src/customMetadataController/subscriptionMetadata.spec.ts b/e2e/src/customMetadataController/subscriptionMetadata.spec.ts index 2f991597..121acc78 100644 --- a/e2e/src/customMetadataController/subscriptionMetadata.spec.ts +++ b/e2e/src/customMetadataController/subscriptionMetadata.spec.ts @@ -10,12 +10,10 @@ import { createSubscriptionTextMetadata, createSubscriptionDropdownMetadata, getMetadataIdList, - removeSubscriptionsMetadataList, } from './utils'; import { createTextSubscriptionField, createDropdownSubscriptionField, - removeSubscriptionsCustomList, } from '../utils/customFieldsController'; import { get2KbObject } from '../utils/stringKB'; import { createSubscription } from '../utils/subscription'; @@ -31,20 +29,10 @@ describe('Subscription metadata', () => { ); beforeAll(async () => { - const randomCode = String(Math.floor(Math.random() * 999999999)); - const { subscriptionResponse } = await createSubscription({ - productFamilyName: `metadata-${randomCode}-invoice`, - productHandle: `metadata-${randomCode}-invoice-handler`, - customerReference: `metadata-${randomCode}-invoice-reference`, - }); + const { subscriptionResponse } = await createSubscription({}); subscriptionID = subscriptionResponse?.subscription?.id ?? 0; }); - afterAll(async () => { - await removeSubscriptionsMetadataList(); - await removeSubscriptionsCustomList(); - }); - describe('Create subscription metadata', () => { let textSubscriptionField: Metafield; @@ -188,8 +176,6 @@ describe('Subscription metadata', () => { const DEFAULT_PER_PAGE = 20; beforeAll(async () => { - await removeSubscriptionsMetadataList(); - await removeSubscriptionsCustomList(); textFieldToList = await createTextSubscriptionField( 'listTextSubscription' ); @@ -296,8 +282,6 @@ describe('Subscription metadata', () => { let textMetaDataSubscriptionToUpdate: Metadata; beforeAll(async () => { - await removeSubscriptionsMetadataList(); - await removeSubscriptionsCustomList(); textFieldSubscriptionToUpdate = await createTextSubscriptionField( 'textFieldSubscriptionNameToUpdate' ); @@ -597,8 +581,6 @@ describe('Subscription metadata', () => { const DEFAULT_PER_PAGE = 20; beforeAll(async () => { - await removeSubscriptionsMetadataList(); - await removeSubscriptionsCustomList(); textFieldSubscriptionResourceList = await createTextSubscriptionField( 'listTextSubscriptionResource' ); @@ -693,7 +675,7 @@ describe('Subscription metadata', () => { expect( metadataNames?.includes(dropdownMetaDataSubscriptionResourceList.name) ).toBeTruthy(); - expect(totalCountBeforeDelete).toBe(DEFAULT_LENGTH + 1); + expect(totalCountBeforeDelete).toBeGreaterThanOrEqual(DEFAULT_LENGTH + 1); const { statusCode } = await customFieldsController.deleteMetadata( subscriptionResource, diff --git a/e2e/src/customersController.spec.ts b/e2e/src/customersController.spec.ts index 5b471117..50c48783 100644 --- a/e2e/src/customersController.spec.ts +++ b/e2e/src/customersController.spec.ts @@ -1,7 +1,9 @@ +import { uid } from 'uid'; import { createClient } from './config'; import { CustomersController, CustomerResponse } from 'advanced-billing-sdk'; describe('CustomersController', () => { + const customerReferenceId = `${uid()}-for-search`; describe('Create customer', () => { test('should create a customer given the correct payload body', async () => { const client = createClient(); @@ -44,6 +46,7 @@ describe('CustomersController', () => { }); test('should throw error when the user try to create a customer with the same reference value', async () => { + const sameReferenceId = uid(); const client = createClient(); const customersController = new CustomersController(client); const body = { @@ -53,7 +56,7 @@ describe('CustomersController', () => { email: 'pedro@example.com', ccEmails: 'pedro@example.com', organization: 'ABC, Inc.', - reference: '1033', + reference: sameReferenceId, address: '123 Main Street', address2: 'Unit 10', city: 'Anytown', @@ -72,7 +75,7 @@ describe('CustomersController', () => { email: 'Juan@example.com', ccEmails: 'Juan@example.com', organization: 'ABC, Inc.', - reference: '1033', + reference: sameReferenceId, address: '123 Main Street', address2: 'Unit 10', city: 'Anytown', @@ -109,42 +112,42 @@ describe('CustomersController', () => { lastName: 'Lopez', email: 'fernando@example.com', organization: 'ABC, Inc.', - reference: '10001', + reference: customerReferenceId, }, { firstName: 'Fernando', lastName: 'Pedregal', email: 'nando@example.com', organization: 'Holand, Inc.', - reference: '10002', + reference: uid(), }, { firstName: 'Solivan', lastName: 'Medrano', email: 'soli@example.com', organization: 'ABC, Inc.', - reference: '10003', + reference: uid(), }, { firstName: 'Edward', lastName: 'Kalua', email: 'kalua@example.com', organization: 'CPD, inc', - reference: '10004', + reference: uid(), }, { firstName: 'Miguel', lastName: 'Santos', email: 'santos@example.com', organization: 'CPD, inc', - reference: '10005', + reference: uid(), }, { firstName: 'Henrique', lastName: 'Figeroa', email: 'figeroa@example.com', organization: 'CPD, inc', - reference: '10006', + reference: uid(), }, ]; @@ -175,11 +178,9 @@ describe('CustomersController', () => { const responseEmails = response.result .map((value: CustomerResponse) => value.customer.email) .sort(); - expect(response.result.length).toBe(2); - expect(responseEmails).toEqual([ - 'fernando@example.com', - 'nando@example.com', - ]); + expect(response.result.length).toBeGreaterThanOrEqual(2); + const [firstEmail] = responseEmails; + expect(firstEmail?.includes('nando')).toBeTruthy(); }); test('should get empty customers list when the user query criteria was not found in data', async () => { @@ -195,7 +196,7 @@ describe('CustomersController', () => { const client = createClient(); const customersController = new CustomersController(client); const response = await customersController.listCustomers({ q: 'ABC' }); - expect(response.result.length >= 2).toBeTruthy(); + expect(response.result.length).toBeGreaterThanOrEqual(2); const responseEmails = response.result .map((value: CustomerResponse) => value.customer.email) .sort(); @@ -206,7 +207,9 @@ describe('CustomersController', () => { test('should get customers list based on reference application criteria when the user search by reference', async () => { const client = createClient(); const customersController = new CustomersController(client); - const response = await customersController.listCustomers({ q: '10001' }); + const response = await customersController.listCustomers({ + q: customerReferenceId, + }); expect(response.result.length).toBe(1); const responseEmails = response.result.map( (value: CustomerResponse) => value.customer.email @@ -240,7 +243,7 @@ describe('CustomersController', () => { lastName: 'Pedregal', email: 'nando@example.com', organization: 'Holand, Inc.', - reference: '102', + reference: uid(), }, }); const id = customerCreated.result.customer.id as number; @@ -270,7 +273,7 @@ describe('CustomersController', () => { lastName: 'Pedregal', email: 'nando@example.com', organization: 'Holand, Inc.', - reference: '102A', + reference: uid(), }, }); const id = customerCreated.result.customer.id as number; @@ -310,7 +313,7 @@ describe('CustomersController', () => { lastName: 'Pedregal', email: 'nando@example.com', organization: 'Holand, Inc.', - reference: '102B', + reference: uid(), }, }); const id = customerCreated.result.customer.id as number; @@ -333,6 +336,7 @@ describe('CustomersController', () => { describe('Read Customer By Reference', () => { test('should read a customer by reference when the user sends a correct id from already created customer', async () => { const client = createClient(); + const referenceId = uid(); const customersController = new CustomersController(client); const customerCreated = await customersController.createCustomer({ customer: { @@ -340,11 +344,11 @@ describe('CustomersController', () => { lastName: 'Pedregal', email: 'nando@example.com', organization: 'Holand, Inc.', - reference: '102C', + reference: referenceId, }, }); const response = - await customersController.readCustomerByReference('102C'); + await customersController.readCustomerByReference(referenceId); expect(response.result).toEqual(customerCreated.result); }); @@ -370,7 +374,7 @@ describe('CustomersController', () => { lastName: 'Pedregal', email: 'nando@example.com', organization: 'Holand, Inc.', - reference: '103C', + reference: uid(), }, }); const id = customerCreated.result.customer.id as number; diff --git a/e2e/src/eventsController.spec.ts b/e2e/src/eventsController.spec.ts index 9f2a874f..7d455520 100644 --- a/e2e/src/eventsController.spec.ts +++ b/e2e/src/eventsController.spec.ts @@ -22,11 +22,7 @@ describe('Events Controller', () => { describe('List Events for site', () => { test('should list events for site', async () => { - await createSubscription({ - customerReference: 'listevents-product-refrence', - productFamilyName: 'listevents-product-familyname', - productHandle: 'listevents-product-handle', - }); + await createSubscription({}); const listResponse = await eventsController.listEvents({}); expect(listResponse.statusCode).toBe(200); @@ -44,11 +40,7 @@ describe('Events Controller', () => { describe('List Events for Subscription', () => { test('should list events for subscription when the user sends a valid subscription id', async () => { - const { subscriptionResponse } = await createSubscription({ - customerReference: 'listeventsbysubscription-product-refrence', - productFamilyName: 'listeventsbysubscription-product-familyname', - productHandle: 'listeventsbysubscription-product-handle', - }); + const { subscriptionResponse } = await createSubscription({}); const subscriptId = subscriptionResponse?.subscription?.id; const listResponse = await eventsController.listSubscriptionEvents({ subscriptionId: subscriptId || 0, @@ -80,11 +72,7 @@ describe('Events Controller', () => { describe('Get total event count ', () => { test('should contain the total count of events', async () => { - await createSubscription({ - customerReference: 'counteventsbysubscription-product-refrence', - productFamilyName: 'counteventsbysubscription-product-familyname', - productHandle: 'counteventsbysubscription-product-handle', - }); + await createSubscription({}); const listResponse = await eventsController.readEventsCount({}); const count = listResponse.result?.count || 0; expect(listResponse.statusCode).toBe(200); diff --git a/e2e/src/invoicesController.spec.ts b/e2e/src/invoicesController.spec.ts index ea2a43c5..e7cf0598 100644 --- a/e2e/src/invoicesController.spec.ts +++ b/e2e/src/invoicesController.spec.ts @@ -22,11 +22,7 @@ describe('Invoices Controller', () => { describe('Valid Advance Invoice Issuance', () => { test('should create a valid advance invoice issuance', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-01-invoice', - productHandle: 'scenario-01-invoice-handler', - customerReference: 'scenario-01-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; @@ -49,11 +45,7 @@ describe('Invoices Controller', () => { }); test('should throw a 422 error when the user sends invalid or missing parameters in the request body', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-02-invoice', - productHandle: 'scenario-02-invoice-handler', - customerReference: 'scenario-02-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; @@ -67,11 +59,7 @@ describe('Invoices Controller', () => { }); test('should throw a 401 error when the user sends incorrect credentials', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-03-invoice', - productHandle: 'scenario-03-invoice-handler', - customerReference: 'scenario-03-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; @@ -85,11 +73,7 @@ describe('Invoices Controller', () => { describe('Read Advance Invoice', () => { test('should read a valid advance invoice retrieval', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-01-read-invoice', - productHandle: 'scenario-01-read-invoice-handler', - customerReference: 'scenario-01-read-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; @@ -125,11 +109,7 @@ describe('Invoices Controller', () => { }); test('should throw a 401 error when the user sends incorrect credentials', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-03-read-invoice', - productHandle: 'scenario-03-read-invoice-handler', - customerReference: 'scenario-03-read-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; @@ -159,11 +139,7 @@ describe('Invoices Controller', () => { describe('Void Advance Invoice', () => { test('should void a valid advance invoice issuance', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-01-void-invoice', - productHandle: 'scenario-01-void-invoice-handler', - customerReference: 'scenario-01-void-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; @@ -195,11 +171,7 @@ describe('Invoices Controller', () => { }); test('should throw a 422 error when the user sends invalid or missing parameters', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-02-void-invoice', - productHandle: 'scenario-02-void-invoice-handler', - customerReference: 'scenario-02-void-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; @@ -226,11 +198,7 @@ describe('Invoices Controller', () => { }); test('should throw a 401 error when the user sends incorrect credentials', async () => { - const subsResponse = await createSubscription({ - productFamilyName: 'scenario-03-void-invoice', - productHandle: 'scenario-03-void-invoice-handler', - customerReference: 'scenario-03-void-invoice-reference', - }); + const subsResponse = await createSubscription({}); const subscriptId = subsResponse.subscriptionResponse?.subscription?.id; diff --git a/e2e/src/offersController.spec.ts b/e2e/src/offersController.spec.ts index acac7b66..c0fcd1f9 100644 --- a/e2e/src/offersController.spec.ts +++ b/e2e/src/offersController.spec.ts @@ -9,24 +9,27 @@ import { IntervalUnit, } from 'advanced-billing-sdk'; import { CONFIG, createClient } from './config'; +import { uid } from 'uid'; describe('Offers Controller', () => { let offersController: OffersController; let productFamilyResponse: ProductFamilyResponse; let productResponse: ProductResponse; let invalidOffersController: OffersController; + const productId = `${uid()}-offers`; + const productFamilyName = `${uid()}-offers-family`; const productFamilyBody = { productFamily: { - name: 'Offers Acme Projects', + name: productFamilyName, description: 'Amazing project management tool', }, }; const productBody = { product: { - name: 'offers-premium-00020', - handle: 'offers-premium-0020', + name: productId, + handle: productId, description: 'premium-desc', priceInCents: BigInt(1000), interval: 1, @@ -60,10 +63,9 @@ describe('Offers Controller', () => { }); describe('List offers', () => { - test('should list an empty list of offers', async () => { + test('should list all offers on the list', async () => { const offersResponse = await offersController.listOffers({}); expect(offersResponse.statusCode).toBe(200); - expect(offersResponse.result.offers).toEqual([]); }); test('should throw 401 error when user use invalid credentials', async () => { @@ -79,21 +81,21 @@ describe('Offers Controller', () => { const offers = [ { name: 'Solo A', - handle: 'han_shot_first_a', + handle: uid(), description: 'A Star Wars Story A', productId: productResponse.product.id || 0, components: [], }, { name: 'Solo B', - handle: 'han_shot_first_b', + handle: uid(), description: 'A Star Wars Story B', productId: productResponse.product.id || 0, components: [], }, { name: 'Solo C', - handle: 'han_shot_first_c', + handle: uid(), description: 'A Star Wars Story C', productId: productResponse.product.id || 0, components: [], @@ -109,17 +111,19 @@ describe('Offers Controller', () => { ?.map((offer: OfferResponse['offer']) => offer?.name) .sort(); expect(offersResponse.statusCode).toBe(200); - expect(offersResponse.result.offers?.length).toBe(3); - expect(offersNames).toEqual(['Solo A', 'Solo B', 'Solo C']); + expect(offersNames?.includes('Solo A')).toBeTruthy(); + expect(offersNames?.includes('Solo B')).toBeTruthy(); + expect(offersNames?.includes('Solo C')).toBeTruthy(); }); }); describe('Create Offer', () => { test('should create an offer when user sends correct product id', async () => { + const offerHandle = uid(); const offerBody = { offer: { name: 'Solo', - handle: 'han_shot_first', + handle: offerHandle, description: 'A Star Wars Story', productId: productResponse.product.id || 0, components: [], @@ -134,13 +138,13 @@ describe('Offers Controller', () => { productId: productResponse.product.id || 0, productRevisableNumber: 0, name: 'Solo', - handle: 'han_shot_first', + handle: offerHandle, description: 'A Star Wars Story', archivedAt: null, offerItems: [], offerDiscounts: [], - productFamilyName: 'Offers Acme Projects', - productName: 'offers-premium-00020', + productFamilyName: productFamilyName, + productName: productId, productPricePointName: 'Original', productPriceInCents: BigInt(1000), offerSignupPages: [], @@ -215,7 +219,7 @@ describe('Offers Controller', () => { beforeAll(async () => { const offer = { name: 'golden A', - handle: 'han_shot_first_golden', + handle: uid(), description: 'A Star Wars Story A', productId: productResponse.product.id || 0, components: [], @@ -255,21 +259,21 @@ describe('Offers Controller', () => { const offers = [ { name: 'Premium A', - handle: 'han_shot_first_premium_a', + handle: uid(), description: 'A Star Wars Story A', productId: productResponse.product.id || 0, components: [], }, { name: 'Premium B', - handle: 'han_shot_first_premium_b', + handle: uid(), description: 'A Star Wars Story B', productId: productResponse.product.id || 0, components: [], }, { name: 'Premium C', - handle: 'han_shot_first_premium_c', + handle: uid(), description: 'A Star Wars Story C', productId: productResponse.product.id || 0, components: [], diff --git a/e2e/src/productsController.spec.ts b/e2e/src/productsController.spec.ts index a00d43d2..06009911 100644 --- a/e2e/src/productsController.spec.ts +++ b/e2e/src/productsController.spec.ts @@ -1,3 +1,4 @@ +import { uid } from 'uid'; import { CONFIG, createClient } from './config'; import { Environment, @@ -7,12 +8,18 @@ import { ProductsController, IntervalUnit, } from 'advanced-billing-sdk'; +const productId01 = `${uid()}-products-controller`; +const productId02 = `${uid()}-products-controller`; +const productId03 = `${uid()}-products-controller`; +const productId04 = `${uid()}-products-controller`; +const productFamilyName = `${uid()}-product-family`; +let newProductId: string; const payloads = [ { product: { - name: 'premium-0001', - handle: 'premium-0001', + name: productId01, + handle: productId01, description: 'premium-desc', priceInCents: BigInt(1000), interval: 1, @@ -21,8 +28,8 @@ const payloads = [ }, { product: { - name: 'premium-0002', - handle: 'premium-0002', + name: productId02, + handle: productId02, description: 'premium-desc', priceInCents: BigInt(1000), interval: 1, @@ -31,8 +38,8 @@ const payloads = [ }, { product: { - name: 'premium-0003', - handle: 'premium-0003', + name: productId03, + handle: productId03, description: 'premium-desc', priceInCents: BigInt(1000), interval: 1, @@ -41,8 +48,8 @@ const payloads = [ }, { product: { - name: 'premium-0004', - handle: 'premium-0004', + name: productId04, + handle: productId04, description: 'premium-desc', priceInCents: BigInt(1000), interval: 1, @@ -70,7 +77,7 @@ describe('Products Controller', () => { const productsController = new ProductsController(client); const payload = { productFamily: { - name: 'product name 005', + name: productFamilyName, description: 'product 0005 description', }, }; @@ -86,14 +93,19 @@ describe('Products Controller', () => { const responseCollection = await Promise.all(promises); productsCreated = responseCollection.map((response) => response.result); }); + + beforeEach(() => { + newProductId = `${uid()}-product-create`; + }); describe('Create Product', () => { test('should create a product when the user send the correct values', async () => { const client = createClient(); const productsController = new ProductsController(client); + const newProductPayload = { product: { - name: 'Platinum plan', - handle: 'platinum-2', + name: newProductId, + handle: newProductId, description: 'This is our gold plan.', accountingCode: '123', requireCredit_card: true, @@ -109,8 +121,8 @@ describe('Products Controller', () => { newProductPayload ); expect(productResponse.statusCode).toBe(201); - expect(productResponse.result.product.name).toBe('Platinum plan'); - expect(productResponse.result.product.handle).toBe('platinum-2'); + expect(productResponse.result.product.name).toBe(newProductId); + expect(productResponse.result.product.handle).toBe(newProductId); }); test('should throw a error when the user send invalid payload values', async () => { @@ -147,8 +159,8 @@ describe('Products Controller', () => { const newProductPayload = { product: { - name: 'Platinum plan-priv', - handle: 'platinum-2-priv', + name: newProductId, + handle: newProductId, description: 'This is our gold plan.', accountingCode: '123', requireCredit_card: true, @@ -185,11 +197,10 @@ describe('Products Controller', () => { .sort(); expect(response.result.length >= 5).toBeTruthy(); const hasAllProducts = [ - 'Platinum plan', - 'premium-0001', - 'premium-0002', - 'premium-0003', - 'premium-0004', + productId01, + productId02, + productId03, + productId04, ].every((name) => productNames.includes(name)); expect(hasAllProducts).toBeTruthy(); }); diff --git a/e2e/src/productsFamiliesController.spec.ts b/e2e/src/productsFamiliesController.spec.ts index 695d9d38..6a37f7eb 100644 --- a/e2e/src/productsFamiliesController.spec.ts +++ b/e2e/src/productsFamiliesController.spec.ts @@ -1,3 +1,4 @@ +import { uid } from 'uid'; import { createClient } from './config'; import { ProductFamilyResponse, @@ -5,12 +6,16 @@ import { } from 'advanced-billing-sdk'; describe('ProductsFamilies Controller', () => { + const productFamilyName = `${uid()}-product-family-controllers`; + const productFamilyName02 = `${uid()}-product-family-controllers-02`; + const productFamilyName03 = `${uid()}-product-family-controllers-03`; + test('should create a product family with the correct params', async () => { const client = createClient(); const productFamiliesController = new ProductFamiliesController(client); const payload = { productFamily: { - name: 'Acme Projects', + name: productFamilyName, description: 'Amazing project management tool', }, }; @@ -48,7 +53,7 @@ describe('ProductsFamilies Controller', () => { const productFamiliesController = new ProductFamiliesController(client); const payload = { productFamily: { - name: 'productFamily', + name: productFamilyName02, description: 'product description', }, }; @@ -76,20 +81,26 @@ describe('ProductsFamilies Controller', () => { const productNames = readResponse.result.map( (item: ProductFamilyResponse) => item.productFamily?.name ); - expect(productNames.includes('Acme Projects')).toBeTruthy(); - expect(productNames.includes('productFamily')).toBeTruthy(); + expect(productNames.includes(productFamilyName)).toBeTruthy(); + expect(productNames.includes(productFamilyName02)).toBeTruthy(); }); test('should list the products from already created product family without products', async () => { const client = createClient(); const productFamiliesController = new ProductFamiliesController(client); - const productsFamiliesResponse = - await productFamiliesController.listProductFamilies({}); - const [productFamilyResponse] = productsFamiliesResponse.result; - const productFamilyId = productFamilyResponse.productFamily?.id || 0; + const payload = { + productFamily: { + name: productFamilyName03, + description: 'Amazing project management tool', + }, + }; + const response = + await productFamiliesController.createProductFamily(payload); + const { productFamily } = response.result; + const readResponse = await productFamiliesController.listProductsForProductFamily({ - productFamilyId, + productFamilyId: productFamily?.id || 0, }); expect(readResponse.statusCode).toBe(200); expect(readResponse.result.length).toBe(0); diff --git a/e2e/src/subscriptionNotesController.spec.ts b/e2e/src/subscriptionNotesController.spec.ts index 8765e401..1f76f3c9 100644 --- a/e2e/src/subscriptionNotesController.spec.ts +++ b/e2e/src/subscriptionNotesController.spec.ts @@ -25,11 +25,7 @@ describe('Subscription Notes Controller', () => { invalidSubscriptionNotesController = new SubscriptionNotesController( invalidClient ); - subscriptionContext = await createSubscription({ - productFamilyName: 'Notes family', - productHandle: 'subs-notes-001', - customerReference: 'notes-001', - }); + subscriptionContext = await createSubscription({}); }); describe('Create subscription note', () => { test('should create a note on selected subscription', async () => { diff --git a/e2e/src/subscriptionsController.spec.ts b/e2e/src/subscriptionsController.spec.ts index 33f6452f..2a58b922 100644 --- a/e2e/src/subscriptionsController.spec.ts +++ b/e2e/src/subscriptionsController.spec.ts @@ -12,24 +12,29 @@ import { BankAccountHolderType, } from 'advanced-billing-sdk'; import { createClient } from './config'; +import { uid } from 'uid'; describe('Subscriptions Controller', () => { let subscriptionsController: SubscriptionsController; let productFamilyResponse: ProductFamilyResponse; let productResponse01: ProductResponse; let productResponse02: ProductResponse; + const productHandleId = `${uid()}-product-handle-basic`; + const productHandleEngageId = `${uid()}-product-handle-engage`; + const productFamilyName = `${uid()}-subscriptions-engage`; + let customerReference: string; const productFamilyBody = { productFamily: { - name: 'subscriptions-engage', + name: productFamilyName, description: 'Amazing subscriptions-engage', }, }; const productBody = { product: { - name: 'subscriptions-engage', - handle: 'basic-subscription', + name: productHandleId, + handle: productHandleId, description: 'Description print', priceInCents: BigInt(1000), interval: 1, @@ -39,8 +44,8 @@ describe('Subscriptions Controller', () => { const productBody02 = { product: { - name: 'subscriptions-engage02', - handle: 'basic-subscription-02', + name: productHandleEngageId, + handle: productHandleEngageId, description: 'Description print', priceInCents: BigInt(100), interval: 1, @@ -63,6 +68,10 @@ describe('Subscriptions Controller', () => { billingAddress: '123 Mass Ave.', }; + beforeEach(() => { + customerReference = uid(); + }); + beforeAll(async () => { const client = createClient(); subscriptionsController = new SubscriptionsController(client); @@ -90,14 +99,14 @@ describe('Subscriptions Controller', () => { test('should create a subscription with valid credit card attributes', async () => { const body = { subscription: { - productHandle: 'basic-subscription', + productHandle: productHandleId, customerAttributes: { firstName: 'Joe', lastName: 'Blow', email: 'joe@example.com', zip: '02120', state: 'MA', - reference: 'XYZ1', + reference: customerReference, phone: '(617) 111 - 0000', organization: 'Acme', country: 'US', @@ -120,14 +129,14 @@ describe('Subscriptions Controller', () => { test('should create a subscription with valid bank account attributes', async () => { const body = { subscription: { - productHandle: 'basic-subscription', + productHandle: productHandleId, customerAttributes: { firstName: 'Joe', lastName: 'Blow', email: 'joe@example.com', zip: '02120', state: 'MA', - reference: 'XYZ', + reference: customerReference, phone: '(617) 111 - 0000', organization: 'Acme', country: 'US', @@ -158,14 +167,14 @@ describe('Subscriptions Controller', () => { test('should throw an 422 error when a subscription does not have a payment profile', async () => { const body = { subscription: { - productHandle: 'basic-subscription', + productHandle: productHandleId, customerAttributes: { firstName: 'Joe', lastName: 'Blow', email: 'joe@example.com', zip: '02120', state: 'MA', - reference: 'XYZ2', + reference: customerReference, phone: '(617) 111 - 0000', organization: 'Acme', country: 'US', @@ -201,14 +210,14 @@ describe('Subscriptions Controller', () => { const subscriptionsByProduct = [ { subscription: { - productHandle: 'basic-subscription-02', + productHandle: productHandleEngageId, customerAttributes: { firstName: 'Joe', lastName: 'Blow', email: 'joe@example.com', zip: '02120', state: 'MA', - reference: 'XYZ4', + reference: customerReference, phone: '(617) 111 - 0000', organization: 'Acme', country: 'US', @@ -221,14 +230,14 @@ describe('Subscriptions Controller', () => { }, { subscription: { - productHandle: 'basic-subscription-02', + productHandle: productHandleEngageId, customerAttributes: { firstName: 'Joe', lastName: 'Blow', email: 'joe@example.com', zip: '02120', state: 'MA', - reference: 'XYZ5', + reference: `${customerReference}second`, phone: '(617) 111 - 0000', organization: 'Acme', country: 'US', diff --git a/e2e/src/utils/index.ts b/e2e/src/utils/index.ts index 36274df1..b9a97b65 100644 --- a/e2e/src/utils/index.ts +++ b/e2e/src/utils/index.ts @@ -1,20 +1,9 @@ import { createClient } from '../config'; -import { SitesController } from '../../../src/controllers/sitesController'; +import { SitesController } from 'advanced-billing-sdk'; -const DELAY_AFTER_CLEAN = 1000; -// Based on https://developers.chargify.com/docs/api-docs/c912e634019c9-clear-site-data -// doc recommendation added small delay a site verification or read retry command export async function cleanSite() { - return new Promise((resolve, reject) => { - const client = createClient(); - const sitesController = new SitesController(client); - sitesController - .clearSite() - .then((response) => { - setTimeout(() => { - resolve(response); - }, DELAY_AFTER_CLEAN); - }) - .catch((error) => reject(error)); - }); + const client = createClient(); + const sitesController = new SitesController(client); + const response = await sitesController.clearSite(); + return response; } diff --git a/e2e/src/utils/subscription.ts b/e2e/src/utils/subscription.ts index 5011c86e..f7c61780 100644 --- a/e2e/src/utils/subscription.ts +++ b/e2e/src/utils/subscription.ts @@ -1,4 +1,5 @@ import { createClient } from '../config'; +import { uid } from 'uid'; import { ProductFamiliesController, @@ -12,9 +13,9 @@ import { product } from '../mocks/products'; import { createMockSubscription } from '../mocks/subscriptions'; export interface SubscriptionConfig { - productFamilyName: string; - productHandle: string; - customerReference: string; + productFamilyName?: string; + productHandle?: string; + customerReference?: string; } export interface SubscriptionContext { @@ -24,9 +25,9 @@ export interface SubscriptionContext { } export async function createSubscription({ - productFamilyName, - productHandle, - customerReference, + productFamilyName = uid(), + productHandle = uid(), + customerReference = uid(), }: SubscriptionConfig): Promise { const client = createClient(); const subscriptionsController = new SubscriptionsController(client); diff --git a/e2e/src/utils/subscriptionsProductsController.ts b/e2e/src/utils/subscriptionsProductsController.ts index 16df7526..4403c81b 100644 --- a/e2e/src/utils/subscriptionsProductsController.ts +++ b/e2e/src/utils/subscriptionsProductsController.ts @@ -9,6 +9,7 @@ import { import { createClient } from '../config'; import { product } from '../mocks/products'; import { createMockSubscription } from '../mocks/subscriptions'; +import { uid } from 'uid'; export interface MigrationContext { productFamilyResponse: ProductFamilyResponse | null; @@ -19,6 +20,9 @@ export interface MigrationContext { export async function createContextForMigration(): Promise { const client = createClient(); + const productHandleId = `${uid()}-subs01`; + const productHandleEngageId = `${uid()}-subs02`; + const productFamilyName = `${uid()} subscriptions migrations`; const subscriptionsController = new SubscriptionsController(client); const productFamiliesController = new ProductFamiliesController(client); const productsController = new ProductsController(client); @@ -26,7 +30,7 @@ export async function createContextForMigration(): Promise { const productFamilyResponse = ( await productFamiliesController.createProductFamily({ productFamily: { - name: 'subscriptions migrations 01', + name: productFamilyName, description: 'Amazing subscriptions migration', }, }) @@ -35,7 +39,7 @@ export async function createContextForMigration(): Promise { await productsController.createProduct( productFamilyResponse.productFamily?.id || 0, { - product: { ...product, handle: 'subs0001' }, + product: { ...product, handle: productHandleId }, } ) ).result; @@ -43,14 +47,14 @@ export async function createContextForMigration(): Promise { await productsController.createProduct( productFamilyResponse.productFamily?.id || 0, { - product: { ...product, handle: 'subs0002' }, + product: { ...product, handle: productHandleEngageId }, } ) ).result; const subscriptionBody = createMockSubscription({ - productHandle: 'subs0001', - customerReference: 'subsProduct001', + productHandle: productHandleId, + customerReference: productHandleEngageId, }); const subscriptionResponse = ( diff --git a/e2e/src/utils/testTeardown.ts b/e2e/src/utils/testTeardown.ts index 13a36977..12acbce8 100644 --- a/e2e/src/utils/testTeardown.ts +++ b/e2e/src/utils/testTeardown.ts @@ -1,8 +1,24 @@ import { cleanSite } from '.'; +import { + removeCustomerMetadataList, + removeSubscriptionsMetadataList, +} from '../customMetadataController/utils'; +import { + removeCustomerCustomList, + removeSubscriptionsCustomList, +} from './customFieldsController'; + const teardown = async () => { - console.log('end it'); - cleanSite(); + try { + await cleanSite(); + await removeSubscriptionsMetadataList(); + await removeSubscriptionsCustomList(); + await removeCustomerMetadataList(); + await removeCustomerCustomList(); + } catch (error) { + console.error('Error on Clean-up:', error); + } }; export default teardown;