Skip to content

Commit

Permalink
DE-575: e2e tests for referral codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Alberto Blacutt authored and Alberto Blacutt committed Mar 1, 2024
1 parent a27e408 commit d0447a1
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions e2e/src/referralCodesController.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
});

0 comments on commit d0447a1

Please sign in to comment.