Skip to content
Open
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
2 changes: 1 addition & 1 deletion plugins/ashby/src/api-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const SecondaryLocationSchema = v.object({
address: JobAddressSchema,
})

const CompensationSchema = v.object({
export const CompensationSchema = v.object({
compensationTierSummary: v.nullable(v.string()),
scrapeableCompensationSalarySummary: v.nullable(v.string()),
compensationTiers: v.array(CompensationTiersSchema),
Expand Down
35 changes: 34 additions & 1 deletion plugins/ashby/src/dataSources.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest"
import { extractLocation } from "./dataSources"
import { extractCompensationSummary, extractLocation } from "./dataSources"

describe("extractLocation", () => {
it("extracts location with full address", () => {
Expand Down Expand Up @@ -88,3 +88,36 @@ describe("extractLocation", () => {
expect(result.name).toBe("東京")
})
})

const emptyCompensation = {
compensationTierSummary: null,
scrapeableCompensationSalarySummary: null,
compensationTiers: [],
summaryComponents: [],
}

describe("extractCompensationSummary", () => {
it("prefers the scrapeable salary summary", () => {
const result = extractCompensationSummary({
...emptyCompensation,
scrapeableCompensationSalarySummary: "€100K - €150K",
compensationTierSummary: "€100K - €150K • Offers Equity",
})

expect(result).toBe("€100K - €150K")
})

it("falls back to the tier summary when the scrapeable summary is null", () => {
const result = extractCompensationSummary({
...emptyCompensation,
compensationTierSummary: "€8K - €12K / month",
})

expect(result).toBe("€8K - €12K / month")
})

it("returns null when no summary is available", () => {
expect(extractCompensationSummary(emptyCompensation)).toBeNull()
expect(extractCompensationSummary(null)).toBeNull()
})
})
23 changes: 10 additions & 13 deletions plugins/ashby/src/dataSources.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ManagedCollectionFieldInput } from "framer-plugin"
import * as v from "valibot"
import {
CompensationSchema,
type DataItem,
type Job,
type JobAddress,
Expand Down Expand Up @@ -71,6 +72,14 @@ function getLocationId(entry: unknown): string | null {
return null
}

export function extractCompensationSummary(value: unknown): string | null {
if (typeof value !== "object" || value === null) return null

const compensation = v.parse(CompensationSchema, value)

return compensation.scrapeableCompensationSalarySummary ?? compensation.compensationTierSummary
}

export function extractLocation(locationName: string, address: JobAddress | null): Location {
const postalAddress = address?.postalAddress
const parts = [
Expand Down Expand Up @@ -169,19 +178,7 @@ const jobsDataSource = createDataSource(
id: "compensation",
name: "Compensation",
type: "string",
getValue: value => {
if (typeof value !== "object" || value === null) return null

if ("scrapeableCompensationSalarySummary" in value) {
return value.scrapeableCompensationSalarySummary
}

if ("compensationTierSummary" in value) {
return value.compensationTierSummary
}

return null
},
getValue: extractCompensationSummary,
},
{
id: "address",
Expand Down
Loading