UNPKG

dg-npm-templates

Version:

Npx generator for react app dependency creation by digite

44 lines (43 loc) 1.75 kB
const assert = require("assert"); const common = require("../src/function/function"); const encryption = require("../src/function/encryption"); const gateway = require("../src/function/gateway"); describe("Encryption Decryption Test", function () { const payload = "Hello World"; const encrypted = encryption.encrypt(payload); const decrypted = encryption.decrypt(encrypted); it("Encrypted Text not equal to payload", function () { assert.notEqual(payload, encrypted); assert.equal(payload, decrypted); }); it("Decrypted Text equal to payload", function () { assert.equal(payload, decrypted); }); }); describe("Parse JSON safely", function () { it("Should return a valid json object for a valid json string", function () { const json = '{"first_name":"Jon","last_name":"Doe"}'; const obj = common.safeJsonParse(json); assert.equal(common.isSet(obj.first_name), true); }); it("Should return a string for a non json string", function () { const json = '{"first_name":"Jon","last_name""Doe"}'; const obj = common.safeJsonParse(json); assert.equal(typeof obj, "string"); }); it("Invalid string should not be parseable", function () { const json = '{"first_name":"Jon","last_name""Doe"}'; const obj = common.safeJsonParse(json); assert.equal(common.isSet(obj.first_name), false); }); }); describe("Get Slug Data", function () { it("Should return valid slug data", function () { const obj = gateway.getSlugData("digite.dev.localhost.com"); assert.equal(obj.realm, "NIMBLEDEV"); }); it("Should return default slug data for unknown slug", function () { const obj = gateway.getSlugData("xxxx.dev.localhost.com"); assert.equal(obj.realm, "NIMBLEDEV"); }); });