Skip to content

Commit

Permalink
revert changes in search.js, format cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LocalNewsTV committed Oct 6, 2023
1 parent 04e1a13 commit 9d610fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
18 changes: 9 additions & 9 deletions api/src/controllers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,23 +355,23 @@ let searchCollection = async function (
pageNum,
pageSize,
project,
sortField = undefined,
sortDirection = undefined,
caseSensitive,
populate = false,
and,
or,
nor,
subset,
_in,
populate = false,
sortField = undefined,
sortDirection = undefined,
_in
) {
let properties;
let properties = undefined;
if (project) {
properties = { project: mongoose.Types.ObjectId(project) };
}

// optional search keys
let searchProperties;
let searchProperties = undefined;
if (keywords) {
// for now, limit fuzzy search to the mine search only. We can expand to all searches
// later if desired
Expand All @@ -389,7 +389,7 @@ let searchCollection = async function (
let hasCollection = null;
if (or && Object.prototype.hasOwnProperty.call(or, 'hasCollection')) {
hasCollectionTest = true;
hasCollection = or.hasCollection === 'true';
hasCollection = or.hasCollection === 'true' ? true : false;
delete or.hasCollection;
}

Expand Down Expand Up @@ -516,7 +516,7 @@ let searchCollection = async function (
// to finalize the facet
searchResultAggregation.push({
$lookup: {
from: subset && subset?.includes('redactedRecord') ? 'redacted_record_subset' : 'nrpti',
from: subset && subset.includes('redactedRecord') ? 'redacted_record_subset' : 'nrpti',
localField: '_id',
foreignField: '_id',
as: 'fullRecord'
Expand Down Expand Up @@ -758,7 +758,7 @@ const executeQuery = async function (args, res, next) {
let or = args.swagger.params.or ? args.swagger.params.or.value : '';
let nor = args.swagger.params.nor ? args.swagger.params.nor.value : '';
let _in = args.swagger.params._in ? args.swagger.params._in.value : '';
let subset = args.swagger.params.subset ? args.swagger.params.subset.value : [];
let subset = args.swagger.params.subset ? args.swagger.params.subset.value : null;
defaultLog.info('Searching keywords:', keywords);
defaultLog.info('Searching datasets:', dataset);
defaultLog.info('Searching project:', project);
Expand Down
36 changes: 19 additions & 17 deletions api/test/tests/controllers/search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let generated_Company;
describe('Search Controller Testing', () => {
const testUser = 'testUser';

beforeAll( async () => {
beforeAll(async () => {
generated_things = await generate_helper.generateSingleFactory(
'Order',
5,
Expand All @@ -47,12 +47,12 @@ describe('Search Controller Testing', () => {
{},
{ genAdult: true }
),
generated_Company = await generate_helper.generateSingleFactory(
'Order',
2,
{ },
{ genCompany: true }
)
generated_Company = await generate_helper.generateSingleFactory(
'Order',
2,
{},
{ genCompany: true }
)
});

test('Invalid ObjectId returns 400 error', async (done) => {
Expand Down Expand Up @@ -89,7 +89,7 @@ describe('Search Controller Testing', () => {

request(app)
.get(searchEndpoint)
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId}))
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId }))
.expect(200)
.expect('Content-Type', 'application/json')
.end((err, res) => {
Expand All @@ -114,7 +114,7 @@ describe('Search Controller Testing', () => {

request(app)
.get(searchEndpoint)
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true}))
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true }))
.expect(200)
.expect('Content-Type', 'application/json')
.end((err, res) => {
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('Search Controller Testing', () => {

request(app)
.get(searchEndpoint)
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true}))
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true }))
.expect(200)
.expect('Content-Type', 'application/json')
.end((err, res) => {
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('Search Controller Testing', () => {

request(app)
.get(searchEndpoint)
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true}))
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true }))
.expect(200)
.expect('Content-Type', 'application/json')
.end((err, res) => {
Expand All @@ -200,6 +200,8 @@ describe('Search Controller Testing', () => {
const roles = ['admin:nrced'];
const orderId = generated_Company[0]._id.toString();
const expected = generated_Company[0];
const redactExpectation = 'Unpublished';

app.get(searchEndpoint, (req, res) => {
const params = test_util.buildParams(req.query)
const paramsWithValues = test_util.createSwaggerParams(params, roles, testUser);
Expand All @@ -208,7 +210,7 @@ describe('Search Controller Testing', () => {

request(app)
.get(searchEndpoint)
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true}))
.query(qs.stringify({ dataset: ['Item'], _schemaName: 'Order', _id: orderId, populate: true }))
.expect(200)
.expect('Content-Type', 'application/json')
.end((err, res) => {
Expand All @@ -221,16 +223,16 @@ describe('Search Controller Testing', () => {
expect(record._id).toMatch(orderId)
expect(record.issuedTo.type).toBe(CONSTANTS.IssuedToEntityTypes.Company)
expect(record.issuedTo.companyName).toBe(expected.issuedTo.companyName)
expect(record.issuedTo.firstName).toBe('')
expect(record.issuedTo.lastName).toBe('')
expect(record.issuedTo.fullName).toBe('')
expect(record.issuedTo.firstName).toBe(redactExpectation || '')
expect(record.issuedTo.lastName).toBe(redactExpectation || '')
expect(record.issuedTo.fullName).toBe(redactExpectation || '')
expect(record.issuedTo.dateOfBirth).toBeFalsy()
return done();
})
})

test('Lookup by dataset returns items', async (done) => {
const roles = ['sysadmin','admin:nrced'];
const roles = ['sysadmin', 'admin:nrced'];
app.get(searchEndpoint, (req, res) => {
const params = test_util.buildParams(req.query)
const paramsWithValues = test_util.createSwaggerParams(params, roles, testUser);
Expand All @@ -239,7 +241,7 @@ describe('Search Controller Testing', () => {

request(app)
.get(searchEndpoint)
.query({ dataset: ['Order','Inspection']})
.query({ dataset: ['Order', 'Inspection'] })
.expect(200)
.expect('Content-Type', 'application/json')
.end((err, res) => {
Expand Down

0 comments on commit 9d610fa

Please sign in to comment.