Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
map(element => {
if (isArray(element)) {
// Only add prefix if no media type is declared
if (arrayContainsMediaType(element)) {
return element
}
return [defaultMediaType, ...element]
}
if (containsMediaType(element)) {
return element
}
return joinAnd([defaultMediaType, element])
})(elements)
private async validateData (functionBindings: ICheckMarkerFunctionBindings, validatedCheck: ReceivedCheckTableEntity, logger: ILogger): Promise {
if (RA.isNilOrEmpty(validatedCheck.answers)) {
await this.updateReceivedCheckWithMarkingError(validatedCheck, 'answers property not populated')
return
}
let parsedAnswersJson: any
try {
// tsc does not recognise the RA.IsNilOrEmpty check above
// therefore we use the exclamanation to assert non null guarantee
parsedAnswersJson = JSON.parse(validatedCheck.answers!)
} catch (error) {
logger.error(error)
return this.updateReceivedCheckWithMarkingError(validatedCheck, 'answers data is not valid JSON')
}
if (!RA.isArray(parsedAnswersJson)) {
return this.updateReceivedCheckWithMarkingError(validatedCheck, 'answers data is not an array')
}
const checkCode = validatedCheck.RowKey
let rawCheckForm
try {
rawCheckForm = await this.sqlService.getCheckFormDataByCheckCode(checkCode)
} catch (error) {
logger.error(error)
return this.updateReceivedCheckWithMarkingError(validatedCheck, `checkForm lookup failed:${error.message}`)
}
if (R.isNil(rawCheckForm)) {
return this.updateReceivedCheckWithMarkingError(validatedCheck, 'associated checkForm could not be found by checkCode')
}
test('supplied parameters are applied to the query', async () => {
const schoolId = 1
const params = [
{
name: 'schoolId',
value: schoolId,
type: mssql.Int
}
]
const sql = 'SELECT TOP 1 * FROM [mtc_admin].school WHERE id=@schoolId'
const result = await sut.query(sql, params)
expect(result).toBeDefined()
expect(RA.isArray(result)).toBe(true)
expect(result.length).toBe(1)
const school = result[0]
expect(RA.isObj(school)).toBe(true)
expect(school.id).toEqual(schoolId)
})
it('returns an empty array if no anomalies were found', () => {
const r = detectInputAfterTheTimerHasCompleted({})
expect(RA.isArray(r)).toBe(true)
})
anomalyData.forEach(data => {
if (RA.isArray(data)) {
data.forEach(innerData => {
checkProcessingService.writeCsv(inputStream, anomalyCsvStream, innerData)
})
} else {
checkProcessingService.writeCsv(inputStream, anomalyCsvStream, data)
}
})
meta.processCount += 1
export const arrayify = input => isArray(input) ? input : [input];
input: '',
eventType: '',
clientTimestamp: '',
question: '4x2',
sequenceNumber: 1
},
{
input: '',
eventType: '',
clientTimestamp: '',
question: '4x2',
sequenceNumber: 2
}
]
)
expect(RA.isArray(r)).toBe(true)
expect(r.length).toBe(1)
})
})