import * as mocha from 'mocha'; import * as chai from 'chai'; const expect = chai.expect; import { VirtualStateMachine } from './state-machine'; import { MongoTxn } from '@birbal/mongo-utilities/dist/mongo-txn'; import { MongoTxnRegistry } from '@birbal/mongo-utilities/dist/mongo-txn-registry'; let testModel: VirtualStateMachine; let DB_NAME = "birbal_sample_db"; let virtualId: string; let userId = "uid01"; let txn: MongoTxn; let dbTxnId: string|undefined; describe('request-state-machine', 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_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" testModel = new VirtualStateMachine(DB_NAME); txn = await MongoTxnRegistry.getSingleton().registerNewTxn(DB_NAME); await txn.beginTxn(); dbTxnId = txn.id; }); after(async function () { await txn.commitTxn(); console.log("******END Tests*******"); }); it('create', function (done) { this.timeout(5000); let promise = testModel.create(userId, 'pan', dbTxnId); promise.then((res) => { virtualId = res; done() }) .catch(err => { done(err); }) }); it('submit', function (done) { this.timeout(5000); let promise = testModel.submit(virtualId, dbTxnId); promise.then(() => { done() }) .catch(err => { done(err); }) }); it('approve', function (done) { this.timeout(5000); let promise = testModel.approve(virtualId, dbTxnId); promise.then(() => { done() }) .catch(err => { done(err); }) }); it('rejected', function (done) { this.timeout(5000); let promise = testModel.rejected(virtualId, dbTxnId); promise.then(() => { done(new Error("Should have failed")); }) .catch(err => { done(); }) }); it('removed', function (done) { this.timeout(5000); let promise = testModel.removed(virtualId, dbTxnId); promise.then(() => { done(new Error("Should have failed")); }) .catch(err => { done(); }) }); it('expire', function (done) { this.timeout(5000); let promise = testModel.expire(virtualId, dbTxnId); promise.then(() => { done() }) .catch(err => { done(err); }) }); it('revoke', function (done) { this.timeout(5000); let promise = testModel.revoke(virtualId, dbTxnId); promise.then(() => { done(new Error("Should have failed")); }) .catch(err => { done(); }) }); });