Skip to content

Commit

Permalink
DE-575: e2e tests for referral codes (#63)
Browse files Browse the repository at this point in the history
Co-authored-by: Alberto Blacutt <[email protected]>
  • Loading branch information
alberto-blacutt-maxio and Alberto Blacutt authored Mar 4, 2024
1 parent 28446b3 commit a9e0b42
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 a9e0b42

Please sign in to comment.