-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mocha tests for the parameter building functions for solr and n…
…amed queries inside the vocab service. Added a feature to expose all service methods when in mocha testing mode
- Loading branch information
1 parent
d7c32f6
commit 9fea34e
Showing
4 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
|
||
|
||
describe('The VocabService', function () { | ||
before(function (done) { | ||
done(); | ||
}); | ||
|
||
|
||
it('Build a named query parameter map that includes both the search string and logged in user attributes', function (done) { | ||
const user = { | ||
id: 1, | ||
username: 'testuser', | ||
email: '[email protected]', | ||
roles: ['Guest','Researcher','Admin']}; | ||
|
||
const queryConfig = { | ||
querySource: 'database', | ||
databaseQuery: 'test', | ||
queryField: { | ||
property: 'title', | ||
type: 'string' | ||
}, | ||
userQueryFields: [ | ||
{ | ||
property: 'userEmail', | ||
userValueProperty: 'email' | ||
}, | ||
{ | ||
property: 'userRole', | ||
userValueProperty: 'roles' | ||
} | ||
] | ||
} | ||
|
||
const queryParamMap = VocabService.buildNamedQueryParamMap(queryConfig, 'test', user); | ||
expect(queryParamMap).to.be.an('object'); | ||
expect(queryParamMap).to.have.property('userEmail'); | ||
expect(queryParamMap.userEmail).to.equal(user.email); | ||
expect(queryParamMap).to.have.property('userRole'); | ||
expect(queryParamMap.userRole).to.equal(user.roles); | ||
|
||
done(); | ||
}); | ||
|
||
it('Build a solr query that includes both the search string and logged in user attributes', function (done) { | ||
const user = { | ||
id: 1, | ||
username: 'testuser', | ||
email: '[email protected]', | ||
roles: ['Guest','Researcher','Admin']}; | ||
|
||
const queryConfig = { | ||
querySource: 'solr', | ||
searchQuery:{ | ||
baseQuery: 'metaMetadata_type:rdmp' | ||
}, | ||
queryField: { | ||
property: 'title', | ||
type: 'text' | ||
}, | ||
userQueryFields: [ | ||
{ | ||
property: 'userEmail', | ||
userValueProperty: 'email' | ||
}, | ||
{ | ||
property: 'userRole', | ||
userValueProperty: 'roles' | ||
} | ||
] | ||
} | ||
const brand ={ | ||
id: "1" | ||
} | ||
|
||
const solrQuery = VocabService.buildSolrParams(brand, 'test',queryConfig, 1, 1, 'json', user); | ||
expect(solrQuery).to.equal('metaMetadata_type:rdmp&sort=date_object_modified desc&version=2.2&start=1&rows=1&fq=metaMetadata_brandId:1&wt=json&fq=title:test*&fq=userEmail:[email protected]&fq=userRole:Guest,Researcher,Admin'); | ||
done(); | ||
}); | ||
|
||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters