Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DE-573: added e2e testing for invoice-proforma controller #55

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions e2e/src/proformaInvoiceController/previewProformaInvoice.spec.ts
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);
});
});
});
});
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 e2e/src/proformaInvoiceController/voidProformaInvoice.spec.ts
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" });
});
});
});
});
Loading