-
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
- 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.
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); | ||
}); | ||
}); | ||
}); | ||
}); |