-
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.
DE-575: e2e tests for referral codes (#63)
Co-authored-by: Alberto Blacutt <[email protected]>
- Loading branch information
1 parent
28446b3
commit a9e0b42
Showing
1 changed file
with
42 additions
and
0 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
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); | ||
}); | ||
}); | ||
}); | ||
}); |