-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alberto Blacutt
authored and
Alberto Blacutt
committed
Feb 16, 2024
1 parent
33fdaef
commit 83260f7
Showing
18 changed files
with
312 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: "[email protected]", | ||
ccEmails: "[email protected]", | ||
} | ||
firstName: 'Martha', | ||
lastName: 'Washington', | ||
email: '[email protected]', | ||
ccEmails: '[email protected]', | ||
}, | ||
}; | ||
const validSecondCustomerBody = { | ||
customer: { | ||
firstName: "George", | ||
lastName: "Washington", | ||
email: "[email protected]", | ||
ccEmails: "[email protected]", | ||
} | ||
firstName: 'George', | ||
lastName: 'Washington', | ||
email: '[email protected]', | ||
ccEmails: '[email protected]', | ||
}, | ||
}; | ||
const invalidClient = createClient({ | ||
timeout: 0, | ||
|
@@ -41,47 +42,70 @@ 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); | ||
}); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
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,39 +115,47 @@ 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); | ||
}); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
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,39 +165,50 @@ 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); | ||
}); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
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,39 +218,46 @@ 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); | ||
}); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
|
||
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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.