Conversation
Tried adding tests as follows in But I keep getting the following errors: Any idea how to add tests? There are no existing tests covering this flag / the |
|
@virkt25 I think you can provide the model name as string instead of a model constructor to get the tests pass: it('coerces ObjectID', function() {
// note it is 'Book' not Book
const coercedId = db.connector.coerceId('Book', '52fcef5c0325ace8dcb7a0bd');
coercedId.should.be.an.instanceOf(db.ObjectID);
}); |
|
Here is the code throwing the error (assuming your stack trace is from the latest version of loopback-connector as seen on GitHub): Connector.prototype.idName = function(model) {
return this.getDataSource(model).idName(model);
};I strongly suspect that in the test you tried to wrote, there was no model defined on the datasource with the name matching the string you passed to What you need to do in your test:
it('coerces ObjectID', function() {
const Book = db.createModel('Book' /*, {properties...}, {settings...}*/);
const coercedId = db.connector.coerceId(Book.modelName, '52fcef5c0325ace8dcb7a0bd');
coercedId.should.be.an.instanceOf(db.ObjectID);
});I am typing this information from my head, it may not be entirely accurate. Sorry if it does not work out of the box! |
Signed-off-by: virkt25 <taranveer@virk.cc>
Description
loopback4-example-shopping. For relations, we need to be able to enablestrictObjectIDCoercionfor those methods only. This PR allows the flag to be passed in from a method instead of just being set on the model.Related issues
Checklist
guide