Skip to content
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
13 changes: 7 additions & 6 deletions src/schema/jsonld.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ export function jobPostingJsonLd(job: Job, origin: string): JsonLdJobPosting {

const salary = job.salary;
if (salary.min !== null || salary.max !== null) {
const min = salary.min ?? salary.max;
const max = salary.max ?? salary.min;
// An absent endpoint is an open bound, not an exact salary. Keep it
// absent in both representations instead of copying the other endpoint.
const { min, max } = salary;
doc['baseSalary'] = {
'@type': 'MonetaryAmount',
currency: salary.currency.toUpperCase(),
value: {
'@type': 'QuantitativeValue',
minValue: min,
maxValue: max,
...(min !== null ? { minValue: min } : {}),
...(max !== null ? { maxValue: max } : {}),
unitText: salary.period.toUpperCase(),
},
};
Expand All @@ -83,8 +84,8 @@ export function jobPostingJsonLd(job: Job, origin: string): JsonLdJobPosting {
currency: salary.currency.toUpperCase(),
value: {
'@type': 'QuantitativeValue',
minValue: Math.round((min ?? 0) * (PER_YEAR[salary.period] ?? 1)),
maxValue: Math.round((max ?? 0) * (PER_YEAR[salary.period] ?? 1)),
...(min !== null ? { minValue: Math.round(min * (PER_YEAR[salary.period] ?? 1)) } : {}),
...(max !== null ? { maxValue: Math.round(max * (PER_YEAR[salary.period] ?? 1)) } : {}),
unitText: 'YEAR',
},
};
Expand Down
30 changes: 30 additions & 0 deletions test/federation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,33 @@ test('the agent policy travels where a validator will accept it', () => {
assert.ok(extra.some((entry) => entry.name === 'applySchemaUrl'));
assert.equal(jsonld['directApply'], true);
});

for (const [label, min, max, expected] of [
['floor', 100, null, { minValue: 100 }],
['ceiling', null, 200, { maxValue: 200 }],
['range', 100, 200, { minValue: 100, maxValue: 200 }],
['fixed', 100, 100, { minValue: 100, maxValue: 100 }],
['zero floor', 0, null, { minValue: 0 }],
] as const) {
test(`structured salary preserves the stated ${label}`, () => {
const job = { ...JOB, salary: { ...JOB.salary, min, max } };
const jsonld = jobPostingJsonLd(job as never, 'https://board.example');
const base = jsonld['baseSalary'] as { value: Record<string, unknown> };
const annual = jsonld['estimatedSalary'] as { value: Record<string, unknown> };
assert.deepEqual(base.value, {
'@type': 'QuantitativeValue', ...expected, unitText: 'HOUR',
});
assert.deepEqual(annual.value, {
'@type': 'QuantitativeValue',
...Object.fromEntries(Object.entries(expected).map(([key, value]) => [key, value * 2080])),
unitText: 'YEAR',
});
});
}

test('an unspecified structured salary does not become a zero salary', () => {
const job = { ...JOB, salary: { ...JOB.salary, min: null, max: null } };
const jsonld = jobPostingJsonLd(job as never, 'https://board.example');
assert.equal(Object.hasOwn(jsonld, 'baseSalary'), false);
assert.equal(Object.hasOwn(jsonld, 'estimatedSalary'), false);
});
Loading