UNPKG

@magic.batua/account

Version:

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

77 lines 3.17 kB
"use strict"; // // Database.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 Account_1 = require("../Source/Account"); const Source_1 = require("../Source/Source"); const Database = require("../Source/Database"); const mongodb_1 = require("mongodb"); const expect = Chai.expect; describe("◊◊◊◊ Database ◊◊◊◊", function () { let dbURI; if (process.env.NodeEnv == "production") { dbURI = process.env.Db_ConnString; } else { let env = YAML.safeLoad(FileSystem.readFileSync(".env", "utf8")); dbURI = env.Db_ConnString; } let db; let account = new Account_1.Account({ "name": "Test", "phone": "1234567890", "email": "contact@example.com", "password": "password", "inviteCode": "abcdefgh" }, Source_1.Source.Client); before(async function () { db = await mongodb_1.MongoClient.connect(dbURI); }); it("Should insert a new Account without throwing an exception.", async function () { expect(await Database.Insert(account, db)).to.be.instanceOf(Account_1.Account); }); it("Should not insert a duplicate account.", async function () { expect(await Database.IsDuplicate(account, db)).to.be.true; }); it("Should find referrer with invite code: abcdefgh", async function () { let referrer = await Database.GetReferrer("abcdefgh", db); expect(referrer).to.not.be.null; expect(referrer._id.toHexString()).to.be.equal("5aad5ef68f678e060c49ee4f"); }); it("Should not find a referral with invite code: animesh.recommends", async function () { let referrer = await Database.GetReferrer("animesh.recommends", db); expect(referrer).to.be.null; }); it("Should find a user with phone number 1234567890", async function () { let account = await Database.Find("1234567890", db); expect(account).to.not.be.null; expect(account).to.have.property("phone").equal("1234567890"); }); it("Should not find a user with phone number 9981999999", async function () { let account = await Database.Find("9981999999", db); expect(account).to.be.null; }); it("Can log into 1234567890 account using password as password", async function () { let account = await Database.Find("1234567890", db); expect(account).to.not.be.null; expect(account.CanAuthenticateUsing("password")).to.be.true; }); it("Cannot log into 1234567890 account using abcdefgh as password", async function () { let account = await Database.Find("1234567890", db); expect(account).to.not.be.null; expect(account.CanAuthenticateUsing("abcdefgh")).to.be.false; }); after(async function () { await db.collection("Users").remove({ phone: "1234567890" }); db.close(); }); }); //# sourceMappingURL=Database.spec.js.map