Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 907caad

Browse files
committed
changing this to work off of assertions and not TESTS!!!
1 parent 3cfc62c commit 907caad

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

src/services/ProcessorService.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ const config = require('config')
66
const joi = require('joi')
77
const logger = require('../common/logger')
88
const helper = require('../common/helper')
9-
const { Leaderboard } = require('../models')
9+
const {
10+
Leaderboard
11+
} = require('../models')
1012

1113
/**
1214
* Returns the tests passed using the metadata information
1315
* @param {object} metadata the object from which to retrieve the tests passed
1416
*/
15-
function getTestsPassed (metadata = {}) {
16-
const tests = metadata.tests || {}
17+
function getTestsPassed(metadata = {}) {
18+
const tests = metadata.assertions || {}
1719

1820
let testsPassed = tests.total - tests.pending - tests.failed
1921

@@ -28,10 +30,16 @@ function getTestsPassed (metadata = {}) {
2830
* Handle create / update topic messages from Kafka queue
2931
* @param {Object} message the Kafka message in JSON format
3032
*/
31-
const upsert = async (message) => {
33+
const upsert = async(message) => {
3234
const submission = await helper.reqToAPI(`${config.SUBMISSION_API_URL}/${message.payload.submissionId}`)
33-
34-
const existRecord = await Leaderboard.findOne({$and: [{challengeId: submission.body.challengeId}, {memberId: submission.body.memberId}]})
35+
36+
const existRecord = await Leaderboard.findOne({
37+
$and: [{
38+
challengeId: submission.body.challengeId
39+
}, {
40+
memberId: submission.body.memberId
41+
}]
42+
})
3543

3644
let testsPassed
3745
let totalTestCases
@@ -46,26 +54,24 @@ const upsert = async (message) => {
4654

4755
if (existRecord) {
4856
logger.debug(`Record with ID # ${message.payload.id} exists in database. Updating the score`)
49-
await Leaderboard.updateOne(
50-
{
51-
_id: existRecord._id
52-
},
53-
{
54-
$set: {
55-
aggregateScore: message.payload.aggregateScore,
56-
reviewSummationId: message.payload.id,
57-
testsPassed,
58-
totalTestCases
59-
}
57+
await Leaderboard.updateOne({
58+
_id: existRecord._id
59+
}, {
60+
$set: {
61+
aggregateScore: message.payload.aggregateScore,
62+
reviewSummationId: message.payload.id,
63+
testsPassed,
64+
totalTestCases
6065
}
61-
)
66+
})
6267
} else {
6368
logger.debug(`Record with ID # ${message.payload.id} does not exists in database. Creating the record`)
64-
const challengeDetail = await helper.reqToAPI(`${config.CHALLENGE_API_URL}?filter=id=${submission.body.challengeId}`)
69+
const challengeDetail = await helper.reqToAPI(
70+
`${config.CHALLENGE_API_URL}?filter=id=${submission.body.challengeId}`)
6571

6672
if (!helper.isGroupIdValid(challengeDetail.body.result.content[0].groupIds)) {
6773
logger.debug(`Group ID of Challenge # ${submission.body.challengeId} is not configured for processing!`)
68-
// Ignore the message
74+
// Ignore the message
6975
return
7076
}
7177

@@ -101,9 +107,11 @@ upsert.schema = {
101107
* Handle delete topic message from Kafka Queue
102108
* @param {Object} message the Kafka message in JSON format
103109
*/
104-
const remove = async (message) => {
110+
const remove = async(message) => {
105111
// Remove the record from MongoDB
106-
await Leaderboard.deleteOne({ reviewSummationId: message.payload.id })
112+
await Leaderboard.deleteOne({
113+
reviewSummationId: message.payload.id
114+
})
107115
}
108116

109117
remove.schema = {

0 commit comments

Comments
 (0)