Skip to content

Commit ef40b7c

Browse files
committed
Specified collection select working
1 parent f67342d commit ef40b7c

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

test/api/API-Spec.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,6 @@ describe('API tests', function() {
837837
fng.searchAll()(mockReq, mockRes);
838838
});
839839

840-
841840
it('should support searchResultFormat option', function(done) {
842841
var mockReq = {
843842
url: '/search',
@@ -861,6 +860,57 @@ describe('API tests', function() {
861860
};
862861
fng.searchAll()(mockReq, mockRes);
863862
});
863+
864+
it('will select from a given collection if specified', (done) => {
865+
const mockReq = {
866+
url: '/search',
867+
query: {
868+
q: 'f_nested_schema:a'
869+
},
870+
route: { path: '/api/search' }
871+
};
872+
const mockRes = {
873+
status: function(code) {
874+
assert.strictEqual(code, 200);
875+
return this;
876+
},
877+
send: function(data) {
878+
assert.equal(data.results.length, 1);
879+
assert.equal(data.results[0].resourceText, 'Exams');
880+
assert.equal(data.results[0].resource, 'f_nested_schema');
881+
assert.equal(data.results[0].text, 'Smith, Anne');
882+
done();
883+
}
884+
};
885+
fng.searchAll()(mockReq, mockRes);
886+
});
887+
888+
it.only('will select from a synonym collection if specified', (done) => {
889+
const mockReq = {
890+
url: '/search',
891+
query: {
892+
q: 'Exams:a'
893+
},
894+
route: { path: '/api/search' }
895+
};
896+
const mockRes = {
897+
status: function(code) {
898+
assert.strictEqual(code, 200);
899+
return this;
900+
},
901+
send: function(data) {
902+
assert.equal(data.results.length, 1);
903+
assert.equal(data.results[0].resourceText, ' ');
904+
assert.equal(data.results[0].resource, 'f_nested_schema');
905+
assert.equal(data.results[0].text, 'Smith, Anne');
906+
done();
907+
}
908+
};
909+
fng.searchAll()(mockReq, mockRes);
910+
});
911+
912+
it('will select from a filtered synonym collection if specified');
913+
864914
});
865915

866916
describe('MongoDB selection', function() {

test/api/models/f_nested_schema.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ FSchema.statics.form = function (layout) {
8484

8585
module.exports = {
8686
model: F,
87-
searchResultFormat: F.prototype.searchResultFormat
87+
options : {
88+
synonyms: [{name: 'Exams'}],
89+
searchResultFormat: F.prototype.searchResultFormat
90+
}
8891
};
8992

9093

test/helpers/db-helpers.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { FormsAngular } from "../../src/server/data_form";
22
const express = require("express");
3-
const async = require("async");
3+
const asyncLib = require("async");
44
const path = require("path");
55
const fs = require("fs");
66
const exec = require("child_process").exec;
@@ -25,31 +25,36 @@ module.exports = {
2525
// Import test data
2626
const dataPath = path.join(__dirname, "../api/data");
2727
fs.readdir(dataPath, function(err, files) {
28-
async.each(files, function(file, cb2) {
28+
29+
function importData(file, cb2) {
2930
const fname = dataPath + "/" + file;
3031
if (fs.statSync(fname).isFile()) {
31-
const command = "mongoimport --db forms-ng_test --drop --collection " + file.slice(0, 1) + "s --jsonArray < " + fname; exec(command, function(error, stdout, stderr) {
32+
const command = "mongoimport --db forms-ng_test --drop --collection " + file.slice(0, 1) + "s --jsonArray < " + fname;
33+
exec(command, function(error, stdout, stderr) {
3234
if (error !== null) {
3335
cb2(new Error("Error executing " + command + " : " + error + " (Code = " + error.code + " " + error.signal + ") : " + stderr + " : " + stdout));
3436
} else {
3537
cb2();
3638
}
3739
});
3840
}
39-
}, function(err) {
41+
}
42+
43+
asyncLib.each(files, importData, function(err) {
4044
if (err) {
4145
throw new Error(err);
4246
} else {
4347
// Bootstrap models
4448
const modelsPath = path.join(__dirname, "../api/models");
4549
fs.readdir(modelsPath, function(err, files) {
46-
async.each(files, function(file, cb2) {
50+
function addAResource(file, cb3) {
4751
const fname = modelsPath + "/" + file;
4852
if (fs.statSync(fname).isFile()) {
4953
fng.addResource(file.slice(0, -3), require(fname), { suppressDeprecatedMessage: true });
5054
}
51-
cb2();
52-
}, function(err) {
55+
cb3();
56+
}
57+
asyncLib.each(files, addAResource, function(err) {
5358
if (err) {
5459
throw new Error(err);
5560
} else {

0 commit comments

Comments
 (0)