-
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-573: added e2e testing for invoice-proforma controller (#55)
Co-authored-by: Alberto Blacutt <[email protected]>
- Loading branch information
1 parent
bb56bd8
commit 8e3b976
Showing
3 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
e2e/src/proformaInvoiceController/previewProformaInvoice.spec.ts
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,67 @@ | ||
import { | ||
Environment, | ||
ProformaInvoicesController, | ||
SubscriptionResponse, | ||
} from 'advanced-billing-sdk'; | ||
import { createClient, CONFIG } from '../config'; | ||
import { createSubscription } from '../utils/subscription'; | ||
|
||
describe('Proforma Invoices Controller', () => { | ||
let proformaInvoicesController: ProformaInvoicesController; | ||
let invalidProformaInvoiceController: ProformaInvoicesController; | ||
let subscriptionResponse: SubscriptionResponse | null; | ||
|
||
beforeAll(async () => { | ||
const client = createClient(); | ||
const invalidClient = createClient({ | ||
timeout: 0, | ||
domain: CONFIG.DOMAIN, | ||
environment: Environment.Production, | ||
subdomain: CONFIG.SUBDOMAIN, | ||
basicAuthUserName: 'invalidKey', | ||
basicAuthPassword: CONFIG.PASSWORD, | ||
}); | ||
proformaInvoicesController = new ProformaInvoicesController(client); | ||
invalidProformaInvoiceController = new ProformaInvoicesController( | ||
invalidClient | ||
); | ||
const subscriptionContext = await createSubscription({}); | ||
subscriptionResponse = subscriptionContext.subscriptionResponse; | ||
}); | ||
|
||
describe('Preview Proforma Invoice', () => { | ||
test('should preview a proforma invoice', async () => { | ||
const subscriptionId = subscriptionResponse?.subscription?.id; | ||
await proformaInvoicesController.createProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
|
||
const previewResponse = | ||
await proformaInvoicesController.previewProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
expect(previewResponse.statusCode).toBe(200); | ||
expect(previewResponse.result.subscriptionId).toBe(subscriptionId); | ||
}); | ||
|
||
test('should throw a 404 error when the user sends invalid subscription_id', async () => { | ||
const promise = proformaInvoicesController.previewProformaInvoice(0); | ||
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 subscriptionId = subscriptionResponse?.subscription?.id; | ||
|
||
const promise = invalidProformaInvoiceController.previewProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
expect(promise).rejects.toThrow(); | ||
await promise.catch((reason) => { | ||
expect(reason.statusCode).toBe(401); | ||
}); | ||
}); | ||
}); | ||
}); |
96 changes: 96 additions & 0 deletions
96
e2e/src/proformaInvoiceController/proformaInvoicesController.spec.ts
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,96 @@ | ||
import { | ||
ProformaInvoicesController, | ||
SubscriptionResponse, | ||
} from 'advanced-billing-sdk'; | ||
import { createClient } from '../config'; | ||
import { createSubscription } from '../utils/subscription'; | ||
|
||
describe('Proforma Invoices Controller', () => { | ||
let proformaInvoicesController: ProformaInvoicesController; | ||
let subscriptionResponse: SubscriptionResponse | null; | ||
|
||
beforeAll(async () => { | ||
const client = createClient(); | ||
proformaInvoicesController = new ProformaInvoicesController(client); | ||
const subscriptionContext = await createSubscription({}); | ||
subscriptionResponse = subscriptionContext.subscriptionResponse; | ||
}); | ||
|
||
describe('Create Proforma Invoices', () => { | ||
test('should create a valid proforma invoice', async () => { | ||
const subscriptionId = subscriptionResponse?.subscription?.id; | ||
|
||
const createResponse = | ||
await proformaInvoicesController.createProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
expect(createResponse.statusCode).toBe(201); | ||
expect(createResponse.result.subscriptionId).toBe(subscriptionId); | ||
}); | ||
|
||
test('should throw a 404 error when the user sends invalid subscription_id', async () => { | ||
const promise = proformaInvoicesController.createProformaInvoice(0); | ||
expect(promise).rejects.toThrow(); | ||
await promise.catch((reason) => { | ||
expect(reason.statusCode).toBe(404); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Read Proforma Invoices', () => { | ||
test('should read a valid proforma invoice', async () => { | ||
const subscriptionId = subscriptionResponse?.subscription?.id; | ||
|
||
const createResponse = | ||
await proformaInvoicesController.createProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
|
||
const proformaUid = createResponse.result.uid; | ||
const readResponse = await proformaInvoicesController.readProformaInvoice( | ||
proformaUid || '' | ||
); | ||
expect(readResponse.statusCode).toBe(200); | ||
expect(readResponse.result.uid).toBe(proformaUid); | ||
}); | ||
|
||
test('should throw a 404 error when the user sends a non-existent proforma invoice UID', async () => { | ||
const promise = proformaInvoicesController.readProformaInvoice('test'); | ||
expect(promise).rejects.toThrow(); | ||
await promise.catch((reason) => { | ||
expect(reason.statusCode).toBe(404); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('List Proforma invoices', () => { | ||
test('should list proforma invoices when user sends valid subscriptionId', async () => { | ||
const subscriptionId = subscriptionResponse?.subscription?.id; | ||
await proformaInvoicesController.createProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
const listResponse = | ||
await proformaInvoicesController.listProformaInvoices({ | ||
subscriptionId: subscriptionId || 0, | ||
}); | ||
const proformaInvoicesLength = | ||
listResponse?.result?.proformaInvoices?.length || 0; | ||
expect(listResponse.statusCode).toBe(200); | ||
expect(proformaInvoicesLength >= 1).toBeTruthy(); | ||
}); | ||
|
||
test('should throw a 404 error when the request body is missing', async () => { | ||
const subscriptionId = subscriptionResponse?.subscription?.id; | ||
await proformaInvoicesController.createProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
const promise = proformaInvoicesController.listProformaInvoices({ | ||
subscriptionId: 0, | ||
}); | ||
expect(promise).rejects.toThrow(); | ||
await promise.catch((reason) => { | ||
expect(reason.statusCode).toBe(404); | ||
}); | ||
}); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
e2e/src/proformaInvoiceController/voidProformaInvoice.spec.ts
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,67 @@ | ||
import { | ||
ProformaInvoicesController, | ||
SubscriptionResponse, | ||
} from 'advanced-billing-sdk'; | ||
import { createClient } from '../config'; | ||
import { createSubscription } from '../utils/subscription'; | ||
|
||
describe('Proforma Invoices Controller', () => { | ||
let proformaInvoicesController: ProformaInvoicesController; | ||
let subscriptionResponse: SubscriptionResponse | null; | ||
beforeAll(async () => { | ||
const client = createClient(); | ||
proformaInvoicesController = new ProformaInvoicesController(client); | ||
const subscriptionContext = await createSubscription({}); | ||
subscriptionResponse = subscriptionContext.subscriptionResponse; | ||
}); | ||
|
||
describe('Void Proforma Invoice', () => { | ||
test('should void a proforma invoice', async () => { | ||
const subscriptionId = subscriptionResponse?.subscription?.id; | ||
|
||
const createResponse = | ||
await proformaInvoicesController.createProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
|
||
const proformaUid = createResponse.result.uid; | ||
const voidResponse = await proformaInvoicesController.voidProformaInvoice( | ||
proformaUid || '', | ||
{ | ||
mVoid: { | ||
reason: 'Duplicate proforma invoice', | ||
}, | ||
} | ||
); | ||
expect(voidResponse.statusCode).toBe(201); | ||
expect(voidResponse.result.uid).toBe(proformaUid); | ||
}); | ||
|
||
test('should throw a 404 error when the user sends a non-existent proforma invoice UID', async () => { | ||
const promise = proformaInvoicesController.voidProformaInvoice(''); | ||
expect(promise).rejects.toThrow(); | ||
await promise.catch((reason) => { | ||
expect(reason.statusCode).toBe(404); | ||
}); | ||
}); | ||
|
||
test('should throw a 422 error when the user does not provide reason in the request body.', async () => { | ||
const subscriptionId = subscriptionResponse?.subscription?.id; | ||
|
||
const createResponse = | ||
await proformaInvoicesController.createProformaInvoice( | ||
subscriptionId || 0 | ||
); | ||
|
||
const proformaUid = createResponse.result.uid; | ||
const promise = proformaInvoicesController.voidProformaInvoice( | ||
proformaUid || '' | ||
); | ||
expect(promise).rejects.toThrow(); | ||
await promise.catch((reason) => { | ||
expect(reason.statusCode).toBe(422); | ||
expect(reason.result.errors).toEqual({ void: "can't be blank" }); | ||
}); | ||
}); | ||
}); | ||
}); |