UNPKG

@magic.batua/account

Version:

The Account modules powers the user account management features of the Magic Batua platform.

92 lines 3.42 kB
"use strict"; // // Registry.spec.ts // Magic-Account // // Created on February 14, 2018 by Animesh Mishra <hello@animesh.ltd> // © 2018 Magic Batua. All Rights Reserved. // Object.defineProperty(exports, "__esModule", { value: true }); const FileSystem = require("fs"); const YAML = require("js-yaml"); const Chai = require("chai"); const mongodb_1 = require("mongodb"); const index_1 = require("../index"); const messaging_1 = require("@magic.batua/messaging"); const expect = Chai.expect; describe("◊◊◊◊ Registry ◊◊◊◊", function () { // Set a test time out of 99999 ms for all Registry tests this.timeout(99999); let dbURI; let smsCreds; if (process.env.NodeEnv == "production") { dbURI = process.env.Db_ConnString; smsCreds = { username: process.env.SMS_Username, password: process.env.SMS_Password, senderID: process.env.SMS_SenderID }; } else { let env = YAML.safeLoad(FileSystem.readFileSync(".env", "utf8")); dbURI = env.Db_ConnString; smsCreds = { username: env.SMS_Username, password: env.SMS_Password, senderID: env.SMS_SenderID }; } let db; let json = { "name": "Test", "phone": "1234567890", "email": "contact@example.com", "password": "password", "inviteCode": "abcdefgh" }; let registry; let id; before(async function () { db = await mongodb_1.MongoClient.connect(dbURI); // Init messaging let messaging = new messaging_1.Messaging(smsCreds); registry = new index_1.Registry(db, messaging); }); it("Should create a new Account with phone 1234567890", async function () { try { let response = await registry.Create(json); let account = JSON.parse(response); expect(account.phone).to.be.equal("1234567890"); expect(account.referredBy).to.be.equal("5aad5ef68f678e060c49ee4f"); } catch (exception) { console.log(exception); Chai.assert(false); } }); it("Should retrieve account with phone 1234567890 using password password", async function () { let account = await registry.Retrieve({ phone: "1234567890", password: "password" }); expect(account).to.not.be.null; }); it("Should throw error when logging in with phone 1234567890 and password abcdefgh", function () { expect(() => registry.Retrieve({ phone: "1234567890", password: "abcdefgh" })).to.throw; }); it("Should put an account into deletion hold", async function () { let response = await registry.Retrieve({ phone: "1234567890", password: "password" }); let account = JSON.parse(response); await registry.Remove(account._id); }); it("Should remove a deletion hold", async function () { let response = await registry.Retrieve({ phone: "1234567890", password: "password" }); let account = JSON.parse(response); expect(account).to.not.be.null; }); it("Should send a verification SMS", async function () { expect(await registry.DidSendOTP("1234567890")).to.throw; }); after(async function () { await db.collection("Users").remove({ phone: "1234567890" }); db.close(); }); }); //# sourceMappingURL=Registry.spec.js.map