From d0447a11a4c871cb06223d18d908b95959c174a5 Mon Sep 17 00:00:00 2001 From: Alberto Blacutt Date: Thu, 29 Feb 2024 22:09:09 -0400 Subject: [PATCH] DE-575: e2e tests for referral codes --- e2e/src/referralCodesController.spec.ts | 42 +++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 e2e/src/referralCodesController.spec.ts diff --git a/e2e/src/referralCodesController.spec.ts b/e2e/src/referralCodesController.spec.ts new file mode 100644 index 00000000..4537a6d0 --- /dev/null +++ b/e2e/src/referralCodesController.spec.ts @@ -0,0 +1,42 @@ +import { ReferralCodesController } from 'advanced-billing-sdk'; +import { createClient, createInvalidClient } from './config'; +import { createSubscription } from './utils/subscription'; +describe('Referral codes', () => { + let referralCodesController: ReferralCodesController; + let invalidReferralCodesController: ReferralCodesController; + + beforeAll(async () => { + const client = createClient(); + const invalidClient = createInvalidClient(); + referralCodesController = new ReferralCodesController(client); + invalidReferralCodesController = new ReferralCodesController(invalidClient); + }); + + describe('Validate Referral codes', () => { + test('should get a valid referral code data', async () => { + const { subscriptionResponse } = await createSubscription({}); + const referralCodesResponse = + await referralCodesController.validateReferralCode( + subscriptionResponse?.subscription?.referralCode || '' + ); + expect(referralCodesResponse.statusCode).toBe(200); + }); + + test('should throw a 404 error when the referral code is invalid', async () => { + const promise = referralCodesController.validateReferralCode('8y7jqr'); + expect(promise).rejects.toThrow(); + await promise.catch((reason) => { + expect(reason.statusCode).toBe(404); + }); + }); + + test('should throw a 401 error when the user sends incorrect credentials', async () => { + const promise = + invalidReferralCodesController.validateReferralCode('CODE'); + expect(promise).rejects.toThrow(); + await promise.catch((reason) => { + expect(reason.statusCode).toBe(401); + }); + }); + }); +});