boldsign
Version:
NodeJS client for boldsign
310 lines • 15.7 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const brandingApi_1 = require("../../api/brandingApi");
const config_1 = __importDefault(require("../config"));
const fs = __importStar(require("fs"));
describe('Test suite', () => {
let brandingApi;
let brandId;
beforeAll(() => {
brandId = null;
const apiKey = config_1.default.apiKey;
const baseUrl = config_1.default.baseUrl;
if (!baseUrl || !apiKey) {
throw new Error("Environment variables 'HOST_URL' or 'API_KEY' are not set");
}
brandingApi = new brandingApi_1.BrandingApi(baseUrl);
brandingApi.setApiKey(apiKey);
});
test('Test1:should create a brand successfully', () => __awaiter(void 0, void 0, void 0, function* () {
const brandName = "NodeSDK";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
const backgroundColor = "Blue";
const buttonColor = "Black";
const buttonTextColor = "White";
const emailDisplayName = "{SenderName} from Syncfusion";
try {
const createBrandApiResponse = yield brandingApi.createBrand(brandName, brandLogo, backgroundColor, buttonColor, buttonTextColor, emailDisplayName);
console.log("Brand created successfully:", createBrandApiResponse.brandId);
brandId = createBrandApiResponse.brandId;
expect(brandId).toBeDefined();
expect(brandId).toBeGreaterThan(0);
}
catch (error) {
console.log("Error occurred while creating the brand:", error.message);
}
}), 20000);
test('Test2:should create a brand only with required fields', () => __awaiter(void 0, void 0, void 0, function* () {
const brandName = "NodeSDK";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
try {
const createBrandApiResponse = yield brandingApi.createBrand(brandName, brandLogo);
console.log("Brand created successfully:", createBrandApiResponse.brandId);
expect(createBrandApiResponse).toBeDefined();
}
catch (error) {
console.log("Error occurred while creating the brand:", error);
expect(error).toBeUndefined();
}
}), 20000);
test('Test3:should fail to create a brand without brand name', () => __awaiter(void 0, void 0, void 0, function* () {
const brandName = "";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
const backgroundColor = "Blue";
const buttonColor = "Black";
const buttonTextColor = "White";
const emailDisplayName = "{SenderName} from Syncfusion";
try {
yield brandingApi.createBrand(brandName, brandLogo, backgroundColor, buttonColor, buttonTextColor, emailDisplayName);
throw new Error("API call should have failed");
}
catch (error) {
console.error("Error occurred while creating the brand:", error.message);
expect(error.message).toBeDefined();
}
}), 20000);
test('Test4:should fail to create a brand with invalid background color', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const brandName = "Node SDK";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
const backgroundColor = "invalid-color";
const buttonColor = "Black";
const buttonTextColor = "White";
const emailDisplayName = "{SenderName} from Syncfusion";
try {
yield brandingApi.createBrand(brandName, brandLogo, backgroundColor, buttonColor, buttonTextColor, emailDisplayName);
throw new Error("API call should have failed due to invalid background color");
}
catch (error) {
console.error("Expected error for invalid background color:", error);
expect(error.response).toBeDefined();
expect((_a = error.response) === null || _a === void 0 ? void 0 : _a.status).toBe(400);
expect(error.response.statusText).toBe("Bad Request");
}
}), 20000);
test('Test5:should fail to create a brand with invalid button color', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const brandName = "Node SDK";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
const backgroundColor = "Blue";
const buttonColor = "not-a-color";
const buttonTextColor = "White";
const emailDisplayName = "{SenderName} from Syncfusion";
try {
yield brandingApi.createBrand(brandName, brandLogo, backgroundColor, buttonColor, buttonTextColor, emailDisplayName);
throw new Error("API call should have failed due to invalid button color");
}
catch (error) {
console.error("Expected error for invalid button color:", error);
expect(error.response).toBeDefined();
expect((_a = error.response) === null || _a === void 0 ? void 0 : _a.status).toBe(400);
expect(error.response.statusText).toBe("Bad Request");
}
}), 20000);
test('Test6:should fail to create a brand with invalid button text color', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const brandName = "Node SDK";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
const backgroundColor = "Blue";
const buttonColor = "Black";
const buttonTextColor = "invalid-text-color";
const emailDisplayName = "{SenderName} from Syncfusion";
try {
yield brandingApi.createBrand(brandName, brandLogo, backgroundColor, buttonColor, buttonTextColor, emailDisplayName);
throw new Error("API call should have failed due to invalid button text color");
}
catch (error) {
console.error("Expected error for invalid button text color:", error);
expect(error.response).toBeDefined();
expect((_a = error.response) === null || _a === void 0 ? void 0 : _a.status).toBe(400);
expect(error.response.statusText).toBe("Bad Request");
}
}), 20000);
test('Test7:should fail to create a brand with invalid logo path', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const brandName = "Node SDK";
const brandLogo = fs.createReadStream("tests/documents/agreement.pdf");
try {
yield brandingApi.createBrand(brandName, brandLogo);
throw new Error("API call should have failed due to invalid button text color");
}
catch (error) {
console.error("Expected error for invalid button text color:", error);
expect(error.response).toBeDefined();
expect((_a = error.response) === null || _a === void 0 ? void 0 : _a.status).toBe(400);
expect(error.response.statusText).toBe("Bad Request");
}
}), 20000);
test('Test8:should update a brand successfully', () => __awaiter(void 0, void 0, void 0, function* () {
const brandName = "Node-SDK-Test";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
const backgroundColor = "Blue";
const buttonColor = "Black";
const buttonTextColor = "White";
const emailDisplayName = "divya.boopathy+12@syncfusion.com";
try {
const updateBrandApiResponse = yield brandingApi.editBrand(brandId, brandName, brandLogo, backgroundColor, buttonColor, buttonTextColor, emailDisplayName);
console.log("Brand updated successfully:", updateBrandApiResponse.brandId);
expect(updateBrandApiResponse).toBeDefined();
}
catch (error) {
console.error("Error occurred while updating the brand:", error.message);
throw new Error("API call failed");
}
}), 20000);
test('Test9: should fail to update a brand with invalid logo path', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const brandName = "Node-SDK-Test";
try {
const brandLogo = fs.createReadStream("tests/documents/agreement.pdf");
yield brandingApi.editBrand(brandId, brandName, brandLogo);
}
catch (error) {
console.error("Expected error while updating with invalid logo path:");
expect(error.response).toBeDefined();
expect((_a = error.response) === null || _a === void 0 ? void 0 : _a.status).toBe(400);
expect(error.response.statusText).toBe("Bad Request");
}
}), 20000);
test('Test10: should fail to update a brand with invalid brand ID', () => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const brandName = "Node-SDK-Test";
try {
const invalidBrandId = "invalid-brand-id";
const brandLogo = fs.createReadStream("tests/documents/logo.jpg");
yield brandingApi.editBrand(invalidBrandId, brandName, brandLogo);
throw new Error("API call should have failed due to invalid brand ID");
}
catch (error) {
console.error("Expected error while updating with invalid brand ID:", error.message);
expect(error.response).toBeDefined();
expect((_a = error.response) === null || _a === void 0 ? void 0 : _a.status).toBe(400);
expect(error.response.statusText).toBe("Bad Request");
}
}), 20000);
test('Test11:should get brand details successfully', () => __awaiter(void 0, void 0, void 0, function* () {
try {
const brandDetailsResponse = yield brandingApi.getBrand(brandId);
console.log("Brand details retrieved successfully:", brandDetailsResponse);
expect(brandDetailsResponse).toBeDefined();
expect(brandDetailsResponse.id).toBe(brandId);
}
catch (error) {
console.log("Error occurred while calling the API:", error.message);
}
}), 20000);
test('Test12:should fail to retrieve brand details with non-existent brand ID', () => __awaiter(void 0, void 0, void 0, function* () {
const brandId = "INVALID_BRAND_ID";
try {
const brandDetailsResponse = yield brandingApi.getBrand(brandId);
console.log("Brand details retrieved successfully:", brandDetailsResponse);
expect(brandDetailsResponse).toBeUndefined();
}
catch (error) {
console.error("Error occurred while calling the API:", error.message);
expect(error.message).toBeDefined();
}
}), 20000);
test('Test13:should retrieve the brand list successfully', () => __awaiter(void 0, void 0, void 0, function* () {
try {
const brandListResponse = yield brandingApi.brandList();
console.log("Brand List:", brandListResponse);
}
catch (error) {
console.error("Error occurred while calling the API:", error.message);
throw new Error("API call failed");
}
}), 20000);
test('Test14:should reset the default brand successfully', () => __awaiter(void 0, void 0, void 0, function* () {
try {
const response = yield brandingApi.resetDefaultBrand(brandId);
console.log("Brand reset as default successfully:", response);
expect(response).toBeDefined();
}
catch (error) {
console.error("Error occurred while calling the API:", error.message);
throw new Error("API call failed to reset default brand");
}
}), 30000);
test('should fail to reset the default brand with non-existent brand ID', () => __awaiter(void 0, void 0, void 0, function* () {
const brandId = "NON_EXISTENT_BRAND_ID";
try {
const response = yield brandingApi.resetDefaultBrand(brandId);
console.log("Brand reset unexpectedly succeeded:", response);
throw new Error("Test failed. API call should have failed with non-existent brand ID.");
}
catch (error) {
console.error("Expected error occurred while calling the API:", error.message);
}
}), 20000);
test('Tes16:should delete a brand successfully', () => __awaiter(void 0, void 0, void 0, function* () {
try {
const deleteResponse = yield brandingApi.deleteBrand(brandId);
console.log("Brand deleted successfully:", deleteResponse);
expect(deleteResponse).toBeDefined();
expect(deleteResponse.success).toBe(true);
}
catch (error) {
console.log("Error occurred while calling the API:", error.message);
}
}), 20000);
test('Test17:should fail to delete a brand with invalid brand ID', () => __awaiter(void 0, void 0, void 0, function* () {
const brandId = "invalid-brand-id";
try {
const deleteResponse = yield brandingApi.deleteBrand(brandId);
console.log("Brand deleted unexpectedly:", deleteResponse);
expect(deleteResponse).toBeDefined();
expect(deleteResponse.success).toBe(false);
}
catch (error) {
console.error("Error occurred while calling the API:", error.message);
expect(error.message).toBeDefined();
}
}), 20000);
});
//# sourceMappingURL=BrandingApiTest.spec.js.map