Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
schema: {
$ref: '#/definitions/Todo',
},
},
},
},
},
})
async find(): Promise {
return []; // dummy implementation, it's never called
}
}
const spec = getControllerSpec(MyController);
const globalSchemas = (spec.components ?? {}).schemas;
expect(globalSchemas).to.be.undefined();
});
it('throws error if method does not exist', () => {
expect(() => invalidInvocationCtx.assertMethodExists()).to.throw(
'Method MyController.prototype.invalid-method not found',
);
expect(() =>
invalidInvocationCtxForStaticMethod.assertMethodExists(),
).to.throw('Method MyController.invalid-static-method not found');
});
it('adds credential', () => {
const cred = {usr: 'auser', pass: 'mypass'};
subject.addCredential(cred);
expect(subject.credentials).to.containEql(cred);
});
});
it('implements Repository.save() with id', async () => {
const repo = new DefaultCrudRepository(Note, ds);
const note1 = await repo.create({title: 't3', content: 'c3'});
note1.content = 'c4';
const note = await repo.save(note1);
const result = await repo.findById(note!.id);
expect(result.toJSON()).to.eql(note1.toJSON());
});
it('serializes values', () => {
expect(anyType.serialize('str')).to.eql('str');
expect(anyType.serialize(1)).to.eql(1);
expect(anyType.serialize([1, '2'])).to.eql([1, '2']);
expect(anyType.serialize(null)).null();
expect(anyType.serialize(undefined)).undefined();
const date = new Date();
expect(anyType.serialize(date)).to.eql(date.toJSON());
const obj = {x: 1};
expect(anyType.serialize(obj)).to.eql(obj);
const json = {
x: 1,
y: 2,
toJSON() {
return {a: json.x + json.y};
},
};
expect(anyType.serialize(json)).to.eql({a: 3});
it('returns singleton value', () => {
let count = 0;
ctx
.bind('foo')
.toDynamicValue(() => count++)
.inScope(BindingScope.SINGLETON);
let result = ctx.getSync('foo');
expect(result).to.equal(0);
result = ctx.getSync('foo');
expect(result).to.equal(0);
const childCtx = new Context(ctx);
result = childCtx.getSync('foo');
expect(result).to.equal(0);
});
it('adds model metadata with custom name', () => {
@model({name: 'foo'})
class Doohickey {
name: string;
}
const meta = MetadataInspector.getClassMetadata(MODEL_KEY, Doohickey);
expect(meta).to.eql({name: 'foo'});
});
it('injects as values', async () => {
class MyControllerWithValues {
constructor(
@inject(filterByTag('foo'))
public values: string[],
) {}
}
ctx.bind('my-controller').toClass(MyControllerWithValues);
const inst = await ctx.get('my-controller');
expect(inst.values).to.eql(['BAR', 'FOO']);
});
it('clones regexp', () => {
const val = {
re: /Ab/,
};
const copy = DecoratorFactory.cloneDeep(val);
expect(copy.re).to.not.exactly(val.re);
expect(copy).to.be.eql(val);
});
});
function expectSpecToBeEqual(controller: Function, paramSpec: object) {
const actualSpec = getControllerSpec(controller);
expect(actualSpec.paths['/greet/{name}']['get'].parameters).to.eql([
paramSpec,
]);
}