Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message for updated_at and ttl for IGM #74

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions utils/igm/igmHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,28 @@ export function checkDomainInAll({
logger.error(`Error occurred while checking domain for /${endpoint}_close api, ${error.stack}`)
}
}

export function compareUpdatedAtForRespondantActions({
endpoint,
updated_at,
respondent_actions,
issueReportObj,
}: {
endpoint: string
updated_at: string
respondent_actions: any
issueReportObj: any
}) {
try {
const index = respondent_actions.length - 1
const lastElem = respondent_actions[respondent_actions.length - 1]
logger.info(`Checking 'comparing 'respondant_actions.updated_at' and updated_at' for /${endpoint}`)
if (updated_at != lastElem.updated_at) {
issueReportObj.updated_at = `respondant_actions[${index}].updated_at should match issue's 'updated_at'`
}
} catch (error: any) {
logger.error(
`Error occurred while comparing 'respondant_actions.updated_at' and updated_at for /${endpoint} api, ${error.stack}`,
)
}
}
8 changes: 8 additions & 0 deletions utils/igm/retOnIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
checkOrganizationNameandDomain,
compareContextTimeStampAndUpdatedAt,
compareUpdatedAtAndContextTimeStamp,
compareUpdatedAtForRespondantActions,
} from './igmHelpers'

const checkOnIssue = (data: any) => {
Expand Down Expand Up @@ -137,6 +138,13 @@ const checkOnIssue = (data: any) => {
created_at: on_issue.message.issue.created_at,
issueReportObj: onissueObj,
})

compareUpdatedAtForRespondantActions({
endpoint: constants.RET_ONISSUE,
updated_at: on_issue.message.issue.updated_at,
respondent_actions: respondent_actions,
issueReportObj: onissueObj,
})

checkDomainInAll({ endpoint: constants.RET_ONISSUE, domain: on_issue.context.domain, issueReportObj: onissueObj })

Expand Down
8 changes: 8 additions & 0 deletions utils/igm/retOnIssueStatus(unsolicited).ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
checkOrganizationNameandDomain,
compareContextTimeStampAndUpdatedAt,
compareUpdatedAtAndContextTimeStamp,
compareUpdatedAtForRespondantActions,
} from './igmHelpers'

const checkOnIssueStatusUnsolicited = (data: any) => {
Expand Down Expand Up @@ -153,6 +154,13 @@ const checkOnIssueStatusUnsolicited = (data: any) => {
issueReportObj: onIssueStatusObj,
})

compareUpdatedAtForRespondantActions({
endpoint: constants.RET_ONISSUE,
updated_at: onIssueStatus.message.issue.updated_at,
respondent_actions: respondent_actions,
issueReportObj: onIssueStatusObj,
})

setValue('onIssueStatusObj', onIssueStatusObj)

// setValue("onIssueStatusObj", onIssueStatusObj);
Expand Down
8 changes: 8 additions & 0 deletions utils/igm/retOnIssueStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
checkOrganizationNameandDomain,
compareContextTimeStampAndUpdatedAt,
compareUpdatedAtAndContextTimeStamp,
compareUpdatedAtForRespondantActions,
} from './igmHelpers'

const checkOnIssueStatus = (data: any) => {
Expand Down Expand Up @@ -146,6 +147,13 @@ const checkOnIssueStatus = (data: any) => {
issueReportObj: onIssueStatusObj,
})

compareUpdatedAtForRespondantActions({
endpoint: constants.RET_ONISSUE,
updated_at: onIssueStatus.message.issue.updated_at,
respondent_actions: respondent_actions,
issueReportObj: onIssueStatusObj,
})

compareContextTimeStampAndUpdatedAt({
endpoint: constants.RET_ONISSUE_STATUS,
contextTimeStamp: onIssueStatus.context.timestamp,
Expand Down
44 changes: 26 additions & 18 deletions utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export const checkContext = (
errObj.action_err = `context.action should be ${path}`
}

if ((path === constants.RET_ONISSUE || path === constants.RET_ONISSUE_STATUS) && data.hasOwnProperty('ttl')) {
{
errObj.ttl_err = `Extraneous key ttl at context.ttl as per the API Contract`
}
}

if (data.ttl && data.ttl != constants.RET_CONTEXT_TTL) {
{
errObj.ttl_err = `ttl = ${constants.RET_CONTEXT_TTL} as per the API Contract`
Expand Down Expand Up @@ -864,32 +870,35 @@ export const checkMandatoryTags = (i: string, items: any, errorObj: any, categor
errorObj[key] = `Mandatory tag field [${tagName}] missing for ${categoryName} item[${index}]`
} else {
if (tagInfo.value.length > 0) {
let isValidValue = false;
let regexPattern = ""
let isValidValue = false
let regexPattern = ''

if (Array.isArray(tagInfo.value)) {
isValidValue = tagInfo.value.includes(originalTag) || tagInfo.value.includes(tagValue);
} else if (typeof tagInfo.value === 'string' && tagInfo.value.startsWith('/') && tagInfo.value.endsWith('/')) {
regexPattern = tagInfo.value.slice(1, -1);
const regex = new RegExp(regexPattern);
isValidValue = regex.test(originalTag) || regex.test(tagValue);
isValidValue = tagInfo.value.includes(originalTag) || tagInfo.value.includes(tagValue)
} else if (
typeof tagInfo.value === 'string' &&
tagInfo.value.startsWith('/') &&
tagInfo.value.endsWith('/')
) {
regexPattern = tagInfo.value.slice(1, -1)
const regex = new RegExp(regexPattern)
isValidValue = regex.test(originalTag) || regex.test(tagValue)
}

if (!isValidValue) {
logger.error(`The item value can only be one of the possible values or match the regex pattern.`);
const key = `InvldValueforItem[${i}][${index}] : ${tagName}`;
errorObj[key] = `Invalid item value: [${originalTag}]. It must be one of the allowed values or match the regex pattern [${regexPattern}].`;
logger.error(`The item value can only be one of the possible values or match the regex pattern.`)
const key = `InvldValueforItem[${i}][${index}] : ${tagName}`
errorObj[key] =
`Invalid item value: [${originalTag}]. It must be one of the allowed values or match the regex pattern [${regexPattern}].`
}
}
}
}
}
}
}
else
{
} else {
const key = `invalidCategoryId${ctgrID}`
errorObj[key] = `Invalid category_id (${ctgrID}) for ${categoryName}`
errorObj[key] = `Invalid category_id (${ctgrID}) for ${categoryName}`
}
}
})
Expand Down Expand Up @@ -998,9 +1007,8 @@ export const checkQuoteTrailSum = (fulfillmentArr: any[], price: number, priceAt
}
if (Math.round(priceAtConfirm) != Math.round(price + quoteTrailSum)) {
const key = `invldQuoteTrailPrices`
errorObj[
key
] = `quote_trail price and item quote price sum for ${constants.ON_UPDATE} should be equal to the price as in ${constants.ON_CONFIRM}`
errorObj[key] =
`quote_trail price and item quote price sum for ${constants.ON_UPDATE} should be equal to the price as in ${constants.ON_CONFIRM}`
logger.error(
`quote_trail price and item quote price sum for ${constants.ON_UPDATE} should be equal to the price as in ${constants.ON_CONFIRM} `,
)
Expand Down Expand Up @@ -1190,4 +1198,4 @@ export function compareTimeRanges(data1: any, data2: any): string[] | null {

function isValidTimestamp(timestamp: string): boolean {
return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(timestamp)
}
}