All files / utils/moderation/subjects index.js

100% Statements 5/5
100% Branches 0/0
100% Functions 1/1
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                      5x 5x   5x             21x     5x  
/**
 * Registry of moderated subject types. The engine looks a task's subject up
 * here by `task.subjectType`; nothing else in the engine mentions a concrete
 * kind of content.
 *
 * A subject implements:
 * - requiredVotes, maxVotes, quotaCost: consensus and quota parameters
 * - buildSubjectRef(params): what to store on the task to find the subject again
 * - loadContext(docClient, task): the subject and what surrounds it, or null if gone
 * - isReviewable(context): whether reviewers should still be shown it
 * - isVisibleToReviewer(context, { reviewerIsTest }) [optional]: whether this
 *   particular reviewer should be offered it (e.g. keeping e2e test content
 *   and real content apart); a subject without it is visible to everyone
 * - describe(context): what the reviewer sees
 * - buildDecisionWrites(task, decision, context): TransactItems applying the decision
 * - buildDiscardWrites(task, context): TransactItems deleting a subject that can
 *   no longer be reviewed (see isReviewable)
 * - buildAuthorNotification(task, outcome, context) [optional]: the
 *   notification (`{ type, data }`) to send the author about the outcome — a
 *   decision, or DISCARDED — or null for none; a subject without it never
 *   notifies
 *
 * See subjects/itemComment.js for the reference implementation.
 *
 * @implements UC-MOD-011.1
 */
 
const itemComment = require('./itemComment')
const packComment = require('./packComment')
 
const SUBJECTS = new Map([
  [itemComment.type, itemComment],
  [packComment.type, packComment]
])
 
/** @returns {object | undefined} the subject registered under `subjectType` */
function getSubject(subjectType) {
  return SUBJECTS.get(subjectType)
}
 
module.exports = { getSubject, SUBJECT_TYPES: [...SUBJECTS.keys()] }