Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
regularComment.load('author').then(function() {
var regularResult = regularComment.toJSON();
expect(regularResult).to.eql({
id: '8dc1464d-8c32-448d-a81d-ff161077d781',
author_id: '3fe94198-7b32-44ee-abdd-04104b902c51',
author: {},
content: 'Hello, World!'
});
tracker.uninstall();
tracker = mockKnex.getTracker();
tracker.install();
configureTracker(tracker);
Comment.forge({ id: '8dc1464d-8c32-448d-a81d-ff161077d781' }, {
accessor: { user: { id: stubs.users.elephant1.id } }
})
.fetch()
.then(function(comment) {
comment.load('author').then(function() {
var author = comment.related('author'); // Need to call this because
// .related() is what transfers model._accessor to the relation
comment.toJSON().then(function(result) {
expect(result).to.eql({
id: '8dc1464d-8c32-448d-a81d-ff161077d781',
author: null,
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
const assert = require("assert");
const should = require("should");
const rewire = require("rewire");
const mockKnex = require("mock-knex");
const tracker = mockKnex.getTracker();
const { ModelBase, registerModel } = require("../app/models/base");
class TempModel extends ModelBase {}
registerModel(TempModel, {
hasTimestamps: true
});
describe("app/models/base.js", function() {
beforeEach(function(done) {
tracker.install();
done();
});
afterEach(function(done) {
};
var expectedJsonWithoutPivot = {
id: 1,
name: 'bert',
classesTeacherOf: [{
id: 2,
name: 'history'
}]
};
// Establish regular, unplugged-in Bookshelf behavior
regularBookshelf.model('Teacher', regularBookshelf.Model.extend(teachersModelDefinition, {}));
regularBookshelf.model('Class', regularBookshelf.Model.extend(classesModelDefinition, {}));
var tracker = mockKnex.getTracker();
tracker.install();
tracker.on('query', mock);
regularBookshelf.model('Teacher').forge({ name: 'bert' })
.fetch()
.then(function(model) {
return model.load('classesTeacherOf').then(function() {
var regularJson = model.toJSON();
expect(regularJson).to.eql(expectedJsonWithPivot);
var regularJsonOmitPivot = model.toJSON({ omitPivot: true });
expect(regularJsonOmitPivot).to.eql(expectedJsonWithoutPivot);
tracker.uninstall();
});
describe('fetchAll', function() {
var tracker = mockKnex.getTracker();
before(function() {
tracker.install();
tracker.on('query', function sendResult(query) {
query.response([
stubs.users.elephant1,
stubs.users.antelope99
]);
});
});
after(function() {
tracker.uninstall();
});
it('should set _accessor on all models in a collection fetched via fetchAll', function(done) {
var user = User.forge({}, { accessor: { user: 'foo' }});
user.fetchAll().then(function(collection) {
expect(collection.length).to.equal(2);
var configureTracker = function(tracker) {
tracker.on('query', function sendResult(query, step) {
[
function() {
query.response([
stubs.comments[0]
]);
},
function() {
query.response([]);
}
][step - 1]();
});
};
var tracker = mockKnex.getTracker();
tracker.install();
configureTracker(tracker);
RegularComment.forge({ id: '8dc1464d-8c32-448d-a81d-ff161077d781' }, {
accessor: { user: { id: stubs.users.elephant1.id } }
})
.fetch()
.then(function(regularComment) {
regularComment.load('author').then(function() {
var regularResult = regularComment.toJSON();
expect(regularResult).to.eql({
id: '8dc1464d-8c32-448d-a81d-ff161077d781',
author_id: '3fe94198-7b32-44ee-abdd-04104b902c51',
author: {},
content: 'Hello, World!'
});
'use strict';
const config = {
"client": "mysql",
debug: false
};
const knex = require('knex');
const mockKnex = require('mock-knex');
const tracker = mockKnex.getTracker();
const connection = knex(config);
mockKnex.mock(connection);
const bookshelf = require('bookshelf')(connection);
const models = require('./../common/models')(bookshelf);
const graphQLSchema = require('./../common/schema')(models);
const sinon = require('sinon');
before(function(done) {
this.sandbox = sinon.sandbox.create();
this.sandbox.graphQLSchema = graphQLSchema;
this.sandbox.tracker = tracker;
done();
});
import knex = require("knex");
import * as mockDb from "mock-knex";
const db = knex({
client: 'sqlite'
});
mockDb.mock(db);
const tracker = mockDb.getTracker();
tracker.install();
tracker.on('query', (query, step) => {
if (query.method === "first" || step === 1) {
query.response([{
a: 1
}, {
a: 2
}, {
a: 3
}], {
stream: false
});
} else {
query.reject(new Error("bad query"));
}
});