Skip to content

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dcrockwell committed Nov 14, 2015
2 parents ac7a25a + 497b346 commit 1ad146c
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 20 deletions.
5 changes: 0 additions & 5 deletions es5/lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ var Database = (function () {
get: function get() {
return new _mockQueryJs2["default"](this);
}
}, {
key: "spy",
get: function get() {
return new _mockQueryJs2["default"](this);
}
}]);

return Database;
Expand Down
9 changes: 8 additions & 1 deletion es5/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,12 @@ var Query = (function () {
value: function value(mockQueries, callback) {
var mockFound = false;
var results = undefined;
var query = undefined;

for (var index in mockQueries) {
var mockQuery = mockQueries[index];

var query = mockQuery.query;
query = mockQuery.query;

results = mockQuery.results;

Expand All @@ -366,6 +367,7 @@ var Query = (function () {
}

if (mockFound) {
query.call;
callback(undefined, results);
} else {
throw new Error("No mock values available for: \"" + this.toString() + "\"", null);
Expand All @@ -381,6 +383,11 @@ var Query = (function () {
get: function get() {
return this.calls > 0;
}
}, {
key: "call",
get: function get() {
(0, _incognito2["default"])(this).calls += 1;
}
}, {
key: "delete",
get: function get() {
Expand Down
36 changes: 36 additions & 0 deletions es5/spec/database/mock.results.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"use strict";

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var _libDatabaseJs = require("../../lib/database.js");

var _libDatabaseJs2 = _interopRequireDefault(_libDatabaseJs);

var databaseConfig = require("../../../database.json").testing;

describe(".mock.results(mockResults)", function () {
var database = undefined;

beforeEach(function () {
database = new _libDatabaseJs2["default"](databaseConfig);
});

it("should return the mock query", function () {
var mockQuery = database.mock;
mockQuery.select("*").from("users").should.equal(mockQuery);
});

it("should increment the call count when subsequent matching queries are executed", function (done) {
var user = {
id: "cigyn1qip0000nxz84cv3bwu6",
name: "Bob"
};

var mockQuery = database.mock.select("*").from("users").results(user);

database.select("*").from("users").results(function () {
mockQuery.called.should.be["true"];
done();
});
});
});
9 changes: 6 additions & 3 deletions es5/spec/database/mock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ var _libDatabaseJs = require("../../lib/database.js");

var _libDatabaseJs2 = _interopRequireDefault(_libDatabaseJs);

var _libMockQueryJs = require("../../lib/mockQuery.js");

var _libMockQueryJs2 = _interopRequireDefault(_libMockQueryJs);

var databaseConfig = require("../../../database.json").testing;

describe(".mock", function () {

var database = undefined;

beforeEach(function () {
database = new _libDatabaseJs2["default"](databaseConfig);
});

it("should return an instance of itself for chaining", function () {
database.mock.should.eql(database);
it("should return an instance of MockQuery", function () {
database.mock.should.be.instanceOf(_libMockQueryJs2["default"]);
});
});
1 change: 0 additions & 1 deletion es5/spec/database/query/results.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var _libDatabaseJs2 = _interopRequireDefault(_libDatabaseJs);
var databaseConfig = require("../../../../database.json").testing;

describe("query.results(callback)", function () {

var database = undefined;
var query = undefined;

Expand Down
4 changes: 0 additions & 4 deletions es6/lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ export default class Database {
return new MockQuery(this);
}

get spy() {
return new MockQuery(this);
}

// unmock() {
// this.mockQueries = undefined;
// }
Expand Down
8 changes: 7 additions & 1 deletion es6/lib/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export default class Query {
return this.calls > 0;
}

get call() {
privateData(this).calls += 1;
}

select(...columns) {
privateData(this).query = privateData(this).knex.select(...columns);
this[addChain]("select", columns);
Expand Down Expand Up @@ -272,11 +276,12 @@ export default class Query {
[mockExecute](mockQueries, callback) {
let mockFound = false;
let results;
let query;

for (let index in mockQueries) {
const mockQuery = mockQueries[index];

const query = mockQuery.query;
query = mockQuery.query;

results = mockQuery.results;

Expand All @@ -287,6 +292,7 @@ export default class Query {
}

if (mockFound) {
query.call;
callback(undefined, results);
} else {
throw new Error(`No mock values available for: "${this.toString()}"`, null);
Expand Down
36 changes: 36 additions & 0 deletions es6/spec/database/mock.results.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import Database from "../../lib/database.js";

const databaseConfig = require("../../../database.json").testing;

describe(".mock.results(mockResults)", () => {
let database;

beforeEach(() => {
database = new Database(databaseConfig);
});

it("should return the mock query", () => {
const mockQuery = database.mock;
mockQuery.select("*").from("users").should.equal(mockQuery);
});

it("should increment the call count when subsequent matching queries are executed", done => {
const user = {
id: "cigyn1qip0000nxz84cv3bwu6",
name: "Bob"
};

const mockQuery = database.mock
.select("*")
.from("users")
.results(user);

database
.select("*")
.from("users")
.results(() => {
mockQuery.called.should.be.true;
done();
});
});
});
6 changes: 3 additions & 3 deletions es6/spec/database/mock.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import Database from "../../lib/database.js";
import MockQuery from "../../lib/mockQuery.js";

const databaseConfig = require("../../../database.json").testing;

describe(".mock", () => {

let database;

beforeEach(() => {
database = new Database(databaseConfig);
});

it("should return an instance of itself for chaining", () => {
database.mock.should.eql(database);
it("should return an instance of MockQuery", () => {
database.mock.should.be.instanceOf(MockQuery);
});
});
1 change: 0 additions & 1 deletion es6/spec/database/query/results.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Database from "../../../lib/database.js";
const databaseConfig = require("../../../../database.json").testing;

describe("query.results(callback)", () => {

let database;
let query;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "almaden",
"version": "0.3.0",
"version": "0.3.1",
"description": "ES6 data adapter.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 1ad146c

Please sign in to comment.