Skip to content

Commit

Permalink
Added tests for utilities functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jermnelson committed Sep 19, 2019
1 parent 28813fa commit 0d7e6f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion __tests__/utilities/propertyTemplates.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
defaultValuesFromPropertyTemplate,
getLookupConfigItems,
getTagNameForPropertyTemplate,
} from '../../src/utilities/propertyTemplates'
} from 'utilities/propertyTemplates'

import shortid from 'shortid'

Expand Down
34 changes: 32 additions & 2 deletions __tests__/utilities/qa.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright 2019 Stanford University see LICENSE for license

import { isContext } from 'utilities/qa'

import getSearchResults, { isContext } from 'utilities/qa'

describe('isContext()', () => {
// check context property is picked up and when property is not present, method returns false
Expand All @@ -13,3 +12,34 @@ describe('isContext()', () => {
expect(isContext({})).toBeFalsy()
})
})

describe('getSearchResults()', () => {
const template = {
valueConstraint: {
useValuesFrom: [
'urn:ld4p:qa:agrovoc',
],
},
}

it('returns an array of values from a search', () => {
expect.assertions(1)

return getSearchResults('Corn', template).then((result) => {
expect(result[0].body.length).toEqual(8)
})
})

it('returns a single value using a bad authority source', () => {
const badAuthorityURItemplate = {
valueConstraint: {
useValuesFrom: [
'urn:ld4p:qa:names:organization',
],
},
}
return getSearchResults('Austin, Jane', badAuthorityURItemplate).catch((result) => {
expect(result[0].statusCode).toEqual(400)
})
})
})
3 changes: 2 additions & 1 deletion src/utilities/qa.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Config from 'Config'
const getSearchResults = (query, propertyTemplate) => Swagger({ spec: swaggerSpec })
.then((client) => {
const lookupConfigs = getLookupConfigItems(propertyTemplate)

// Create array of promises based on the lookup config array that is sent in
const lookupPromises = createLookupPromises(client, query, lookupConfigs, isContext(propertyTemplate))

Expand All @@ -34,7 +35,7 @@ const getSearchResults = (query, propertyTemplate) => Swagger({ spec: swaggerSpe

export const isContext = propertyTemplate => propertyTemplate?.subtype === 'context'

const createLookupPromises = (client, query, lookupConfigs, context) => lookupConfigs.map((lookupConfig) => {
export const createLookupPromises = (client, query, lookupConfigs, context) => lookupConfigs.map((lookupConfig) => {
const authority = lookupConfig.authority
const subauthority = lookupConfig.subauthority
const language = lookupConfig.language
Expand Down

0 comments on commit 0d7e6f2

Please sign in to comment.