Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
suite('ioc/Decorators', () => {
suite('Autowire', () => {
test('Autowire gets called', () => {
// const val = new Test1();
Reflect.hasMetadata('inceptum', Test1.prototype).must.be.true();
const metadata = Reflect.getMetadata('inceptum', Test1.prototype);
metadata.autowire.get('prop1').must.equal('the value');
});
});
suite('Lazy', () => {
test('Lazy gets called', () => {
// const val = new Test1();
Reflect.hasMetadata('inceptum', Test1.prototype).must.be.true();
const metadata = Reflect.getMetadata('inceptum', Test1.prototype);
metadata.lazy.must.be.false();
});
});
suite('Groups', () => {
test('Groups are Autowired', async () => {
const context = new Context('test1');
context.addObjectDefinitionInspector(new ObjectDefinitionDecoratorInspector());
context.registerDefinition(new BaseSingletonDefinition(Wired1));
context.registerDefinition(new BaseSingletonDefinition(Wired2));
context.registerDefinition(new BaseSingletonDefinition(Wired3));
context.registerDefinition(new BaseSingletonDefinition(WireInto));
await context.lcStart();
});
test('If trace contains me, there\'s a Circular Dependency', () => {
const def = new BaseSingletonDefinition<a>(A);
try {
def.checkConstructorCircularDependency(['hsd', 'A']);
false.must.be.true();
} catch (e) {
e.must.be.an.error(/Circular dependency detected/);
}
});
test('If trace doesn\'t contains me, there\'s no Circular Dependency', () => {
const def = new BaseSingletonDefinition</a><a>(A);
def.checkConstructorCircularDependency(['hsd', 'B']);
});
});
suite('getInstance', () => {
test('get simple instance', () => {
const contextMock = MockUtil.mock(Context);
// const contextMock = new Object();
const defA = new BaseSingletonDefinition</a><a>(A);
defA.setContext(contextMock);
const promise = defA.getInstance()
.then((instance) => {
instance.must.not.be.falsy();
});
return promise;
});
test('get instance with constructor dep', () => {
const contextMock = MockUtil.mock(Context);
// const contextMock = new Object();
const defA = new BaseSingletonDefinition</a><a>(A);</a>
suite('HealthCheckGroup', () => {
suite('Grouping', () => {
test('adding simple test adds it directly', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId');
group.addCheck(instance(mockHealthCheck));
group.healthChecks.size.must.equal(1);
Array.from(group.healthChecks.keys()).must.eql(['simpleId']);
});
test('adding 2nd level test adds it to a group', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId.subtest');
group.addCheck(instance(mockHealthCheck));
group.healthChecks.size.must.equal(1);
Array.from(group.healthChecks.keys()).must.eql(['simpleId']);
const simpleIdGroup = group.healthChecks.get('simpleId');
group.healthChecks.size.must.equal(1);
Array.from(group.healthChecks.keys()).must.eql(['simpleId']);
const simpleIdGroup = group.healthChecks.get('simpleId');
simpleIdGroup.must.be.instanceOf(HealthCheckGroup);
const asGroup = simpleIdGroup as HealthCheckGroup;
asGroup.healthChecks.size.must.equal(1);
Array.from(asGroup.healthChecks.keys()).must.eql(['subtest']);
const simpleIdGroup2 = asGroup.healthChecks.get('subtest');
simpleIdGroup2.must.be.instanceOf(HealthCheckGroup);
const asGroup2 = simpleIdGroup2 as HealthCheckGroup;
asGroup2.healthChecks.size.must.equal(1);
Array.from(asGroup2.healthChecks.keys()).must.eql(['subsubtest']);
});
});
suite('Lifecycle', () => {
test('starting the group starts the checks', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId');
group.addCheck(instance(mockHealthCheck));
group.start();
verify(mockHealthCheck.start()).once();
group.stop();
});
test('stopping the group stops the checks', () => {
const group = new HealthCheckGroup('test1');
const mockHealthCheck = mock(HealthCheck);
when(mockHealthCheck.getCheckName()).thenReturn('simpleId');
group.addCheck(instance(mockHealthCheck));
group.start();
verify(mockHealthCheck.start()).once();
import { suite, test, slow, timeout } from "mocha-typescript";
import {mount} from "avoriaz";
import SelectList from "./../src/select-list.ts";
import expect from 'expect';
import {StandardSlot} from "./resources.ts";
import sinon from 'sinon';
suite("SelectList", () => {
test("it can set the name", () => {
let wrapper: any = mount(SelectList, {
propsData: {
name: 'title'
}
});
expect(wrapper.first('select').hasAttribute('name')).toBe(true);
expect(wrapper.first('select').getAttribute('name')).toBe('title');
});
test("the label gets output", () => {
let wrapper: any = mount(SelectList, {
propsData: {
name: 'title',
label: 'My Input'
suite('ioc/Context', () => {
suite('inheritance', () => {
test('starting the child context starts the parent context', () => {
const parentContext = new Context('parent context');
const childContext = new Context('child context', parentContext);
return childContext.lcStart()
.then(() => {
childContext.getStatus().must.be.equal(LifecycleState.STARTED);
parentContext.getStatus().must.be.equal(LifecycleState.STARTED);
})
.then(() => childContext.lcStop());
});
test('stopping the child context stops the parent context', () => {
const parentContext = new Context('parent context');
const childContext = new Context('child context', parentContext);
return childContext.lcStart()
.then(() => childContext.lcStop())
.then(() => {
const myContext = new Context('test1');
myContext.registerSingletons(new BaseSingletonDefinition(A).constructorParamByRef('B'));
myContext.registerSingletons(new BaseSingletonDefinition(B).constructorParamByRef('A'));
return myContext.lcStart()
.then(() => myContext.getObjectByName('A'))
.then(() => {
throw new Error('Shouldn\'t be here');
})
.catch((err) => {
err.must.be.an.error(/Circular dependency detected/);
})
.then(() => myContext.lcStop());
});
});
suite('cloning', () => {
test('throws an exception when in any state other than NOT_STARTED', () => {
const myContext = new Context('test1');
return myContext.lcStart()
.then(() => myContext.clone('copy'))
.catch((err) => err.must.be.an.error(/Operation requires state to be/))
.then(() => myContext.lcStop());
});
test('clones all object definitions', () => {
const myContext = new Context('test1');
myContext.registerSingletons(new BaseSingletonDefinition(A).constructorParamByValue('the value'));
const clonedContext = myContext.clone('test2');
return myContext.lcStart()
.then(() => clonedContext.lcStart())
.then(() => PromiseUtil.mapSeries([myContext, clonedContext], (c) => c.getObjectByName('A')))
const myContext = new Context('test1');
myContext.registerSingletons(new BaseSingletonDefinition(A));
myContext.registerSingletons(new BaseSingletonDefinition(B).setPropertyByDefinitionGroup('a', 'myGroup'));
myContext.addObjectNameToGroup('myGroup', 'A');
await myContext.lcStart();
const b: B = await myContext.getObjectByName('B');
(b === undefined).must.be.false();
(b.a === undefined).must.be.false();
b.a.must.be.an.array();
b.a.length.must.equal(1);
(b.a[0] instanceof BaseSingletonDefinition).must.be.true();
(b.a[0] as any as BaseSingletonDefinition).getName().must.equal('A');
await myContext.lcStop();
});
});
suite('wiring', () => {
test('can manage circular dependencies', () => {
const myContext = new Context('test1');
myContext.registerSingletons(new BaseSingletonDefinition<a>(A).constructorParamByRef('B'));
myContext.registerSingletons(new BaseSingletonDefinition<b>(B).setPropertyByRef('a', 'A'));
return myContext.lcStart()
.then(() => PromiseUtil.map(['A', 'B'], (n) => myContext.getObjectByName(n)))
.then(([a, b]) => {
(a === undefined).must.be.false();
(b === undefined).must.be.false();
(a.val === undefined).must.be.false();
a.val.must.be.equal(b);
return [a, b];
})
.then((v) => PromiseUtil.sleepPromise(20, v))
.then(([a, b]) => {
b.a.must.be.equal(a);</b></a>
import {
assert,
} from 'chai'
import {
suite,
test,
skip,
} from 'mocha-typescript'
import { ORDERBOOK_VERSION } from '../src/api'
import { Order, OrderSide, OrderJSON } from '../src/types'
import { orderToJSON } from '../src'
import { mainApi, rinkebyApi, apiToTest, ALEX_ADDRESS, CK_RINKEBY_TOKEN_ID, CK_RINKEBY_ADDRESS, CK_RINKEBY_SELLER_FEE } from './constants'
suite('api', () => {
test('API has correct base url', () => {
assert.equal(mainApi.apiBaseUrl, 'https://api.opensea.io')
assert.equal(rinkebyApi.apiBaseUrl, 'https://rinkeby-api.opensea.io')
})
test('API fetches bundles and prefetches sell orders', async () => {
const { bundles } = await apiToTest.getBundles({asset_contract_address: CK_RINKEBY_ADDRESS, on_sale: true})
assert.isArray(bundles)
const bundle = bundles[0]
assert.isNotNull(bundle)
if (!bundle) {
return
}
assert.include(bundle.assets.map(a => a.assetContract.name), "CryptoKittiesRinkeby")
import { JsonTslint } from '@scaffold/generators'
import { expect } from 'chai'
import { skip, slow, suite, test, timeout } from 'mocha-typescript'
import { join } from 'path'
@suite('Unit::Scaffold::JsonTslint')
class Test {
@test
'can be initialized'() {
const gen = JsonTslint()
expect(gen).to.be.an('object')
}
}