Skip to content

Commit eac7ee0

Browse files
Merge pull request #34 from topcoder-platform/hotfix/patch-1.5.3.1
[PROD] Patch 1.5.3.1
2 parents 387c397 + c7a55dc commit eac7ee0

12 files changed

+443
-32
lines changed

config/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* The default configuration file.
3+
*/
4+
5+
module.exports = {
6+
zapier: {
7+
ZAPIER_SWITCH: process.env.ZAPIER_SWITCH || 'ON',
8+
ZAPIER_JOB_CANDIDATE_SWITCH: process.env.ZAPIER_JOB_CANDIDATE_SWITCH || 'ON'
9+
}
10+
}

package-lock.json

Lines changed: 181 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,21 @@
1010
"create-index": "node src/scripts/createIndex.js",
1111
"delete-index": "node src/scripts/deleteIndex.js",
1212
"view-data": "node src/scripts/view-data.js",
13-
"test": "mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
14-
"test:cov": "nyc --reporter=html --reporter=text mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
15-
"e2e": "mocha test/e2e/test.js --timeout 20000 --exit",
16-
"e2e:cov": "nyc --reporter=html --reporter=text mocha test/e2e/test.js --timeout 20000 --exit"
13+
"test": "cross-env NODE_ENV=test mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
14+
"test:cov": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
15+
"e2e": "cross-env NODE_ENV=test mocha test/e2e/test.js --timeout 20000 --exit",
16+
"e2e:cov": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text mocha test/e2e/test.js --timeout 20000 --exit"
1717
},
1818
"author": "TCSCODER",
1919
"license": "none",
2020
"devDependencies": {
21+
"cross-env": "^7.0.3",
2122
"mocha": "^7.1.2",
2223
"mocha-prepare": "^0.1.0",
2324
"nock": "^12.0.3",
2425
"nyc": "^14.1.1",
2526
"should": "^13.2.3",
27+
"sinon": "^10.0.1",
2628
"standard": "^12.0.1",
2729
"stringcase": "^4.3.1",
2830
"superagent": "^5.1.0"

src/bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ global.Promise = require('bluebird')
66

77
Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly')
88
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
9-
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled', 'interview')
9+
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled', 'interview', 'topcoder-rejected')
1010
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
1111
Joi.title = () => Joi.string().max(128)
1212
// Empty string is not allowed by Joi by default and must be enabled with allow('').

src/common/helper.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ function getESClient () {
109109
}
110110
}
111111

112+
// get document or catch not found error
113+
esClient.getExtra = async function (data) {
114+
let doc
115+
116+
try {
117+
doc = await esClient.getSource(data)
118+
} catch (err) {
119+
if (err.statusCode === 404) {
120+
throw new Error(`id: ${data.id} "${data.index}" not found`)
121+
}
122+
throw err
123+
}
124+
125+
return doc
126+
}
127+
112128
// delete document or catch not found error
113129
esClient.deleteExtra = async function (data) {
114130
try {

src/services/JobCandidateProcessorService.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const localLogger = {
2020
* @param {Object} message the message object
2121
* @returns {undefined}
2222
*/
23-
async function updateCandidateStatus ({ type, payload }) {
24-
if (!payload.status) {
25-
localLogger.debug({ context: 'updateCandidateStatus', message: 'status not updated' })
23+
async function updateCandidateStatus ({ type, payload, previousData }) {
24+
if (previousData.status === payload.status) {
25+
localLogger.debug({ context: 'updateCandidateStatus', message: `jobCandidate is already in status: ${payload.status}` })
2626
return
2727
}
2828
if (!['rejected', 'shortlist'].includes(payload.status)) {
@@ -56,13 +56,13 @@ async function updateCandidateStatus ({ type, payload }) {
5656
* @param {Object} message the message object
5757
* @returns {undefined}
5858
*/
59-
async function postMessageToZapier ({ type, payload }) {
59+
async function postMessageToZapier ({ type, payload, previousData }) {
6060
if (config.zapier.ZAPIER_JOB_CANDIDATE_SWITCH === constants.Zapier.Switch.OFF) {
6161
localLogger.debug({ context: 'postMessageToZapier', message: 'Zapier Switch off via config, no messages sent' })
6262
return
6363
}
6464
if (type === constants.Zapier.MessageType.JobCandidateUpdate) {
65-
await updateCandidateStatus({ type, payload })
65+
await updateCandidateStatus({ type, payload, previousData })
6666
return
6767
}
6868
throw new Error(`unrecognized message type: ${type}`)
@@ -113,6 +113,12 @@ processCreate.schema = {
113113
*/
114114
async function processUpdate (message, transactionId) {
115115
const data = message.payload
116+
// save previous data for Zapier logic
117+
// NOTE: ideally if we update Kafka event message to have both: pervious and updated value so we don't have to request it again
118+
const { body: previousData } = await esClient.getExtra({
119+
index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
120+
id: data.id
121+
})
116122
await esClient.updateExtra({
117123
index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
118124
id: data.id,
@@ -124,7 +130,8 @@ async function processUpdate (message, transactionId) {
124130
})
125131
await postMessageToZapier({
126132
type: constants.Zapier.MessageType.JobCandidateUpdate,
127-
payload: data
133+
payload: data,
134+
previousData
128135
})
129136
}
130137

0 commit comments

Comments
 (0)