Skip to content

[DEV] Patch 1.5.3.1 #33

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

Merged
merged 4 commits into from
Apr 9, 2021
Merged
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
10 changes: 10 additions & 0 deletions config/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* The default configuration file.
*/

module.exports = {
zapier: {
ZAPIER_SWITCH: process.env.ZAPIER_SWITCH || 'ON',
ZAPIER_JOB_CANDIDATE_SWITCH: process.env.ZAPIER_JOB_CANDIDATE_SWITCH || 'ON'
}
}
181 changes: 181 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
"create-index": "node src/scripts/createIndex.js",
"delete-index": "node src/scripts/deleteIndex.js",
"view-data": "node src/scripts/view-data.js",
"test": "mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
"test:cov": "nyc --reporter=html --reporter=text mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
"e2e": "mocha test/e2e/test.js --timeout 20000 --exit",
"e2e:cov": "nyc --reporter=html --reporter=text mocha test/e2e/test.js --timeout 20000 --exit"
"test": "cross-env NODE_ENV=test mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
"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",
"e2e": "cross-env NODE_ENV=test mocha test/e2e/test.js --timeout 20000 --exit",
"e2e:cov": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text mocha test/e2e/test.js --timeout 20000 --exit"
},
"author": "TCSCODER",
"license": "none",
"devDependencies": {
"cross-env": "^7.0.3",
"mocha": "^7.1.2",
"mocha-prepare": "^0.1.0",
"nock": "^12.0.3",
"nyc": "^14.1.1",
"should": "^13.2.3",
"sinon": "^10.0.1",
"standard": "^12.0.1",
"stringcase": "^4.3.1",
"superagent": "^5.1.0"
Expand Down
16 changes: 16 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ function getESClient () {
}
}

// get document or catch not found error
esClient.getExtra = async function (data) {
let doc

try {
doc = await esClient.getSource(data)
} catch (err) {
if (err.statusCode === 404) {
throw new Error(`id: ${data.id} "${data.index}" not found`)
}
throw err
}

return doc
}

// delete document or catch not found error
esClient.deleteExtra = async function (data) {
try {
Expand Down
19 changes: 13 additions & 6 deletions src/services/JobCandidateProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const localLogger = {
* @param {Object} message the message object
* @returns {undefined}
*/
async function updateCandidateStatus ({ type, payload }) {
if (!payload.status) {
localLogger.debug({ context: 'updateCandidateStatus', message: 'status not updated' })
async function updateCandidateStatus ({ type, payload, previousData }) {
if (previousData.status === payload.status) {
localLogger.debug({ context: 'updateCandidateStatus', message: `jobCandidate is already in status: ${payload.status}` })
return
}
if (!['rejected', 'shortlist'].includes(payload.status)) {
Expand Down Expand Up @@ -56,13 +56,13 @@ async function updateCandidateStatus ({ type, payload }) {
* @param {Object} message the message object
* @returns {undefined}
*/
async function postMessageToZapier ({ type, payload }) {
async function postMessageToZapier ({ type, payload, previousData }) {
if (config.zapier.ZAPIER_JOB_CANDIDATE_SWITCH === constants.Zapier.Switch.OFF) {
localLogger.debug({ context: 'postMessageToZapier', message: 'Zapier Switch off via config, no messages sent' })
return
}
if (type === constants.Zapier.MessageType.JobCandidateUpdate) {
await updateCandidateStatus({ type, payload })
await updateCandidateStatus({ type, payload, previousData })
return
}
throw new Error(`unrecognized message type: ${type}`)
Expand Down Expand Up @@ -113,6 +113,12 @@ processCreate.schema = {
*/
async function processUpdate (message, transactionId) {
const data = message.payload
// save previous data for Zapier logic
// NOTE: ideally if we update Kafka event message to have both: pervious and updated value so we don't have to request it again
const { body: previousData } = await esClient.getExtra({
index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
id: data.id
})
await esClient.updateExtra({
index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
id: data.id,
Expand All @@ -124,7 +130,8 @@ async function processUpdate (message, transactionId) {
})
await postMessageToZapier({
type: constants.Zapier.MessageType.JobCandidateUpdate,
payload: data
payload: data,
previousData
})
}

Expand Down
11 changes: 5 additions & 6 deletions test/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

const config = require('config')
const _ = require('lodash')
const stringcase = require('stringcase')
const app = require('../../src/app')
const request = require('superagent')
Expand Down Expand Up @@ -89,14 +88,14 @@ describe('Taas ES Processor E2E Test', () => {
index,
id: testData.messages[model].create.message.payload.id
})
should.deepEqual(doc.body._source, _.omit(testData.messages[model].create.message.payload, ['id']))
should.deepEqual(doc.body._source, testData.messages[model].create.message.payload, ['id'])
})

it(`Should handle ${modelInSpaceCase} updating message`, async () => {
await testHelper.esClient.create({
index,
id: testData.messages[model].create.message.payload.id,
body: _.omit(testData.messages[model].create.message.payload, ['id']),
body: testData.messages[model].create.message.payload,
refresh: 'true'
})
await testHelper.sendMessage(testData.messages[model].update.message)
Expand All @@ -105,14 +104,14 @@ describe('Taas ES Processor E2E Test', () => {
index,
id: testData.messages[model].update.message.payload.id
})
should.deepEqual(_.omit(doc.body._source, ['createdAt', 'createdBy']), _.omit(testData.messages[model].update.message.payload, ['id']))
should.deepEqual(doc.body._source, testData.messages[model].update.message.payload)
})

it(`Should handle ${modelInSpaceCase} deletion message`, async () => {
await testHelper.esClient.create({
index,
id: testData.messages[model].create.message.payload.id,
body: _.omit(testData.messages[model].create.message.payload, ['id']),
body: testData.messages[model].create.message.payload,
refresh: 'true'
})
await testHelper.sendMessage(testData.messages[model].delete.message)
Expand All @@ -133,7 +132,7 @@ describe('Taas ES Processor E2E Test', () => {
await testHelper.esClient.create({
index,
id: testData.messages[model].create.message.payload.id,
body: _.omit(testData.messages[model].create.message.payload, ['id']),
body: testData.messages[model].create.message.payload,
refresh: 'true'
})
await testHelper.sendMessage(testData.messages[model].create.message)
Expand Down
2 changes: 1 addition & 1 deletion test/messages/taas.job.create.event.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"topic":"taas.job.create","originator":"taas-api","timestamp":"2020-11-05T19:00:17.563Z","mime-type":"application/json","payload":{"projectId":21,"externalId":"1212","description":"Dummy Description","startDate":"2020-09-27T04:17:23.131Z","endDate":"2020-09-27T04:17:23.131Z","numPositions":13,"resourceType":"Dummy Resource Type","rateType":"hourly","skills":["56fdc405-eccc-4189-9e83-c78abf844f50","f91ae184-aba2-4485-a8cb-9336988c05ab","edfc7b4f-636f-44bd-96fc-949ffc58e38b","4ca63bb6-f515-4ab0-a6bc-c2d8531e084f","ee03c041-d53b-4c08-b7d9-80d7461da3e4"],"id":"ffbc24f7-301e-48d3-bf01-c056916056a2","createdAt":"2020-11-05T19:00:16.268Z","createdBy":"a55fe1bc-1754-45fa-9adc-cf3d6d7c377a","status":"sourcing"}}
{"topic":"taas.job.create","originator":"taas-api","timestamp":"2020-11-05T19:00:17.563Z","mime-type":"application/json","payload":{"title":"Job Title","projectId":21,"externalId":"1212","description":"Dummy Description","startDate":"2020-09-27T04:17:23.131Z","duration":17,"numPositions":13,"resourceType":"Dummy Resource Type","rateType":"hourly","skills":["56fdc405-eccc-4189-9e83-c78abf844f50","f91ae184-aba2-4485-a8cb-9336988c05ab","edfc7b4f-636f-44bd-96fc-949ffc58e38b","4ca63bb6-f515-4ab0-a6bc-c2d8531e084f","ee03c041-d53b-4c08-b7d9-80d7461da3e4"],"id":"ffbc24f7-301e-48d3-bf01-c056916056a2","createdAt":"2020-11-05T19:00:16.268Z","createdBy":"a55fe1bc-1754-45fa-9adc-cf3d6d7c377a","status":"sourcing","isApplicationPageActive":false}}
Loading