141 lines
4.6 KiB
JavaScript
141 lines
4.6 KiB
JavaScript
/**
|
|
* Reapplied chip — two kept applications count, even with no job assigned.
|
|
*
|
|
* node reapplicant.test.mjs
|
|
*/
|
|
import { mkdtempSync, rmSync } from 'node:fs'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
import esbuild from 'esbuild'
|
|
|
|
const outDir = mkdtempSync(join(tmpdir(), 'tf-reapp-'))
|
|
const outFile = join(outDir, 'reapplicant.mjs')
|
|
|
|
await esbuild.build({
|
|
entryPoints: ['src/components/ReapplicantHistory.jsx'],
|
|
outfile: outFile,
|
|
bundle: true,
|
|
format: 'esm',
|
|
platform: 'node',
|
|
target: 'node20',
|
|
jsx: 'automatic',
|
|
logLevel: 'error',
|
|
define: { 'import.meta.env': JSON.stringify({ VITE_API_BASE: '' }) },
|
|
})
|
|
|
|
const { isReapplicant, candidateApplicationsOf, hrefForPreviousApplication } = await import(pathToFileURL(outFile).href)
|
|
|
|
let failed = 0
|
|
function ok(name, cond, extra) {
|
|
if (cond) {
|
|
console.log(`ok ${name}`)
|
|
} else {
|
|
failed += 1
|
|
console.log(`FAIL ${name}`)
|
|
if (extra) console.log(` ${extra}`)
|
|
}
|
|
}
|
|
|
|
const current = {
|
|
id: 'inbox-2',
|
|
inboxId: 'inbox-2',
|
|
previousApplications: [
|
|
{
|
|
source: 'inbox',
|
|
inbox_id: 'inbox-2',
|
|
message_id: 'inbox-2',
|
|
job_post_id: null,
|
|
job_title: null,
|
|
status: 'CLOSED',
|
|
},
|
|
{
|
|
source: 'inbox',
|
|
inbox_id: 'inbox-1',
|
|
message_id: 'inbox-1',
|
|
job_post_id: null,
|
|
job_title: null,
|
|
status: 'CLOSED',
|
|
},
|
|
],
|
|
}
|
|
|
|
ok('two unassigned emails still count as reapplied', isReapplicant(current) === true)
|
|
|
|
ok('a single application is not reapplied', isReapplicant({
|
|
id: 'inbox-1',
|
|
previousApplications: [{
|
|
source: 'inbox', inbox_id: 'inbox-1', message_id: 'inbox-1', job_post_id: null,
|
|
}],
|
|
}) === false)
|
|
|
|
ok('a wrong-format drop plus one real mail is not reapplied', isReapplicant({
|
|
id: 'inbox-1',
|
|
previousApplications: [
|
|
{ source: 'inbox', inbox_id: 'inbox-1', message_id: 'inbox-1', job_post_id: null, status: 'CLOSED', attachment: true },
|
|
{ source: 'filtered', message_id: 'drop-1', status: 'WRONG_FORMAT', rejection_reason: 'wrong_format' },
|
|
],
|
|
}) === false)
|
|
|
|
ok('an unreadable prior CV is not a reapplication', isReapplicant({
|
|
id: 'inbox-2',
|
|
previousApplications: [
|
|
{ source: 'inbox', inbox_id: 'inbox-2', message_id: 'inbox-2', job_post_id: null, status: 'CLOSED', attachment: true, match_status: 'matched' },
|
|
{ source: 'inbox', inbox_id: 'inbox-1', message_id: 'inbox-1', job_post_id: null, status: 'WRONG_FORMAT', rejection_reason: 'wrong_format', attachment: true, match_status: 'no_text' },
|
|
],
|
|
}) === false)
|
|
|
|
ok('body-only mail plus one real mail is not reapplied', isReapplicant({
|
|
id: 'inbox-1',
|
|
previousApplications: [
|
|
{ source: 'inbox', inbox_id: 'inbox-1', message_id: 'inbox-1', job_post_id: null, status: 'CLOSED', attachment: true },
|
|
{ source: 'inbox', inbox_id: 'inbox-0', message_id: 'inbox-0', job_post_id: null, status: 'WRONG_FORMAT', rejection_reason: 'wrong_format', attachment: false },
|
|
],
|
|
}) === false)
|
|
|
|
ok('an assigned prior application still counts', isReapplicant({
|
|
id: 'inbox-2',
|
|
previousApplications: [
|
|
{ source: 'inbox', inbox_id: 'inbox-2', message_id: 'inbox-2', job_post_id: null },
|
|
{ source: 'inbox', inbox_id: 'inbox-1', message_id: 'inbox-1', job_post_id: 'job-1', job_title: 'Analyst' },
|
|
],
|
|
}) === true)
|
|
|
|
ok('wrong-format rows are omitted from the highlighted list', candidateApplicationsOf({
|
|
id: 'inbox-1',
|
|
previousApplications: [
|
|
{ source: 'inbox', inbox_id: 'inbox-1', message_id: 'inbox-1', job_post_id: null, status: 'CLOSED' },
|
|
{ source: 'filtered', message_id: 'drop-1', status: 'WRONG_FORMAT', rejection_reason: 'wrong_format' },
|
|
],
|
|
}).length === 1)
|
|
|
|
ok('email history still opens the inbox applicant', hrefForPreviousApplication({
|
|
source: 'inbox', message_id: 'msg-1',
|
|
}) === '/inbox?open=msg-1&kind=email')
|
|
|
|
ok('form history still opens the inbox form applicant', hrefForPreviousApplication({
|
|
source: 'form', form_data_id: 'form-1',
|
|
}) === '/inbox?open=form-1&kind=form')
|
|
|
|
ok('upload history opens the candidate profile', hrefForPreviousApplication({
|
|
source: 'manual', user_id: 'user-1', manual_upload_candidate_id: 'm-1',
|
|
}) === '/candidate/user-1')
|
|
|
|
ok('upload without its own user id uses the open row', hrefForPreviousApplication(
|
|
{ source: 'manual', manual_upload_candidate_id: 'm-1' },
|
|
{ userId: 'user-9' },
|
|
) === '/candidate/user-9')
|
|
|
|
ok('upload never falls through to matching', hrefForPreviousApplication({
|
|
source: 'manual', manual_upload_candidate_id: 'm-1',
|
|
}) == null)
|
|
|
|
rmSync(outDir, { recursive: true, force: true })
|
|
|
|
if (failed) {
|
|
console.log(`\n${failed} check(s) failed`)
|
|
process.exit(1)
|
|
}
|
|
console.log('\nAll reapplicant checks passed')
|