import * as mocha from 'mocha'; import * as chai from 'chai'; import * as UUID from 'uuid' const expect = chai.expect; import { SystemResource } from './system-identity'; import { MongoTxn } from '@birbal/mongo-utilities/dist/mongo-txn'; import { MongoTxnRegistry } from '@birbal/mongo-utilities/dist/mongo-txn-registry'; let DB_NAME = "birbal_sample_db"; let testModel: SystemResource; let txn: MongoTxn; let userId: string = "test-uid01"; let userType: string = '1234'; let idValue: string = '4321'; let idType: string = '1111'; let limit: number = 0; let skip: number = 0; let dbTxnId: string|undefined; describe('User Resource test cases', function () { before(async function () { console.log("******BEGIN Tests*******"); process.env["BIRBAL_MONGO_HOST"] = "10.42.0.1"; process.env["BIRBAL_MONGO_PORT"] = "27017" process.env["BIRBAL_MONGO_POOL_SIZE"] = "4"; process.env["BIRBAL_MONGO_DATABASE"] = DB_NAME // process.env["BIRBAL_PRIMARY_REPLICA"] = "rs0"; process.env["BIRBAL_SYSTEM_SECRET"] = "asterix" process.env["BIRBAL_SYSTEM_PORT"] = "3000" process.env["BIRBAL_SYSTEM_HOST_TAG"] = "SampleSys" process.env["BIRBAL_SYSTEM_LOGTYPE"] = "5" process.env["BIRBAL_SYSTEM_LOGMODE"] = "console" process.env["BIRBAL_FACTOR_API_KEY"] = "e2b56cfe-37ea-11e8-a895-0200cd936042"; process.env["BIRBAL_SENDGRID_VERIFICATION_BASE_URL"] = "http://localhost:2998/comm/email/otp"; txn = await MongoTxnRegistry.getSingleton().registerNewTxn(DB_NAME); await txn.beginTxn(); dbTxnId = txn.id; let model = new SystemResource( DB_NAME , process.env["BIRBAL_SYSTEM_SECRET"] ); testModel = model; }); after(async function () { await txn.commitTxn(); console.log("******END Tests*******"); }); it('Create', function (done) { this.timeout(5000); let promise = testModel.addIdentity(userId, userType, idValue, idType, dbTxnId); promise.then((res) => { userId = res; done(); }) .catch(err => { done(err); }); }); it('Remove', function (done) { this.timeout(5000); let promise = testModel.removeIdentity(userType, idValue, idType, dbTxnId); promise.then((res) => { done(); }) .catch(err => { done(err); }); }); it('AdvanceSearch', function (done) { this.timeout(5000); let promise = testModel.advancedSearch(DB_NAME, limit, skip, 'qqq'); promise.then((res) => { console.log(res); done(); }) .catch(err => { done(err); }); }); });