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
5 changes: 3 additions & 2 deletions .forge/features/career-job-router/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ No pages in this slice. It supplies:
cannot be in the future.
- Community visibility by default, with a private setting.

- Members can manage their own company and location alert rules and opt into
internship and new-grad digests independently.

### Out of scope

- Ping preferences and digest opt-ins. They follow in a second PR once the
matching services in #650 merge.
- Editing or deleting individual timeline entries.
- Blade pages, cron, ingestion and Discord delivery.

Expand Down
10 changes: 8 additions & 2 deletions .forge/features/career-job-router/srd.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Career Job Router SRD

Status: Implemented for PR 1 of #651. References: #633, #646, #647, #648, #650.
Status: Includes both parts of #651. References: #633, #646, #647, #648, #650.

## Technical purpose

Expand All @@ -20,7 +20,7 @@ from `@forge/validators`, typed return shapes, extracted logic in
- Unauthenticated: none.
- Signed-in without a member profile: `FORBIDDEN` from every procedure
(`requireJobBoardMember`).
- Member: all eight procedures. Writes are scoped to the caller's `Member.id`;
- Member: all job board procedures. Writes are scoped to the caller's `Member.id`;
another member's application answers `NOT_FOUND`.
- Officer: no additional access. Officers do not see private applications.
- No `permProcedure`, so nothing is added to `utils/audit/coverage.ts`.
Expand Down Expand Up @@ -104,3 +104,9 @@ None in this slice.
## Open questions

- See spec.md. Search returns rows only once #649's ingestion lands.

## Member alert settings

The six jobBoard procedures resolve the member from the session and call the
preference and digest helpers from #650. Mutations reuse the job-board input
schemas. The digest mutation returns the saved choice and Discord sync result.
17 changes: 13 additions & 4 deletions .forge/features/career-job-router/status.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Career Job Router Status

Current phase: PR 1 implemented, validated locally and opened as a draft PR.
Current phase: PR 1 merged. Member alert settings reviewed locally and ready for PR submission.

## Decision log

Expand Down Expand Up @@ -31,9 +31,18 @@ Current phase: PR 1 implemented, validated locally and opened as a draft PR.
application mutations.
- [x] Add validator, integration and contract tests; update the API surface snapshot.
- [x] Commit and open the draft PR for Kevin's review.
- [ ] PR 2: ping preferences and digest opt-ins after #650.
- [x] Expose member ping preferences and digest opt-ins using the merged #650 services.

## Validation / commands
## Follow-up validation

- 42 tests passed across the job board, router integration, audit coverage and
API surface suites using disposable local PostgreSQL. The snapshot gained six paths.
- Root lint passed with warnings (31 tasks) and typecheck passed (33 tasks).
- Root format reported existing checkout-wide formatting issues in 24 packages.
Prettier passed on the changed TypeScript and Markdown files.
- Local review found a stale procedure count in the SRD, which was corrected.

## PR 1 validation / commands

- `pnpm --filter @forge/validators exec vitest run src/tests/audit.test.ts src/tests/job-board.test.ts`:
39 passed.
Expand All @@ -50,7 +59,7 @@ Current phase: PR 1 implemented, validated locally and opened as a draft PR.

## Links

- PRs:
- PRs: https://github.com/KnightHacks/forge/pull/670, https://github.com/KnightHacks/forge/pull/673
- Issues: https://github.com/KnightHacks/forge/issues/651,
https://github.com/KnightHacks/forge/issues/633
- Discord/thread context:
3 changes: 2 additions & 1 deletion .forge/features/career-job-router/test-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Status: Implemented. Kept to the key rules, per the small-slice testing guidance
## Scope

Member access, privacy of applications and notes, dated history, ownership, and
the default search filter. Preferences, digests, UI and ingestion are excluded.
the default search filter. The alert settings follow-up covers owner-only rule CRUD, independent digest
tracks, failed role sync and access denial for guests and users without profiles.

## Test placement plan

Expand Down
53 changes: 53 additions & 0 deletions packages/api/src/routers/job-board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { and, count, desc, eq, ilike, inArray } from "@forge/db";
import { db } from "@forge/db/client";
import { Job, JobApplication } from "@forge/db/schemas/job-board";
import {
alertPreferenceCreateInputSchema,
alertPreferenceIdInputSchema,
alertPreferenceUpdateInputSchema,
applicationIdInputSchema,
applicationSaveInputSchema,
applicationUpdateInputSchema,
companyViewInputSchema,
digestOptInInputSchema,
jobIdInputSchema,
jobSearchInputSchema,
peopleInProcessInputSchema,
Expand All @@ -17,6 +21,7 @@ import {
import type { CommunityApplication } from "../utils/job-board/community";
import { protectedProcedure } from "../trpc";
import { requireJobBoardMember } from "../utils/job-board/access";
import * as alertPreferences from "../utils/job-board/alert-preferences";
import {
listApplicationHistory,
removeApplication,
Expand All @@ -27,6 +32,7 @@ import {
countCommunityApplications,
listCommunityApplications,
} from "../utils/job-board/community";
import * as digestSubscriptions from "../utils/job-board/digest-subscriptions";
import {
containsPattern,
jobSearchConditions,
Expand Down Expand Up @@ -254,4 +260,51 @@ export const jobBoardRouter = {
);
return { applicationId: input.applicationId };
}),

listAlertPreferences: protectedProcedure.query(async ({ ctx }) => {
const member = await requireJobBoardMember(ctx.session.user.id);
return alertPreferences.listAlertPreferences(db, member.id);
}),

addAlertPreference: protectedProcedure
.input(alertPreferenceCreateInputSchema)
.mutation(async ({ ctx, input }) => {
const member = await requireJobBoardMember(ctx.session.user.id);
return alertPreferences.addAlertPreference(db, member.id, input);
}),

updateAlertPreference: protectedProcedure
.input(alertPreferenceUpdateInputSchema)
.mutation(async ({ ctx, input }) => {
const member = await requireJobBoardMember(ctx.session.user.id);
return alertPreferences.updateAlertPreference(
db,
member.id,
input.preferenceId,
input.preference,
);
}),

removeAlertPreference: protectedProcedure
.input(alertPreferenceIdInputSchema)
.mutation(async ({ ctx, input }) => {
const member = await requireJobBoardMember(ctx.session.user.id);
return alertPreferences.removeAlertPreference(
db,
member.id,
input.preferenceId,
);
}),

listDigestSubscriptions: protectedProcedure.query(async ({ ctx }) => {
const member = await requireJobBoardMember(ctx.session.user.id);
return digestSubscriptions.listDigestSubscriptions(db, member.id);
}),

setDigestSubscription: protectedProcedure
.input(digestOptInInputSchema)
.mutation(async ({ ctx, input }) => {
const member = await requireJobBoardMember(ctx.session.user.id);
return digestSubscriptions.setDigestSubscription(db, member.id, input);
}),
} satisfies TRPCRouterRecord;
73 changes: 71 additions & 2 deletions packages/api/src/tests/integration/job-board.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ describe.runIf(canRunDatabaseTests())("job board router", () => {
let blake: Awaited<ReturnType<typeof callerFor>>;
let openJobId: string;

async function callerFor(userId: string) {
async function callerFor(userId: string | null) {
const trpc = await import("../../trpc");
const { jobBoardRouter } = await import("../../routers/job-board");
const router = trpc.createTRPCRouter({ jobBoard: jobBoardRouter });

return trpc.createCallerFactory(router)({
headers: new Headers(),
session: { user: { id: userId, name: "Member" } } as Session,
session: userId
? ({ user: { id: userId, name: "Member" } } as Session)
: null,
source: "job-board-integration",
}).jobBoard;
}
Expand Down Expand Up @@ -145,6 +147,73 @@ describe.runIf(canRunDatabaseTests())("job board router", () => {
).rejects.toMatchObject({ code: "FORBIDDEN" });
});

it.each([
[null, "UNAUTHORIZED"],
[NO_PROFILE_USER, "FORBIDDEN"],
] as const)("guards all alert settings for %s", async (userId, code) => {
const caller = await callerFor(userId);
const preference = {
kind: "location",
target: { kind: "remote_us" },
track: "internship",
} as const;
const preferenceId = ALEX.memberId;
for (const call of [
() => caller.listAlertPreferences(),
() => caller.addAlertPreference(preference),
() => caller.updateAlertPreference({ preferenceId, preference }),
() => caller.removeAlertPreference({ preferenceId }),
() => caller.listDigestSubscriptions(),
() =>
caller.setDigestSubscription({ track: "internship", enabled: true }),
]) {
await expect(call()).rejects.toMatchObject({ code });
}
});

it("manages only the caller's alert preferences", async () => {
const saved = await alex.addAlertPreference({
track: "internship",
kind: "company",
target: { kind: "option", value: "google" },
});
const preferenceId = saved.id;
const preference = {
track: "new_grad",
kind: "location",
target: { kind: "remote_us" },
} as const;
await expect(blake.listAlertPreferences()).resolves.toEqual([]);
await expect(
blake.updateAlertPreference({ preferenceId, preference }),
).rejects.toMatchObject({ code: "NOT_FOUND" });
await expect(
blake.removeAlertPreference({ preferenceId }),
).rejects.toMatchObject({ code: "NOT_FOUND" });
await alex.updateAlertPreference({ preferenceId, preference });
await expect(alex.listAlertPreferences()).resolves.toMatchObject([
{ id: preferenceId, track: "new_grad", targetKey: "remote_us" },
]);
await alex.removeAlertPreference({ preferenceId });
await expect(alex.listAlertPreferences()).resolves.toEqual([]);
});

it("saves each digest independently when the member has no usable Discord ID", async () => {
await expect(
alex.setDigestSubscription({ track: "internship", enabled: true }),
).resolves.toEqual({ enabled: true, roleSynced: false });
await alex.setDigestSubscription({ track: "new_grad", enabled: true });
await alex.setDigestSubscription({ track: "internship", enabled: false });
await expect(alex.listDigestSubscriptions()).resolves.toEqual({
internship: false,
new_grad: true,
});
await expect(blake.listDigestSubscriptions()).resolves.toEqual({
internship: false,
new_grad: false,
});
});

it("hides inactive jobs from search unless asked, and filters by company", async () => {
const byDefault = await search(alex, { company: "acme" });
expect(byDefault.jobs.map((job) => job.id)).toEqual([openJobId]);
Expand Down
8 changes: 7 additions & 1 deletion packages/api/src/tests/job-board/router-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ vi.mock("../../utils/profile-picture/storage", () => ({
}));

describe("job board router contract", () => {
it("exposes job, community and own-application procedures", () => {
it("exposes job, community, application and alert settings procedures", () => {
expect(Object.keys(jobBoardRouter).sort()).toEqual(
[
"addAlertPreference",
"listAlertPreferences",
"listDigestSubscriptions",
"removeAlertPreference",
"setDigestSubscription",
"updateAlertPreference",
"getCompany",
"getJob",
"listMyApplications",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,19 @@ exports[`client-facing API surface > exposes exactly the documented procedure pa
"issues.restore",
"issues.update",
"issues.updateTemplate",
"jobBoard.addAlertPreference",
"jobBoard.getCompany",
"jobBoard.getJob",
"jobBoard.listAlertPreferences",
"jobBoard.listDigestSubscriptions",
"jobBoard.listMyApplications",
"jobBoard.listPeopleInProcess",
"jobBoard.removeAlertPreference",
"jobBoard.removeApplication",
"jobBoard.saveApplication",
"jobBoard.searchJobs",
"jobBoard.setDigestSubscription",
"jobBoard.updateAlertPreference",
"jobBoard.updateApplication",
"judging.addDeliberationProject",
"judging.archiveRoom",
Expand Down
Loading