-
Notifications
You must be signed in to change notification settings - Fork 3
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
Test validator 37 #3
Changes from 5 commits
293e03e
136b06a
1ffb1a7
72f687e
3352422
e55605a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
module.exports = { | ||
beforeCreate(event) { | ||
console.log("**** beforeCreate hook is activated! ****"); | ||
const [eventTests, eventMetaTests] = [ | ||
event.params.data.tests, | ||
event.params.data.MetaTest, | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't make sense. Take a second look at it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
runMetaTests(eventTests, eventMetaTests); | ||
}, | ||
|
||
beforeUpdate(event) { | ||
console.log("**** beforeUpdate hook is activated! ****"); | ||
const [eventTests, eventMetaTests] = [ | ||
event.params.data.tests, | ||
event.params.data.MetaTest, | ||
]; | ||
runMetaTests(eventTests, eventMetaTests); | ||
}, | ||
}; | ||
|
||
// runMetaTestsNeed more specific name later, maybe use "validateInternalTests" | ||
async function runMetaTests(eventTests, eventMetaTests) { | ||
const [tests, metaTests] = await Promise.all([ | ||
getInternalTests(eventTests), | ||
getMetaTests(eventMetaTests), | ||
]); | ||
|
||
tests.map((test) => | ||
console.log("final test.internalTest: ", test.internalTest) | ||
); | ||
|
||
metaTests.map((metaTest) => | ||
console.log("final metaTest caseCode: ", metaTest.caseCode) | ||
); | ||
|
||
return false; | ||
} | ||
|
||
async function getInternalTests(eventTests) { | ||
const internalTests = await strapi.db | ||
.query("challenge.code-challenge-test") | ||
.findMany({ | ||
select: ["id", "internalTest"], | ||
where: { | ||
id: getCurrentTestIDs(eventTests), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. getCurrentINTERNALTestIds There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I prefer Ids to IDs? I'm ok with either one but just not sure. I read this SO response https://stackoverflow.com/questions/15526107/acronyms-in-camelcase/27172000 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's whatever. I think Ids is more common There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with the top answer, that's how I do it I guess |
||
}, | ||
}); | ||
|
||
// console.log("internalTests: ", internalTests); | ||
return internalTests; | ||
} | ||
|
||
function getCurrentTestIDs(eventTests) { | ||
let currentTestIDs = []; | ||
eventTests.map((test) => { | ||
currentTestIDs.push(test.id); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this defeats the point of map. You need to return inside of the map function. Take a look at map on MDN There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. function getCurrentTestIDs(eventTests) { There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The eventTests array is an array of objects like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the heads up. I didn't realize .map() could be so flexible! |
||
// console.log("currentTestIDs: ", currentTestIDs); | ||
return currentTestIDs; | ||
} | ||
|
||
async function getMetaTests(eventMetaTests) { | ||
const MetaTests = await strapi.db.query("challenge.meta-test").findMany({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be camel case |
||
select: ["id", "caseCode", "passes"], | ||
where: { | ||
id: getCurrentMetaIDs(eventMetaTests), | ||
}, | ||
}); | ||
|
||
// console.log("MetaTests: ", MetaTests); | ||
return MetaTests; | ||
} | ||
|
||
function getCurrentMetaIDs(eventMetaTests) { | ||
let metaIDs = []; | ||
eventMetaTests.map((metaTest) => { | ||
metaIDs.push(metaTest.id); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as the above comment regarding map |
||
// console.log("metaIDs: ", metaIDs); | ||
return metaIDs; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"collectionName": "components_challenge_meta_tests", | ||
"info": { | ||
"displayName": "MetaTest", | ||
"icon": "balance-scale", | ||
"description": "" | ||
}, | ||
"options": {}, | ||
"attributes": { | ||
"caseCode": { | ||
"type": "richtext" | ||
}, | ||
"label": { | ||
"type": "string" | ||
}, | ||
"passes": { | ||
"type": "boolean" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The console.log can be used for testing but shouldn't be merged. Make sure to remove it when you finish. If anything we would do more specific logging , but this is too generic